Installing Xen On An Ubuntu 7.10 (Gutsy Gibbon) Server From The Ubuntu Repositories

Version 1.0
Author: Falko Timme
Last edited 10/30/2007

This tutorial provides step-by-step instructions on how to install Xen on an Ubuntu Gutsy Gibbon (Ubuntu 7.10) server system (i386). You can find all the software used here in the Ubuntu repositories, so no external files or compilation are needed.

Xen lets you create guest operating systems (*nix operating systems like Linux and FreeBSD), so called "virtual machines" or domUs, under a host operating system (dom0). Using Xen you can separate your applications into different virtual machines that are totally independent from each other (e.g. a virtual machine for a mail server, a virtual machine for a high-traffic web site, another virtual machine that serves your customers' web sites, a virtual machine for DNS, etc.), but still use the same hardware. This saves money, and what is even more important, it's more secure. If the virtual machine of your DNS server gets hacked, it has no effect on your other virtual machines. Plus, you can move virtual machines from one Xen server to the next one.

I will use Ubuntu Gutsy Gibbon (i386) for the host OS (dom0) and Ubuntu Gutsy Gibbon and Ubuntu Feisty Fawn for the guest operating systems (domU). Other Debian-based distributions that can be installed using xen-tools are Debian Etch, Debian Lenny, Debian Sid, and Debian Sarge, as well as Ubuntu Dapper Drake and Ubuntu Edgy Eft.

This howto is meant as a practical guide; it does not cover the theoretical backgrounds. They are treated in a lot of other documents in the web.

This document comes without warranty of any kind! I want to say that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!

 

1 Install The Ubuntu Gutsy Gibbon Host System (dom0)

You can install the host system (dom0) as shown in the chapters one to nine of this tutorial: http://www.howtoforge.com/perfect_server_ubuntu7.10 (of course, you don't have to do this if you already have an Ubuntu 7.10 host system that you want to use).

Make sure that you are logged in as root (type in

sudo su

to become root), because we must run all the steps from this tutorial as root user. Also, if you want to use vi as your text editor (as suggested by this tutorial), you should run

apt-get install vim-full

The vim-full package makes sure that the vi text editor behaves as expected (without vim-full, you might experience some strange behaviour in the vi text editor).

dom0's FQDN in this example will be server1.example.com. server1.example.com's IP address will be 192.168.0.100 in this tutorial, and the gateway I use is 192.168.0.1, so the virtual machines will have to use that one, too.

 

2 Install Xen

To install Xen and all needed dependencies, all we have to do is run the following command:

apt-get install ubuntu-xen-server

This will also install the xen-tools package which we use later on to create virtual machines.

Now we edit /etc/xen/xend-config.sxp. Comment out the (network-script network-dummy) line and add (network-script network-bridge) right above the (vif-script vif-bridge) line, like this:

vi /etc/xen/xend-config.sxp

[...]
#(network-script network-dummy)

# The script used to control virtual interfaces.  This can be overridden on a
# per-vif basis when creating a domain or a configuring a new vif.  The
# vif-bridge script is designed for use with the network-bridge script, or
# similar configurations.
#
# If you have overridden the bridge name using
# (network-script 'network-bridge bridge=<name>') then you may wish to do the
# same here.  The bridge name can also be set when creating a domain or
# configuring a new vif, but a value specified here would act as a default.
#
# If you are using only one bridge, the vif-bridge script will discover that,
# so there is no need to specify it explicitly.
#
(network-script network-bridge)
(vif-script vif-bridge)
[...]

We also need to add the loop module to the kernel every time we boot our system, so we edit /etc/modules. If you already have a loop line in there, make it look like this, otherwise add it:

vi /etc/modules

[...]
loop max_loop=64
[...]

Now take a look at the /boot directory to see which kernels and ramdisks are installed:

ls -l /boot/

root@server1:~# ls -l /boot/
total 32948
-rw-r--r-- 1 root root  424317 2007-10-15 03:42 abi-2.6.22-14-server
-rw-r--r-- 1 root root   75416 2007-10-15 03:42 config-2.6.22-14-server
-rw-r--r-- 1 root root   76107 2007-10-15 03:49 config-2.6.22-14-xen
drwxr-xr-x 2 root root    4096 2007-10-30 13:02 grub
-rw-r--r-- 1 root root 7080785 2007-10-18 12:57 initrd.img-2.6.22-14-server
-rw-r--r-- 1 root root 6794412 2007-10-18 12:50 initrd.img-2.6.22-14-server.bak
-rw-r--r-- 1 root root 6871299 2007-10-30 13:02 initrd.img-2.6.22-14-xen
-rw-r--r-- 1 root root 6871266 2007-10-30 13:01 initrd.img-2.6.22-14-xen.bak
-rw-r--r-- 1 root root  103204 2007-09-28 12:06 memtest86+.bin
-rw-r--r-- 1 root root  828819 2007-10-15 03:42 System.map-2.6.22-14-server
-rw-r--r-- 1 root root  806408 2007-10-15 03:49 System.map-2.6.22-14-xen
-rw-r--r-- 1 root root 1787224 2007-10-15 03:42 vmlinuz-2.6.22-14-server
-rw-r--r-- 1 root root 1596690 2007-10-15 03:49 vmlinuz-2.6.22-14-xen
-rw-r--r-- 1 root root  308810 2007-10-12 17:10 xen-3.1.gz
root@server1:~#

The /boot/vmlinuz-2.6.22-14-xen kernel is the Xen kernel that got installed together with the ubuntu-xen-server package, and /boot/initrd.img-2.6.22-14-xen is its ramdisk. We will need these soon.

You can now also take a look at the /usr/lib/xen-tools directory because it reveals which distributions can be installed in a virtual machine with xen-tools:

ls -l /usr/lib/xen-tools

root@server1:~# ls -l /usr/lib/xen-tools
total 32
drwxr-xr-x 2 root root 4096 2007-10-30 13:00 centos4.d
-rwxr-xr-x 1 root root 4306 2007-09-17 01:13 common.sh
drwxr-xr-x 2 root root 4096 2007-10-30 13:00 dapper.d
drwxr-xr-x 2 root root 4096 2007-10-30 13:00 debian.d
drwxr-xr-x 2 root root 4096 2007-10-30 13:00 edgy.d
lrwxrwxrwx 1 root root    8 2007-10-30 13:00 etch.d -> debian.d
drwxr-xr-x 2 root root 4096 2007-10-30 13:00 fedora.d
lrwxrwxrwx 1 root root    6 2007-10-30 13:00 feisty.d -> edgy.d
drwxr-xr-x 2 root root 4096 2007-10-30 13:00 gentoo.d
lrwxrwxrwx 1 root root    6 2007-10-30 13:00 gutsy.d -> edgy.d
lrwxrwxrwx 1 root root    8 2007-10-30 13:00 lenny.d -> debian.d
lrwxrwxrwx 1 root root    8 2007-10-30 13:00 sarge.d -> debian.d
lrwxrwxrwx 1 root root    8 2007-10-30 13:00 sid.d -> debian.d
lrwxrwxrwx 1 root root    8 2007-10-30 13:00 stentz.d -> fedora.d
root@server1:~#

As you see we can install the following distributions:

  • Debian: Etch, Lenny (testing), Sid (unstable), Sarge
  • Ubuntu: Dapper Drake, Edgy Eft, Feisty Fawn, Gutsy Gibbon
  • CentOS 4
  • Fedora Core 4 (Stentz)
  • Gentoo

(I haven't tried to install CentOS, Fedora, and Gentoo with xen-tools yet, so I can't say how good it works.)

I want to store my virtual machines in the /home/xen directory, therefore I create it now:

mkdir /home/xen

We will use xen-tools to create virtual machines. xen-tools make it very easy to create virtual machines - please read this tutorial to learn more: http://www.howtoforge.com/xen_tools_xen_shell_argo. As mentioned before, the xen-tools package got installed together with the ubuntu-xen-server package.

Now we edit /etc/xen-tools/xen-tools.conf. This file contains the default values that are used by the xen-create-image script unless you specify other values on the command line. I changed the following values and left the rest untouched:

vi /etc/xen-tools/xen-tools.conf

[...]
dir = /home/xen
[...]
dist   = gutsy     # Default distribution to install.
[...]
gateway   = 192.168.0.1
netmask   = 255.255.255.0
broadcast = 192.168.0.255
[...]
passwd = 1
[...]
mirror = http://de.archive.ubuntu.com/ubuntu/
[...]

The dist line holds the default distribution that you want to install in a virtual machine. The contents of the /usr/lib/xen-tools directory reveals which distributions are available (see above).

The kernel line must contain our Xen kernel, and the initrd line its ramdisk. The default /etc/xen-tools/xen-tools.conf file has the values kernel = /boot/vmlinuz-`uname -r` and initrd = /boot/initrd.img-`uname -r` which automatically translate to the correct kernel and ramdisk, so we don't have to modify these lines.

The passwd = 1 line makes that you can specify a root password when you create a new guest domain. In the mirror line specify an Ubuntu mirror close to you.

Make sure you specify a gateway and netmask. If you don't, and you don't specify a gateway and netmask on the command line when using xen-create-image, your guest domains won't have networking even if you specified an IP address!

Now reboot the system:

shutdown -r now

If your system reboots without problems, then everything is fine!

Run

uname -r

and your new Xen kernel should show up:

root@server1:~# uname -r
2.6.22-14-xen
root@server1:~#

Share this page:

8 Comment(s)

Add comment

Comments

From: at: 2007-11-09 21:46:48

rpmstrap is presently broken on Gutsy, and you will need to always issue rpmstrap commands with "bash" explicitly called.  Otherwise it will fail with obscure shell complaints.

 in short: instead of "rpmstrap ..." use "bash `which rpmstrap` ..."

From: at: 2008-03-25 01:22:38

One more step required to use the xm console facility with versions of xen-hypervisor etc.
packages circa March 2008: need to add this to /etc/xen/server.cfg:
 
 extra = 'xencons=tty'
 
This passes a kernel command line option that causes the Xen console to work with the
xm console command (as described in this most excellent document).
 
Otherwise the Xen guest console appears to go to a virtual framebuffer (vfb) and this document
does not discuss how to view that (probably needs a GUI environment). 

From: at: 2007-11-15 12:07:58
From: at: 2007-11-19 08:05:49

Falko, Thanks for a great tutorial.

I tried it and was most impressed, until... I rebooted the guest.

From there on in whenever the guest is started it will not attach to the network! You cannot ping it, you cannot ssh, you cannot get a console - more Dr Zeus then xen (sorry).

Well after a couple of late nights  I found that the config file needs to know the original mac address in order to re-start the machine. Perhaps the create-xen-image command has inherited more security since you first did the tutorial - apparmour? Anyway, here are my suggested add-ons to the above:

Obtain the MAC address first thing after you boot the guest ie:

ping xen1

arp xen1

Now configure the virtual NIC to always use that MAC address:

vi /etc/xen/xen1.example.com.cfg

vif         = [ 'mac=00:16:3E:6C:A5:5C', 'ip=192.168.0.106' ]

 

Voila! 


From: at: 2008-01-25 02:31:50

I add the following two lines to /etc/udev/rules.d/70-persistent-net.rules. They cause the OS to assign the interfaces by the device path, rather than the MAC address, which is what leads to the problem you are seeing.

SUBSYSTEM=="net", SUBSYSTEMS=="xen", DRIVERS=="vif", ATTRS{nodename}=="device/vif/0", NAME="eth0"
SUBSYSTEM=="net", SUBSYSTEMS=="xen", DRIVERS=="vif", ATTRS{nodename}=="device/vif/1", NAME="eth1"

From: at: 2008-04-02 01:39:51

Thanks for the net rules, they did the trick.  But, it took me a while to figure out that the /etc/udev/rules.d/70-persistent-net.rules file to fix is on the domU disk image.  I tried changing the one on my actual (dom0) boot disk, and got very confused.  Once I realised that it was the domU having the network problems, and that I needed only to fix it's /etc/udev/rules.d/ and it's /etc/networking/interfaces was ok.  (I use LVM, so I just mounted the domU root disk and fixed it before starting it up with 'xm create'.)

 

From: at: 2008-04-02 12:17:58

I wrote up a little how-to configure the /etc/udev/rules.d/70-persistent-net.rules and the vif in the domU .cfg to solve the problem of networking not working, or networking stops working, or eth interface number increasing:

http://adminstuff.wikidot.com/xen-bridge-networking

From: at: 2008-01-09 05:17:59

Gutsy has xen-tools version 3.5, and from 3.2 on --deboostrap and --rpmstrap are obsolete. See the man page or http://www.xen-tools.org/software/xen-tools/upgrading.html

That said, the version of rpmstrap available on gutsy does not work out of the box for xen. I'm still working on that.