I have a qcow2 image. The image size is 200 GB, but the actual use is only 30 GB.
I'm using qemu-img convert -O qcow2 source.qcow2 shrunk.qcow2
to removes sparse space and the images shrinks correctly to 30 GB.
This image has internal snapshots taken using virt-manager. After converting the image, the snapshots is lost.
Is there any way to removes unused space from the image but still keep internal snapshots?

- 13
- 3
1 Answers
I have tested what you asked. If you use virt-sparsify --in-place it preserves snapshots. But to be safe and sure if you have free space first copy than use virt-sparsify.
cp source.qcow2 target.qcow2
virt-sparsify --in-place target.qcow2
qemu-img version 7.1.0
virt-sparsify 1.48.2
Linux 6.0.9-arch1-1 #1 SMP PREEMPT_DYNAMIC Wed, 16 Nov 2022 17:01:17 +0000 x86_64 GNU/Linux
Edit:
I use virt-sparsify then pigz to backup machine. I do not convert them. Also machines are on NVME I do fstrim to ...../ACTIVE_VMs directory. So that I keep nvme durable from backup to backups.
Tried ZFS for dedupe and compression on raw images. Qcow2 is far better. Now I am gonna search for snapshot branch visualisation because apparently you can create branches and go back and forth and add new things.
What would be fantastic is if you send snapshot command to base via ssh creating an UUID code as a name to snapshot and dumping kernel and other software info to an xml with it. You can truly make a parallel universe of installation combinations in one disk file and one xml :). This should be default. Maybe it is I don't know.

- 536
- 4
- 12