Setting Up Xen From Scratch

Setting Up Xen From Scratch

Xen is a virtual machine monitor for x86 that supports executing multiple guest operating systems with high levels of performance and resource isolation. The following explains how to set up and run a Linux system with one or more Xen domains. Prerequisites include an installed and networked Fedora Core 4 system and the following required packages:

  • grub
  • bridge-utils
  • iproute
  • python
  • python-twisted
  • gcc
  • libcurl2
  • libcurl2-dev
  • zlib1g
  • zlib1g-dev

Installing the Required Packages

The Xen package and dependencies can be installed by using the following YUM command:

> yum update
> yum install xen

Additionally, the Xen domain0 and user domain kernels need to be installed.

> yum install kernel-xen0.i686
> yum install kernel-xenU.i686

This will also create an entry in the /boot/grub/menu.lst file so that the domain0 kernel can be booted. Domain0 is where the Xen daemon is started and further domains can be created.

Creating a Xen Domain File System

Domain is the term Xen developers use to describe a virtual machine. Any number of domains can be created on a host machine as long as sufficient resources are available. Although it is possible to create a domain file system of any Linux flavor (or NetBSD or FreeBSD), the following information outlines how to create a Debian Linux file system.

The first step is to create the file system and swap images. Depending on the amount of software you want installed in the domain, these images will vary in size. For a minimal install, the file system image can be as small as 200 MB. The swap image should be the same size as the amount of RAM you want the domain to allocate.

> dd if=/dev/zero of=deb3.1.img bs=1024k count=200
> dd if=/dev/zero of=swap64.swp bs=1024k count=64

Then, initialize.

>mkfs.ext3 deb3.1.img
>mkswap swap64.swp

Note: The next steps must be done on an Ubuntu or Debian system. The required debootstrap program to create a minimal Debian install is only available on Ubuntu and Debian systems. Optionally, you can use the program alien to convert the Debian package to an RPM and install it on an rpm-based system.

>apt-get install debootstrap

Mount the newly created file system image.

>mkdir /mnt/debian
>mount -o loop deb3.1.img /mnt/debian

Create the base Debian installation.

>debootstrap --arch i386 sarge /mnt/debian http://ftp.us.debian.org/debian

At this point your system is an unconfigured base system. Edit the following files to establish a valid configuration.

  • /etc/fstab
  • /etc/hostname
  • /etc/hosts
  • /etc/network/interfaces
  • /etc/apt/sources.list

The following entries should be made to /etc/fstab:

fstab
/dev/sda1 	 /     ext3     defaults 0 1 
/dev/sda2	 swap  swap     defaults 0 0
proc	         /proc   proc   defaults 0 0

The following should be listed in /etc/sources.list:

deb http://ftp.at.debian.org/debian/ sarge main
deb http://security.debian.org sarge/updates main

Edit the /etc/network/interfaces file to set up networking. The following setup uses DHCP to obtain network settings:

auto lo
iface lo inet loopback
auto eth0
iface eth0 inet dhcp
Creating a Domain Configuration File

There are two ways to set domain parameters before starting a domain. One way is to specify all the domain parameters in a configuration file. Alternatively, you can set the necessary parameters at run time. The following is an example configuration file for the file system just created:

#Set the name of the Xen domain
name="Xen-domain"
#Set the kernel the domain uses to boot (must be #xenU)
kernel="/boot/vmlinuz-2.6.11-1.1369_FC4xenU"
#Set the domain	memory (this must be available)
memory=64
#Set the hdds up
disk=['file:/path/to/deb3.1.img,sda1,w','file:/path/to/swap64.swp,sda2,w']
root="/dev/sda1,rw"
restart="onreboot"

The new domain can now be started. First start Xen if it's not running, then create the domain:

>/etc/init.d/xend start
>xm create deb3.1.conf -c

You should now see the new domain booting up. Log in as root (no password) and go ahead and update apt and install any additional packages needed.

> apt-get update
> apt-get install XXX
Shared /usr Directory

To further cut-down on file system image size, it is possible to share a common NFS-mounted /usr directory between multiple domains. To do this, create an NFS export in domain0. All software that is installed will then be common to each domain that is run.

Custom IP Address

Xen does not allow setting the domain IP via the configuration file. To work around this, you can pass in kernel parameters with the extra="xxx=yyy aaa=bbb" domain configuration parameter. Then, custom startup scripts can be created and called from /etc/init.d/rcS to catch these parameters and set up the /etc/network/interfaces file as required.

See Also


Home Up Previous Next
Searches Moab documentation only