Re: Can i shrink the image file size?

Luca Tettamanti
2009-03-21T20:26:00Z

2009/3/21 John Wong <johnw@wonghome.net>:
> I create the 30G qcow2 image file, installed winxp, winxp show me the
> harddisk used 5G, but the image file size is 12G now.
> can i shrink the image file size? how?

It's not possible to directly reclaim the unused space (qemu is not
aware of what is used and what is not); a workaround is first filling
the unused space with zeros (using sdelete -c) and then compressing
the image with qemu-img convert -c; the side effect of sdelete is that
the image will grow to the limit of 30G, but then the empty space will
be highly compressible.
The alternative is dumping the FS and restoring it on a new image as
suggested by Piavlo.

Luca