Snapshot VMs

This past week at the  Red Hat summit I got the chance to demonstrate Enterprise IPA, the Red Hat version of FreeIPA, at the Red Hat booth.  One of the aspects of IPA we want to showcase is registering client systems.  That means that I wanted to be able to get a client system in the pre-installed state pretty very quickly.  My approach was to use Qemu/KVM virtual machines.  I had one VM image that I did not touch, and all the rest of the virtual machines will be snapshots that overlay that image.

I’ve tried no to go too deep in crafting the prototype VM image.  Pretty much the only things I’ve done are:

  1. yum install ipa-client and a few other required RPMS
  2. Removing the udev configuration in /etc/udev/rules.d/70-persistent-net.rules so that a vm with a new MAC address still will bring up eth0:

Here’s my clone-client script:




	echo "Usage $1  TYPE INDEX"
	echo "TYPE = [ client | server | replica ] "
	echo "INDEX = integer"

if [ -z $TARGET_INDEX ]
    exit 1

if [ $TARGET_INDEX -lt 0 ]
    exit 1

case $TARGET_TYPE in 
	exit 1


echo creating $TARGET_NAME




qemu-img create -f qcow2 -b $SOURCE_IMAGE  $TARGET_IMAGE

guestmount -a $TARGET_IMAGE --rw /mnt/vmdisks/  -m /dev/vg_root/lv_root
echo HOSTNAME=$TARGET_TYPE$ >> /mnt/vmdisks/etc/sysconfig/network

echo "supersede domain-name-servers :;"  >> /mnt/vmdisks/etc/dhclient-eth0.conf 

umount /mnt/vmdisks
virt-install --vcpus=1  --name $TARGET_NAME  --ram 1024  --import  --disk $TARGET_IMAGE

I tried to give DHCP a little help in finding the right nameservers by editing /mnt/vmdisks/etc/dhclient-eth0.conf to contain the line: supersede domain-name-servers :; This is a workaround for the qemu implementation of DNSMASQ/DHCP, but wouldn’t be necessary with a standard DHCP server. It seemed to work before the demo…but it stopped at some point. I till have no idea where the DHCP server was getting the values it was sticking into /etc/resolv.conf.

I could have used guestfish to modify the VM images, but it was easier for me to use standard bash utilities, and it would only have saved me a line or two of code.


3 thoughts on “Snapshot VMs

  1. Sweet, thanks for writing this up. Definitely going to give this a shot.

  2. Now you’re teaching me something I didn’t know before: I didn’t know you could use plain umount instead of fusermount -u 🙂

  3. Its just a mount point. But it was due to your earlier comments that I even knew to look for guestmount. Thanks, made things much simpler.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.