Score:1

How can I recover the space in a qcow2 file after deleting snapshots, while retaining remaining snapshots?

cn flag

I have a virtual machine that started out with 5 snapshots 1,2,3,4,5.

I used qemu-img to delete snapshots 1,2,3. Snapshots 4 and 5 are still needed and were not deleted.

How can I release the space used by snapshots 1,2,3 and retain snapshots 4 and 5?

I have spent a lot of time searching for a solution, and the solutions I have found fit into one of two patterns:

Use qemu-img convert (Deleted needed snapshots) qemu-img convert -O qcow2 Linux.qcow2 Linux_s.qcow2 Reduces the space used by Linux.qcow2, but deletes snapshots 4 and 5

Copy the VM and use virt-sparsify (Doesn't recover any space) cp Linux.qcow2 TEST.qcow2 sudo virt-sparsify --in-place TEST.qcow2

It retains the two nundeleted snapshots, but doesn't recover the space that was originally occupied by snapshots 1,2,3.

How can I recover the space in a qcow2 file after deleting snapshots, while retaining remaining snapshots?

Michael Hampton avatar
cz flag
Why do you believe that there is any space left to "recover"?
user73383 avatar
cn flag
The VM is essentially clean, it's updated, and snapshotted. I restore the napshot on boot at regular intervals, so the delta for each snapshot is essentially what changes on each distribution update.
Score:0
ml flag

qcow2 files are sparse files, on file systems that support sparse files they can take a lot less space on disk than the size of the file.

If you delete a snapshot the size as reported by ls -l doesn't change, but the amount of free space on the disk as reported by df does change.

Almost all file systems support sparse files, FAT and NFS3 are probably the only common file systems that don't.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.