qcow2 auto resize?

Jorem

New Member
May 28, 2009
24
0
1
I have a KVM VM with CentOS and I used to be 20GB in size. After a few local backups the size changed to 69GB. I removed the backups now and the size of the files is 20GB again.
But the size of the qcow2 image file is still 69GB and is not reducing according to the size of the VM.

Is that normal? (one way resize)
How can I let the qcow2 become smaller again?

The problem I have now is that my backup is also 69GB. With compression smaller (34GB), but that used to be 12GB.
 
Is that normal? (one way resize)

Yes - the filesystem never frees allocated space.

How can I let the qcow2 become smaller again?

Attach a second disk, and copy the contents (the use the new disk instead). But that is non-trivial because you need to copy the partitions and MBR too. I don't really know if there is a nice tool to do that?
 
Can the qemu-img command be used to do this?

Like : qemu-img convert -O qcow2 vm-101-disk.qcow2 vm-101-disk.qcow2.new

This should free up all the 0's on the drive. On Windows you first have to overwrite the old empty space with 0's to free it with the qemu-img command. Is this also the case with Linux?

Did someone maybe tried this already?
 
Yes, you have to:
1) overwrite free space with zeores, e.g. dd if=/dev/zero of=/bigzerofile bs=4k
2) qemu-img convert
I did this lots of times and I dont think there is a better way of shrinking qcow2 files
 
It works great, but I wondered if you can run the 'qemu-img convert' command also on a running system?
 
Thanks for the Clonzilla tip. I will have a trie with that. Looks pretty risk free to me :).
 

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!