One way to increase the efficiencies of Xen based systems is to utilize templates. VMware talks about this in their whitepaper for ESX2 best practices.
With Xen, you have to create your own. Here is a straight forward guide for how to do it.
1. Bootstrap a DomU named
I recommend using a file-backed VBD, but partition or LVM volume will work fine as well. Here is an example /etc/xen/centos4-tpl
This is just a normal system (DomU) install – see Centos-4 on Xen for an example. Un-customize files
2.Inside the VM, edit the following files
remove any address lines other than localhost
use a generic hostname which will be unique to each deployment
should look like this:
also important – remove any line starting with HWADDR, e.g.:
Other configuration files to consider tweaking include /etc/dhclient.conf & /etc/hosts
3. Files to remove:
– SSH Host key files (auto-created at boot time)
4. Shutdown the template VM
You might normally link your VMs into /etc/xen/auto. I recommend against this as the template VM can be left shutdown until/unless you want to update it, saving valuable RAM and CPU cycles.
Clone the virtual disk Now we can deploy from the template by cloning the data into a clean diskimage (or partition or LVM volume). Create the diskimage using an appropriate size (must be larger than the template). Oh -the nice thing here is that there is flexibility. For instance, you can have a file-based diskimage and clone the data onto LVM volumes. As long as you can mount the (virtual) disks, you can clone templatized systems.
Here we use /mnt/disk to mount the new system disk, and /mnt/image to mount the template disk.
First, mount the template disk.
Next, create and mount the new system (DomU) disk space & swap space.
Create the exclude file in /tmp/XenCloneExclude
Copy the data across
Chroot into the newly copied template and fixup certain files
Fix the hostname, etc in the files we “un-customized” in the template.
Exit, unmount both the template image and volume
Setup your Xen config and be on your way!
cp centos4-tpl cloned
(edit cloned to change name and paths to disk and swap)
xm create -c cloned