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:
- yum install ipa-client and a few other required RPMS
- 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:
#!/bin/bash
TARGET_TYPE=$1
TARGET_INDEX=$2
usage(){
echo "Usage $1 TYPE INDEX"
echo "TYPE = [ client | server | replica ] "
echo "INDEX = integer"
}
if [ -z $TARGET_INDEX ]
then
usage
exit 1
fi
if [ $TARGET_INDEX -lt 0 ]
then
usage
exit 1
fi
case $TARGET_TYPE in
client)
;;
server)
;;
replica)
;;
*)
usage
exit 1
esac
TARGET_NAME=summit-$TARGET_TYPE-$TARGET_INDEX
echo creating $TARGET_NAME
SOURCE_DIR=/var/lib/libvirt/images
TARGET_DIR=/var/lib/libvirt/images
SOURCE_NAME=ayoung-rhel6-client-disk0
SOURCE_IMAGE=$SOURCE_DIR/$SOURCE_NAME
TARGET_IMAGE=$TARGET_DIR/$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$TARGET_INDEX.ayoung.boston.devel.redhat.com >> /mnt/vmdisks/etc/sysconfig/network
echo "supersede domain-name-servers :192.168.122.1;" >> /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 :192.168.122.1; 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.
Sweet, thanks for writing this up. Definitely going to give this a shot.
Now you’re teaching me something I didn’t know before: I didn’t know you could use plain
umountinstead offusermount -u🙂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.