Shrink qemu qcow2 files

By technese - Last updated: Thursday, October 22, 2015 - Save & Share - Leave a Comment

Excerpt from source:

Windows Guest

1.Delete all unnecessary files, empty recycle bin
2.Defragment drive (you might need to do this several times, until you see it “compacted” well)
3.Use sdelete to zero free disk space. Please note that this operation will cause that all drive free space will be filled by zero, so the virtual machine image will grow to the maximum size.

Using command prompt

sdelete -c c:

Linux/FreeBSD Guest

# dd if=/dev/zero of=./zero bs=1M
# sync
# rm -f ./zero

Note, the bs parameter is important, since it greatly reduce time necessary to complete this task.

Convert image to the same format that is currently is (e.g. qcow2 => qcow2)… during this procedure it will release unused space.

# qemu-img convert -O qcow2 w2k3.qcow2 w2k3-shrinked.qcow2


Download sdelete from here:

Posted in General, Linux, Other, Virtualization • • Top Of Page