Ny way to shrink qcow2 image without converting it raw

converthard drivekvm-virtualizationqcow2qemu

Is there any way to shrink qcow2 image without converting it raw?

I cannot convert it to raw because I don't have disk space enough for raw image.

Best Answer

Noop conversion (qcow2-to-qcow2) removes sparse space:

qemu-img convert -O qcow2 source.qcow2 shrunk.qcow2

You can also try add compression (-c) to the output image:

qemu-img convert -c -O qcow2 source.qcow2 shrunk.qcow2

Before running above command be sure to shutdown the VM. After you are satisfied with the result, you can rename shrunk.qcow2 to original name your VM config wants.