A lot of this tutorial was stolen from the CentOS wiki - http://wiki.centos.org/HowTos/Xen/InstallingCentOSDomU. I've shortened it by quite a bit to make it easier.  I assume you know this already but you will need to be logged in as root or have root privileges in order to execute this tutorial.

Creating an Image

The first step is to create an image that will hold the domU virtual disk. Since this can just be a file filled with zeros, our usual friend dd comes in handy.  The following command will create a /srv/xen/centos5.img file of 11GB, although the actual data blocks are allocated in a lazy fashion meaning that the disk image doesn't actually take up the whole 11GB until you fill it up. This is referred to as a sparse file.


dd if=/dev/zero of=/srv/xen/centos5.img oflag=direct bs=1M seek=10240 count=1


Preparing the Xen configuration file for installation

Xen uses one configuration file per domain. The configuration for the domain will be slightly different during the installation, because we have to provide installation kernels, and possibly some boot parameters. Here we download the installation kernel, ramdisk and xen config file.


wget http://mirror.centos.org/centos/5/os/i386/images/xen/vmlinuz -O /boot/vmlinuz-xen-install
wget http://mirror.centos.org/centos/5/os/i386/images/xen/initrd.img -O /boot/initrd-xen-install
wget http://www.grantmcwilliams.com/files/centos5-install -O /etc/xen/centos5


In this example, the kernel and initrd image will be named /boot/vmlinuz-xen-install and /boot/initrd-xen-install respectively. The third line downloads the centos5 DomU configuration file.


Example kickstart file

A kickstart file holds the instructions for installation, this one is very minimal which is handy if you would like to make copies of an image to deploy new instances rapidly.  To modify the kickstart files just download them from grantmcwilliams.com and store them on a web server that you manage. Make sure that you change the "extra =" line in the Centos5 DomU config file (downloaded above) to match though.


Starting the installation

With the installation configuration set up, you can launch the domU instance:


xm create -c centos5

After the installation, the domU will be rebooted and destroyed (since that is the default action for reboots, we will change that later).


Post install configuration

Now that the installation is finished, this can be a good time to make a copy of the instance image to use as a template.

The installation configuration should now be modified for non-install use. This is the modified configuration:


wget http://www.grantmcwilliams.com/files/centos5 -O /etc/xen/centos5

This new configuration is no longer be using the dowloaded kernel and initrd images but instead boot from the DomU /boot directory. This is very handy, because this will allow you to use/manage kernels in the domU. All system updates will be handled by yum-updates.d in the DomU.

With this configuration in place, you can test this domain:


xm create -c centos5


Now that your Xen server is running you can login. The password was set using the kickstart file.


    • Username: root
    • Password: bogus


Add additional repositories and packages

rpm -ivh http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm


Now install additional packages and update the complete OS. In the future I'll be adding more packages to the kickstart file as I see fit.


yum install vim-enhanced
yum update


Backup Virtual Image

Before you start modifying the base CentOS image you should back it up.

cp /srv/xen/centos5.img /srv/xen/centos5-base.img


Automatically starting our new Xen virtual machine

If you would like a domain to start automatically when the (dom0) system is started, move the domain configuration to the /etc/xen/auto directory. For instance:


ln -s /etc/xen/centos5 /etc/xen/auto/centos5

This will also shut down the domain properly when the system is shut down.