March 14, 2018 · qcow2 KVM Virtual Machine Tutorial

How to reclaim free space/shrink qcow2 file?

Qcow2 file grows overtime; even if we delete files and snapshots. It still does not reduce the file size. The only way to that is to fill the disk with zero and then convert the disk to qcow2.


Do a disk free command

df -h


We need to fill root and home with zero.

dd if=/dev/zero of=/mytempfile bs=10M; rm -f /mytempfile
dd if=/dev/zero of=/home/mytempfile bs=10M; rm -f /home/mytempfile


shutdown -h now


qemu-img convert -O qcow2 vm_learn.qcow2 vm_learn_new.qcow2

Edit guest and use the newly created qcow2 disk.

virsh edit vm_learn

Comments powered by Disqus