diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index 99e37d87..a156117a 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -156,8 +156,8 @@ my $create_disks = sub { }else{ $fmt = 'raw'; } - # FIXME: Reasonable size? qcow2 shouldn't grow if the space isn't used anyway? - my $cloudinit_iso_size = 5; # in MB + # Initial disk created with 4MB, every time it is regenerated the disk is aligned to 4MB again. + my $cloudinit_iso_size = 4; # in MB my $volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $fmt, $name, $cloudinit_iso_size*1024); $disk->{file} = $volid; diff --git a/PVE/QemuServer/Cloudinit.pm b/PVE/QemuServer/Cloudinit.pm index e83c0db4..445c7771 100644 --- a/PVE/QemuServer/Cloudinit.pm +++ b/PVE/QemuServer/Cloudinit.pm @@ -30,9 +30,15 @@ sub commit_cloudinit_disk { my $storecfg = PVE::Storage::config(); my $iso_path = PVE::Storage::path($storecfg, $drive->{file}); my $scfg = PVE::Storage::storage_config($storecfg, $storeid); + my $format = PVE::QemuServer::qemu_img_format($scfg, $volname); + if (! -e $iso_path) { + $volname =~ m/(vm-$vmid-cloudinit(.(qcow2|raw))?)/; + my $name = $1; + my $d = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $format, $name, 4 * 1024); + } + my $plugin = PVE::Storage::Plugin->lookup($scfg->{type}); $plugin->activate_volume($storeid, $scfg, $volname); - my $format = PVE::QemuServer::qemu_img_format($scfg, $volname); my $size = PVE::Storage::file_size_info($iso_path); @@ -434,7 +440,7 @@ sub read_cloudinit_snippets_file { my ($full_path, undef, $type) = PVE::Storage::path($storage_conf, $volid); die "$volid is not in the snippets directory\n" if $type ne 'snippets'; - return PVE::Tools::file_get_contents($full_path); + return PVE::Tools::file_get_contents($full_path, 1 * 1024 * 1024); } my $cloudinit_methods = {