qcow2 Virtual Machine Image Compression

KVM qcow2 Image Compression

Have you ever encountered your QEMU-KVM Virtual Machine Image in qcow2 format eating your storage space? If yes, today we will solve that problem. The problem is due to thin provisioning

QEMU-KVM Virtual Machine(VM) Images take extra space with snapshots as original image size increases. We will restore the image to minimal size, deleting extra space occupied by snapshots.

Thin Provisioning

When a snapshot is taken, the changes made to the VM after the snapshot are stored in a separate file. With thin provisioning, the snapshot size can increase dynamically as more data is written to the VM after the snapshot is taken. This means that the snapshot will only consume additional space as changes occur, rather than reserving a fixed amount of space upfront.

General

ls cannot understand thin provisioning , use Disk Utility du instead

Here is my sample disk size: qcow2-image-size

qemu-img

Deleting Snapshots

virt-sparsify

Free space within the disk image can be converted back to free space on the host. Check documentation for all features.

Before Compression

size-of-qcow2-image-before-compression

After Compression

size-of-qcow2-image-after-compression