Qcow disk size problem

I have opennebula server running on ubuntu 16.04 LTS. Currently running more than 50 vms. I use qcow2 format for running vm’s disks. The problem is the physical size of qcow2 is much bigger than the actual. I realize it’s the characteristic of qcow format that it will grow as the data increase but won’t shrink as the data decrease. Now, is it able to shrink? If able, how can i shrink it? Or should i change from qcow to other format? What is the reliable format for opennebula vms?

Yonathan Hartoko


There are two common ways to shrink a qcow2 file using TRM/discard/ or zerofill. .

If you are using virtio-scsi driver and you have discard enabled you can just issue fstrim from inside the VM. The zerofill mostly involves scripted/manual intervention inside the vm and then on the qcow file of the powered off VM

Quick googling should reveal the details regarding of both resolutions.

Best Regards,
Anton Todorov

1 Like

One additional hint: If you are using NFS to store the qcow2 images, make sure to use NFS Version >= 4.2. Otherwise discarding will have no effect on the file size.