Xen

Administrator's Guide

Release 5.0

March 2007


Table of Contents

1. Installation
1.1. Installation of the dom0 on a Ubuntu system
1.1.1. Server kernel
1.1.2. Generic kernel
1.2. Installation of domU on a Ubuntu system
1.2.1. Template system
1.2.2. Duplication of systems
1.2.3. Automatically running domU on startup
2. Using Xen

Chapter 1. Installation

Xen is composed of two parts: the dom0 is the physical system with a running kernel, and one or more domU, the virtual systems.

1.1. Installation of the dom0 on a Ubuntu system

1.1.1. Server kernel

This section is only to install Xen on systems using a server kernel.

Install required packages:

apt-get install xen-hypervisor-3.0-i386-pae xen-utils-3.0
apt-get install bridge-utils xen-tools

A patched kernel higher than 2.6.17 is required.

Create an initrd image:

mkinitramfs -o /boot/xen0-linux-2.6.18-3-xen-vserver-686.initrd.img 2.6.18-3-xen-vserver-686

Update your grub configuration by adding the following at the top of the list:

title XEN/2.6.18
root (hd0,0)
kernel /boot/xen-3.0-i386-pae.gz
module /boot/xen0-linux-2.6.18-3-xen-vserver-686 root=/dev/xxx ro
module /boot/xen0-linux-2.6.18-3-xen-vserver-686.initrd.img

root=/dev/xxx must be replaced with the appropriate device.

The netloop module should be loaded before running xend. Add it to /etc/modules.

In order to use more than 4 domUs on the same dom0, the number of loop devices should be increased:

echo 'options loop max_loop=255' > /etc/modprobe.d/loop.local
for i in $(seq 8 255) ; do mknod /dev/loop$i b 7 $i ; done
chmod 664 /dev/loop*
chown 0.disk /dev/loop*

Starting too many domU simultaneously may crash the system. To avoid that, edit /etc/default/xendomains and set the following variables (usually already set to other values):

XENDOMAINS_CREATE_USLEEP=50000000
XENDOMAINS_RESTORE=false

Reboot the system to use the new kernel.

1.1.2. Generic kernel

This section is only to install Xen on systems using a generic kernel.

Install required packages:

apt-get install xen-hypervisor-3.0-i386 xen-image-xen0-2.6.17-6-generic-xen0 xen-utils-3.0
apt-get install bridge-utils xen-tools

Create an initrd image:

mkinitramfs -o /boot/xen0-linux-2.6.17-6-generic-xen0.initrd.img 2.6.17-6-generic-xen0

Update your grub configuration by adding the following at the top of the list:

title XEN/2.6.17
root (hd0,0)
kernel /boot/xen-3.0-i386.gz
module /boot/xen0-linux-2.6.17-6-generic-xen0 root=/dev/xxx ro
module /boot/xen0-linux-2.6.17-6-generic-xen0.initrd.img

root=/dev/xxx must be replaced with the appropriate device.

Reboot the system to use the new kernel.

1.2. Installation of domU on a Ubuntu system

1.2.1. Template system

Edit /etc/xen-tools/xen-tools.conf, and adapt it to your preferences. The most important values are mirror, kernel and initrd.

Install the base system by using xen-create-image. For example, for an edgy system with 20Gb of hard drive, 1Gb of memory and 1 Gb of swap, use:

xen-create-image --debootstrap --ip=IP_ADDRESS --hostname=HOSTNAME --dir=DESTDIR \
	--dist=edgy --size=20Gb --memory=1024Mb --swap=1024Mb

This should create a disk image in DESTDIR/domains/HOSTNAME/disk.img

You can now create the first domU with

xm create -c /etc/xen/HOSTNAME.cfg

You should see the system starting up in the console. Log in as root (the first time, the password is empty), and configure the system with everything needed on each system.

A base system includes for example: a kernel with its modules (using the same kernel as the dom0 is the easiest solution), users with password, configured base packages, a configured network. See the Debian/Ubuntu installation guide for more information.

1.2.2. Duplication of systems

To create another system quickly, use the template system. Mount it on a temporary directory, e.g. /mnt/loop, with the following command:

mount -o loop DESTDIR/domains/HOSTNAME/disk.img /mnt/loop

You can now quickly duplicate the images by editing /mnt/loop/etc/network/interfaces, /mnt/loop/etc/hostname and any other specific configuration file. This may be scripted if you have many system to configure. The /mnt/loop directory should be considered as the root directory. Now, run:

xen-create-image --copy=/mnt/loop --ip=IP_ADDRESS_2 --hostname=HOSTNAME_2 --dir=DESTDIR \
	--dist=edgy --size=20Gb --memory=1024Mb --swap=1024Mb

1.2.3. Automatically running domU on startup

This can be achieved with the following commands:

cd /etc/xen/auto
for file in ../lm*.cfg; do basename $file | while read a; do ln -s ../$a $a; done; done;

This later command creates a symbolic link in /etc/xen/auto for each configuration file found in /etc/xen.

Chapter 2. Using Xen

The xm command allows one to monitor every system. The xm manpage is quite exhaustiv.

In case of problems, Xen logs everything in /var/log/xen/ on the dom0.

Useful links: http://xen-tools.org/software/xen-tools/ for easy creation of images and https://help.ubuntu.com/community/XenVirtualMachine/XenOnUbuntuEdgy for an example of a complete procedure.