Score:1

Can't Recover Space from qcow2 image without deleting wanted 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 tried got the following results:

  • Using 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.

  • Using virt-sparsify (Doesn't recover any space) cp Linux.qcow2 TEST.qcow2 sudo virt-sparsify --in-place TEST.qcow2

    Retains the two undeleted 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?

I find it difficult to understand why there isn't an easy way to achive this that is clearly documented

Edit: Is there any way to copy Snapshot 4 to a new file as a snapshot, and then add the delta for snapshot 5. Then I could just discard the extra file with the wasted space.

user73383 avatar
cn flag
@shodanshok in my case the Virtual Disk size is 20GB, but the image file is well over 50GB. Any possibility of coping the snapshots beginning with the first one manually to a new file (offline with he VM not running of course)? If so any suggestions as to hos I might do this?.
Score:0
ca flag

Unfortunately, deleting a snapshot does not shrink a QCOW2 file below its max permitted logical size.

Using a 2 GB max-logical-size file as example:

  • if, due to snapshots, its current, real size is above 2 GB (ie: 3 GB), deleting previous snapshots will shrink it at 2 GB (as reported by du -hs, while ls -al continue to show its "enlarged" size);

  • if its current size is less than 2 GB, then deleting snapshots will not release any additional space (unless using qemu-img convert to create a new, shrunk file).

This is one of the reasons while Red Hat does not recommend using internal QCOW2 snapshots for production workloads: while very convenient and easy to use, they are less flexible (and somewhat more "opaque") than external snapshots.

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.