Revision history [back]

click to hide/show revision 1
initial version

To shrink a qcow2 image fire up an instance off your snapshot and for each filesystem do:

   dd if=/dev/zero of=fillmeup
   rm fillmeup

f.e. if you've got '/' only:

   cd /
   dd if=/dev/zero of=fillmeup
   rm -f fillmeup

The same goes for /var, /usr etc.

I've crafter a script for my own usage:

   for q in \
      $(lsblk -ln \
        | grep "^vg_system" \
        | fgrep -v "[SWAP]" \
        | awk '{print $NF}') ; \
   do \
      pushd ${q} ; \
      dd if=/dev/zero of=fillme ; \
      sync ; \
      rm -f fillme ; \
      sync ; \
      popd ; \

From my experience, /dev/zero trick will give you an image about 20 times smaller.

PS. You may be able to avoid booting an instance off the snapshot by using 'guestmount' to mount the snapshot on the hypervisor (tip: use 'virt-df' to display a list of filesystems so you know what you'll be mounting). I haven't tried it (yet) so please reply with your results should you go this route.