Xen
About
Xen (http://www.cl.cam.ac.uk/Research/SRG/netos/xen/) is a virtual machine monitor (VMM) for x86-compatible computers. Xen can securely execute multiple virtual machines, each running its own OS, on a single physical system with close-to-native performance. The VMM monitor itself runs in what is often referred to as Domain 0, virtual machines (VM) run in other Domains. See also Xen-strap
Prerequisites
Documentation
README file in
xen-3.0.2-src.tgz or xen-3.0.2-install-x86_32.tgz
Xen 3.0 User Manual http://www.cl.cam.ac.uk/Research/SRG/netos/xen/readmes/user.pdf
Hardware
A reasonably powerful box. I'm running Xen on:
- 2 processor Pentium III (Katmai) 600MHz, 512MB RAM.
- 1 processor Intel(R) Pentium(R) 4 CPU 1.80GHz, 512MB RAM.
- 1 processor Intel(R) Pentium(R) 4 CPU 3.00GHz, 4GB RAM.
- 2 processor Intel(R) Xeon(TM) CPU 2.80GHz, 4GB RAM.
- 1 processor Intel(R) Pentium(R) M 1.4GHz, 2GB RAM (IBM Thinkpad X31 laptop).
Software
OS
A Linux distribution. I chose Debian stable 3.1 as I was having difficulties with Xen domain 0 on Scientific Linux.
User:Andrew_elwell Also has Xen 3.1 running on Ubuntu 7.10
Xen
I chose to install Xen from a binary distribution (xen-3.0.2-install-x86_32.tgz), but compiled my Xen kernels from source (xen-3.0.2-src.tgz). Another possibility would be to use -xen modules from the binary distribution for both dom0 and domU. If you do that don't forget to generate initrd and add it to your boot loader.
Get both of these packages at http://www.xensource.com/xen/downloads/
Installation
Xen 3.0.2 Installation
# xr=<temporary_xen_installation_root> # mkdir -p $xr # tar zxvf xen-3.0.2-install-x86_32.tgz -C $xr # tar zxvf xen-3.0.2-src.tgz -C $xr
Read $xr/xen-3.0.2-2-install/README. In particular, you'll need to install bridge-utils and iproute packages.
# $xr/xen-3.0.2-2-install/install.sh
The script performs a few checks and installs Xen 3.0.2 (unpackaged) on your Linux box. The install script can be run several times (if you find it fails for some reason). It must exit 0 (all done).
Xen 3.0.2 kernel compilation
Kernel configuration files are stored in $xr/xen-3.0.2-2/buildconfigs
I've customised these: $xr/xen-3.0.2-2/buildconfigs/{linux-defconfig_xen0_x86_32,linux-defconfig_xenU_x86_32}
In particular, I've added support for IP tables and my network card.
# cd $xr/xen-3.0.2-2/ && KERNELS="linux-2.6-xen0 linux-2.6-xenU" make world
After compilation copy Xen kernels
# mkdir -p /boot/kernel/xen-3.0.2 # cp -a $xr/xen-3.0.2-2/dist/install/boot/* /boot/kernel/xen-3.0.2
and kernel modules
# cp -ra $xr/xen-3.0.2-2/dist/install/lib/modules /lib
on your Domain 0 box. You'll also need to copy 2.6.16-xenU modules on your Domain U (VM) boxes.
Image managers
After some time playing with Xen, you'll realise you need an OS image manager of some sort to help you installing and archiving VMs. I'm you'll find many of them around, but you'll probably be better off writing your own to suit your specific needs. I've written a simple dialog-based GUI Xen Image Manager (XIM). see also https://www.gridpp.ac.uk/wiki/Xen-strap http://www.gridpp.rl.ac.uk/pps/xen-strap/
Configuration
Domain 0
Grub
title Xen 3.0 (DEB-31) kernel /boot/kernel/xen-3.0.2/xen-3.0.gz dom0_mem=131072 console=vga module /boot/kernel/xen-3.0.2/vmlinuz-2.6.16-xen0 root=/dev/sda1 ro console=tty0
you may need to change /dev/sda1, it is my Xen Domain 0 root partition.
System configuration
Add /etc/init.d/xend to your init scripts.
You may also want to add a simple script to start all your virtual domains after your Domain 0 reboots.
for b in $(ls /etc/xen/*.rl.ac.uk) do xm create $b done
Sample configuration file
# cat /etc/xen/grumpy.esc.rl.ac.uk name="grumpy.esc.rl.ac.uk" memory=384 kernel="/boot/kernel/xen-3.0.2/vmlinuz-2.6-xenU" disk=['phy:sda5,hda2,w','file:/mnt/sda13/swap0,hda13,w'] root="/dev/hda2 ro" vif=['mac=aa:00:00:77:ca:8f'] ip="130.246.76.119" netmask="255.255.255.0" gateway="130.246.76.254" hostname="grumpy.esc.rl.ac.uk" restart='onreboot' extra="4" vnc=0
Domain U
Creating custom Xen images
Make sure that:
- /dev/* contains device files, especially /dev/console
- you edit /etc/fstab
- you do mv /lib/tls /lib/tls.disabled
- you have /lib/modules/2.6.16-xenU
See also https://www.gridpp.ac.uk/wiki/Xen-strap http://www.gridpp.rl.ac.uk/pps/xen-strap/
Testing
ttylinux
Start xend
# xend start
Make sure it worked:
# xm list Name ID Mem(MiB) VCPUs State Time(s) Domain-0 0 128 1 r----- 734.5
Get, unpack and modify ttylinux (or use https://www.gridpp.ac.uk/wiki/Xen-strap alternatively for other images)
# wget http://www.minimalinux.org/ttylinux/packages/ttylinux-5.0.tar.gz # tar zxvf ./ttylinux-5.0.tar.gz -C /boot ttylinux-5.0/rootfs.gz # cd /boot/ttylinux-5.0 # gzip -d rootfs.gz # mkdir -p mnt # mount -o loop rootfs mnt # mv mnt/etc/fstab mnt/etc/fstab.orig # sed 's|^/dev/ram0|/dev/sda1|' < mnt/etc/fstab.orig > mnt/etc/fstab # umount mnt # rmdir mnt
Create a Xen Domain U configuration file
# cat >/etc/xen/tty<<EOF kernel="/boot/kernel/xen-3.0.2/vmlinuz-2.6-xenU" memory=64 name="ttylinux" disk=['file:/boot/ttylinux-5.0/rootfs,sda1,w'] dhcp="dhcp" root="/dev/sda1 ro" extra="4" EOF
Start tty Domain U (VM) with attached console
# xm create tty -c
Login as root, password root.
OS tested and working on Xen 3.0.2
- CentOS 4.2
- Debian Linux 3.1 (stable), testing
- Fedora Core 4, 5
- NetBSD 3.0, 3.0.1
- OpenSolaris 5.11
- Scientific Linux 3.0.5, 3.0.7
- Scientific Linux 4.3
- Scientific Linux CERN 3.0.6
- Scientific Linux CERN 4.3
- SuSE 9.3 Enteprise Server, Professional; 10.1 (open)
- Ubuntu Linux 5.10, 6.06
- WhiteBox EL 4
Gotchas
As far as I know Xen 3.0.2 (in contrast to 2.0.7) works only with 2.6.x Linux kernels. If you want to use SL 3.0.x, you'll need modutils that support 2.6.x kernels, for example from SL 4.3.