BACKGROUND: Up to now, I have been provisioning VMs as follows:
Create template/gold VM:
- Create new CentOS 6.6 VM with raw 200GB disk (1 .xml file, 1 .img file)
- LVM partitioning with: /boot, swap, and / partitions (most space in /)
- Install desired packages
The above results in a VM such as:
200GB /var/lib/libvirt/images/mytemplate.img
To produce guest images from the above I do:
- dd if=mytemplate.img of=myguest.img iflag=direct oflag=direct (vs cp for better copying speed)
- use guestfish to modify the /etc/sysconfig/network, /etc/sysconfig/network-scripts/ifcfg-eth0
- uuidgen and a MAC address generator script generate these ids
- static ip addresses are pulled from an available pool
The above works just fine: we have one .xml file and one .img file that can easily be moved around our data farm.
PROBLEM: The problem is that the above is thick provisioning. The images are 200GB in size, even though the majority of the image may be unused disk space. I'd like to have these thinly provisioned with a maximum growth size to make moving the images across the network faster. We'd want commands such as df / inside the guest VM to show the maximum size of the guest filesystem if at all possible.
Also, we'd like to consider qcow2 instead of raw for the image file so as to make it possible to take snapshots.
QUESTION: How do I create thinly-provisioned KVM images that are LVM partitioned as described above? Can I virt-sparsify the existing mytemplate.img file and still allow the image to grow to the maximum size and have the / filesystem have the behavior I want? Please feel free to offer alternatives for consideration.
Best Answer
virt-sparsify
is what you need.virt-clone
qemu-img convert
is the better approach.To really save disk space, you can make the golden image, then create some snapshots of it using
qemu-img
, and base your VMs on those snapshots. This way the base data will remain in the base image and the VMs will be on very small images that will only contain the differences between the actual VM and the golden image. The downside will be in performance of course, so the choice is yours, whether to sacrifice space or performance.