13 January, 2014

Shrink VMs on virt-manager/KVM

  I tend to use rsync to backup my system ( including VMs) thanks an anoying bug[1] . Turns out, this would sync the entire sparse file, expanding from 11gb on disk to 64gb on target system.

 To "fix" this I now use qcow2 for disk image, based of instructions from here[2].

  •  Move existing images to qcow2 , if not done. This also would allow us to use snapshots via virt-manager [3]

  • Fill VMs with zeros to allow them to be compressed

  • Shut down the VMs, and run from host 

$ mv original_image.qcow2 original_image.qcow2_backup
$ qemu-img convert -O qcow2 original_image.qcow2_backup original_image.qcow2

[1] https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1259829
[2] http://www.jamescoyle.net/how-to/323-reclaim-disk-space-from-a-sparse-image-file-qcow2-vmdk
[3] http://www.phoronix.com/scan.php?page=news_item&px=MTQ0NjM