From 37a1f42acf5ee8abc4a9d90a0d49a44de7efca00 Mon Sep 17 00:00:00 2001 From: Daniel Kral Date: Thu, 17 Oct 2024 13:51:23 +0200 Subject: [PATCH] fix #5301: convert added volume disks to base image for templates This will automatically convert imported volume disks and newly allocated VM volume disks (i.e. no efidisks, tpmstate disks, cloudinit images, etc.) to a base volume, if the VM is a template. Previously, this required a user to manually convert the imported/allocated disk with `qm template --disk `. Signed-off-by: Daniel Kral --- PVE/API2/Qemu.pm | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index 19af6bf9..c50c42be 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -461,6 +461,11 @@ my sub create_disks : prototype($$$$$$$$$$) { 'skip-config-update' => 1, }, ); + + # change imported disk to a base volume in case the VM is a template + $dst_volid = PVE::Storage::vdisk_create_base($storecfg, $dst_volid) + if PVE::QemuConfig->is_template($conf); + push @$vollist, $dst_volid; } } @@ -490,6 +495,10 @@ my sub create_disks : prototype($$$$$$$$$$) { $volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, "raw", undef, $size); } else { $volid = PVE::Storage::vdisk_alloc($storecfg, $storeid, $vmid, $fmt, undef, $size); + + # change created disk to a base volume in case the VM is a template + $volid = PVE::Storage::vdisk_create_base($storecfg, $volid) + if PVE::QemuConfig->is_template($conf); } push @$vollist, $volid; $disk->{file} = $volid;