- Category: Xen Howtos
- Published: September 23, 2009
- Written by Grant
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/x86_64/images/xen/vmlinuz -O /boot/vmlinuz-xen-install
wget http://mirror.centos.org/centos/5/os/x86_64/images/xen/initrd.img -O /boot/initrd-xen-install
wget http://www.grantmcwilliams.com/files/centos5_64-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. My example kickstart file is very minimal. To modify the kickstart files just download them from grantmcwilliams.com and store them on a web server that you manage. If you want to create a new kickstart file you can use system-config-kickstart, then store it on a webserver and change the "extra=" line in /etc/xen/centos5 xen DomU file that you downloaded earlier.
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
The installation configuration should now be modified for non-install use. Use wget to download the DomU config file.
wget http://www.grantmcwilliams.com/files/centos5_64 -O /etc/xen/centos5
This new configuration is no longer using the dowloaded kernel and initrd images. Instead, it is using pygrub as a bootloader which works similar to GRUB and uses the grub.conf file and boots the kernel listed there. This is very handy, because this will allow you to use/manage kernels in the domU. If yum update in the Virtual Machine pulls in a security updated kernel it will automatically be used during the next boot of the domain. Another change is that we have changed how to handle crashes and reboots. You'll usually want to reboot a domain if a crash or reboot occurs.
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.x86_64.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
Backup Virtual Image
Before you start modifying the base CentOS image you should back it up.
cp /srv/xen/centos5.img /srv/xen/centos-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.