Yesterday I hinted that virt-customize could be used to make custom guests sharing a single backing file. Here is how you do that.
Firstly download a cloud image, or use virt-builder to create one:
$ virt-builder fedora-20 -o backing.img [ 0.0] Downloading: http://libguestfs.org/download/builder/fedora-20.xz [ 1.0] Planning how to build this image [ 1.0] Uncompressing [ 11.0] Opening the new disk [ 15.0] Setting a random seed [ 15.0] Setting passwords Setting random password of root to 8obMIvmrWe6CCkAv [ 16.0] Finishing off
Now use qemu-img to create overlays for each guest:
$ qemu-img create -b backing.img -f qcow2 guest1.img $ qemu-img create -b backing.img -f qcow2 guest2.img
You must leave the backing file untouched. In particular don’t try to customize it, else you’ll corrupt all the guests using that backing file.
Now you can customize each guest overlay:
$ virt-customize -a guest1.img \ --hostname guest1 --timezone Europe/London \ --install gcc [ 0.0] Examining the guest ... [ 3.0] Setting a random seed [ 3.0] Setting the hostname: guest1 [ 3.0] Setting the timezone: Europe/London [ 3.0] Installing packages: gcc $ virt-customize -a guest2.img \ --hostname guest2 --install /usr/bin/soffice [ 0.0] Examining the guest ... [ 5.0] Setting a random seed [ 5.0] Setting the hostname: guest2 [ 5.0] Installing packages: /usr/bin/soffice
As expected, each guest overlay uses a different amount of space depending on what has been installed:
$ ls -lh guest?.img -rw-r--r--. 1 rjones rjones 613M Mar 26 15:49 guest1.img -rw-r--r--. 1 rjones rjones 924M Mar 26 16:04 guest2.img
Sounds like you’re getting closer and closer to matching some of the functionality that vagrant+vagrant-libvirt provides.
In case this is misinterpreted, i think that guestfish+virt-* tools shouldn’t be seen as equivalents to vagrant. They are a different (and very useful) set of tools that are _also_ needed.
Keep up the good work!
PS:
It’s a shame that vagrant+vagrant-libvirt isn’t in Fedora yet. Boo hiss.
I wonder what the problem is with putting Vagrant into Fedora? There is a feature page and a bug which seems to have petered out last month.
So true! I don’t know either. I’m a hacker, not a paintainer… err package maintainer 🙂
Can one provide security updates to all the guests using the base image ?
No. You will corrupt all the guest images if you touch the backing file in any way.
Pingback: libguestfs 1.26 released | Richard WM Jones