Shrink virtual disk for creation of template

andy77

Renowned Member
Jul 6, 2016
248
13
83
41
Hallo @all

I am trying to shring a virtual disk to be able to create a smal template that can be easily and fast cloned to the nodes.

Unfortunately I have started with a 50GB disksize when I started to build my Windows Server Template. After much work of configuration for my template I realized that cloning 50GB to nodes take much time (and IO delay) so I want to reduce this size.

What I did until now is: I shrinked the drive in windows to 15GB. the rest is "unalocated disk space" for Windows.

Then I shrinked the qcow2 file with following parameter. This made a siginificant reduction of filesize to 7GB
Code:
qemu-img convert -O qcow2 -c image.qcow2_backup image.qcow2

But now when trying to clone the template via WebGUI, it still transfers somehow 50GB and takes the same time to do this. I do not really understand why this happans. Also in the hardware tab, it is still writing me that the drive has 50GB.

So I tried to change that directly in the qemu conf file of that VM. Now for the template VM it is showing me 15GB, but when I start cloning it still transfers 50GB and after completion of the cloning, it is showing me again 50GB in the hardware tab of the new VM.

So is there a way of shrinking a VMs virtual harddisk so that it can be faster cloned?

Thx a lot for any help

Regards
Andy
 
Where do you clone the qcow2 file to (which storage type)?
 
You don't get around the fill-up on the conversion, as qemu can only do sparse on qcow2-to-qcow2 conversion. But after the conversion you can compact it again.
 
Things to try (I guess mostly obvious ;)), use a VM backup, a smaller VM disk size or to use the same storage as the target for your template. You also could create linked clones, but performance degraded over time.
 
Well I would love to use a smaler VM Disk size, but I can't figure out how to shrink it. This is the reason why I initialy start writing here.

So do I understand you right, that there is no soultion for shrinking a VM Disk in their size?

Regards
Andy
 
You mean to resize a qcow2 image? That is done with qemu-img resize.
resize filename [+ | -]size
Change the disk image as if it had been created with size.

Before using this command to shrink a disk image, you MUST use file system and partitioning tools inside the VM to reduce allocated file systems and partition sizes accordingly. Failure to do so will result in data loss!

After using this command to grow a disk image, you must use file system and partitioning tools inside the VM to actually begin using the new space on the device.
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!