Basic script to create qcow2 backed kvm domains based on a golden domain. Your golden domain must be using qcow2
To install the dependencies on fedora 19 run the following:
yum install libvirt-client qemu-img libguestfs-tools xmlstarlet libxml2 The virt-sysprep tool can do much more than this and I could potentially set the hostname and configure the machine to run some scripts when it starts up to check in with puppet which I may do in the future.
Configuration for libvirt to get serial and graphics working at the same time:
virt-install \ --name centos6_golden \ --ram 2048 \ --arch x86_64 \ --vcpus 4 \ --disk path=/var/lib/libvirt/images/centos6_golden.disk,format=qcow2,sparse=true,size=24,bus=virtio \ --location http://repos.example.com/repos/centos/6.4/os/x86_64/ \ --hvm \ --accelerate \ --nographics \ --os-type linux \ --os-variant virtio26 \ --extra-args 'acpi=force noipv6 console=tty0 console=ttyS0,115200 ks=http://repos.example.com/kickstarts/el6.ks ksdevice=52:54:00:A8:7A:0A ip=192.168.122.10 gateway=192.168.122.1 netmask=255.255.255.0 dns=192.168.122.1 ' \ --network bridge:br250 \ --mac 52:54:00:A8:7A:0A Serial console in GRUB:
serial --speed=115200 --unit=0 --word=8 --parity=no --stop=1 terminal --timeout=15 serial console Change the kernel command line to attach ttys in the right spots. Remove rhgb and quiet and add the following to the kernel command line:
The txqueuelen is a value in the kernel on network interfaces that sets the transmit queue length. This value can be tuned for different work loads. In the case of modern networking the defaults can sometimes be changed to get better line speeds over ethernet. Most people will do this using a rc.local command to set it on the physical ethX devices like this.
vim /etc/rc.local Add the following
/sbin/ip link set eth0 txqueuelen 2500 This is a perfectly reasonable way of doing it but what happens when network interfaces appear after boot and the name is unknown before hand? This is exactly what happens with Libvirt vnetX interfaces. Ideally we would be able to get Libvirt to tune these interfaces when it creates them, but that level of control is yet to be implemented BZ#809172. Libvirt >= 0.8.0 has some hooks which enable you to run commands at specific times in the lifecycle of a guest which may be good for this but on RHEL 5 Libvirt is version 0.6.0 so I needed a different solution.
Libvirt is fast becoming the standard tool for managing virtual machines on Linux and Qpid is the Apache Foundation’s new implementation of AMQP which is the first open standard for Enterprise Messaging. These two technologies have the potential to work well together for large virtualization installations and luckily for us the good guys in the libvirt team have done just that http://libvirt.org/qpid/ but there are currently very few examples on how to use it. I am putting this brief tutorial in their wiki as a starting point for others but will continue to publish my experiences here.