Howto: Virtualising with Xen under Debian Lenny (Linux Kernel 2.6.26)
This howto is about installing and configuring Xen under the Linux distribution Debian Lenny. It also shows some simple steps to create and manage Xen-images.
Xen belongs to the group of paravirtualization, there an hypervisor (which runs on the host system) distributes cpu-cycles and other resources to virtual guest systems. The guest system will be directly executed on the CPU, with the exception of system calls, which are forwarded to the hypervisor. This works without special hardware extensions at an amazing performance, closely to native speed. The only drawback is that the host system must be patched in order to use the hypervisor instead of real syscalls. Special kernel-patches for Linux, FreeBSD, Solaris, and other free operating systems are already available. If you like to run Windows, which can’t be patched, you must stick with hardware-virtualization, a feature that Xen now also offers.
But now to the installation: I show it with the 64bit version of Debian Lenny.
After the installation of Lenny, install the custom Xen kernel and Xen-Tools:
apt-get install xen-linux-system-2.6.26-1-xen-amd64 xen-utils-3.2-1 lvm2 python-xml xen-tools
In order to bridge the virtual network devices of your guests to the host system, you need to edit the configuration file /etc/xen/xend-config.sxp
This part is relevant:
##
# To bridge network traffic, like this:
#
# dom0: ----------------- bridge -> real eth0 -> the network
# |
# domU: fake eth0 -> vifN.0 -+
#
# use
#
(network-script network-bridge)
#
# Your default ethernet device is used as the outgoing interface, by default.
# To use a different one (e.g. eth1) use
#
# (network-script 'network-bridge netdev=eth1')
#
# The bridge is named xenbr0, by default. To rename the bridge, use
#
# (network-script 'network-bridge bridge=
#
# It is possible to use the network-bridge script in more complicated
# scenarios, such as having two outgoing interfaces, with two bridges, and
# two fake interfaces per guest domain. To do things like this, write
# yourself a wrapper script, and call network-bridge from it, as appropriate.
#
#(network-script network-dummy)
You must comment “(network-script network-dummy)” out as seen in the listing and remove the comment before “(network-script network-bridge)”
Now you can boot into your freshly installed Xen-Linux:
shutdown -r now
To check that everything works as expected run:
xm list Xm stands for Xen-management, a tool to manage your guest machines.
Is should say something like this:
olymp:~# xm list
Name ID Mem VCPUs State Time(s)
Domain-0 0 3242 4 r----- 266.8
Domain-0 is your host system and you haven’t created any guests yet.
You can do that very easily with the xen-tools, that you’ve already installed. You can set your default preferences for it very easily in the file /etc/xen-tools/xen-tools.conf. To use Debian Lenny 64bit as default guest, use the following configuration:
### /etc/xen-tools/xen-tools.conf#### This is the global configuration file for the scripts included# within the xen-tools package.## For more details please see:## http://xen-tools.org/####### File Format# ———–## Anything following a ‘#’ character is ignored as a comment.## Otherwise the format of this file "key = value". The value of# any keys in this file may be constructed via the output of a command.## For example:## kernel = /boot/vmlinuz-`uname -r`####### Output directory for storing loopback images.## If you choose to use loopback images, which are simple to manage but# slower than LVM partitions, then specify a directory here and uncomment# the line.## New instances will be stored in subdirectories named after their# hostnames.###dir = /home/xen###### If you don’t wish to use loopback images then you may specify an# LVM volume group here instead#### lvm = skx-vg##### Installation method.## There are four distinct methods which you may to install a new copy# of Linux to use in your Xen guest domain:## - Installation via the debootstrap command.# - Installation via the rpmstrap command.# - Installation via the rinse command.# - Installation by copying a directory containing a previous installation.# - Installation by untarring a previously archived image.## NOTE That if you use the "untar", or "copy" options you should ensure# that the image you’re left with matches the ‘dist’ setting later in# this file.####### install-method = [ debootstrap | rinse | rpmstrap | copy | tar ]##install-method = debootstrap## If you’re using the "copy", or "tar" installation methods you must# need to specify the source location to copy from, or the source# .tar file to unpack.## You may specify that with a line such as:## install-source = /path/to/copy# install-source = /some/path/img.tar###### Command definitions.#### The "rinse", and "rpmstrap" commands are hardwired into# the script, but if you wish to modify the commands which are executed# when installing new systems by a "copy", "debootstrap", or "tar" method# you can do so here:## (This allows you to install from a .tar.bz file, rather than a plain# tar file, use cdebootstrap, etc.)## install-method=copy:# copy-cmd = /bin/cp -a $src/* $dest###install-method=debootstrap:debootstrap-cmd=/usr/sbin/debootstrap## install-method=tar:# tar-cmd = /bin/tar –numeric-owner -xvf $src###### Disk and Sizing options.###size = 4Gb # Disk image size.memory = 256Mb # Memory sizeswap = 256Mb # Swap size# noswap = 1 # Don’t use swap at all for the new system.fs = ext3 # use the EXT3 filesystem for the disk image.dist = lenny # Default distribution to install.image = sparse # Specify sparse vs. full disk images.## Currently supported and tested distributions include:## via Debootstrap:## Debian:# sid, sarge, etch, lenny.## Ubuntu:# edgy, feisty, dapper.## via Rinse:# centos-4, centos-5.# fedora-core-4, fedora-core-5, fedora-core-6, fedora-core-7##### Networking setup values.#### Uncomment and adjust these network settings if you wish to give your# new instances static IP addresses.## gateway = 192.168.1.1# netmask = 255.255.255.0# broadcast = 192.168.1.255## Uncomment this if you wish the images to use DHCP#dhcp = 1### Misc options#### Uncomment the following line if you wish to disable the caching# of downloaded .deb files when using debootstrap to install images.## cache = no### Uncomment the following line if you wish to interactively setup# a new root password for images.#passwd = 1## If you’d like all accounts on your host system which are not present# on the guest system to be copied over then uncomment the following line.## accounts = 1### Default kernel and ramdisk to use for the virtual servers#kernel = /boot/vmlinuz-`uname -r`initrd = /boot/initrd.img-`uname -r`## The architecture to use when using debootstrap, rinse, or rpmstrap.## This is most useful on 64 bit host machines, for other systems it# doesn’t need to be used.#arch=amd64### The default mirror for debootstrap to install Debian-derived distributions#mirror = http://ftp.de.debian.org/debian/## A mirror suitable for use when installing the Dapper release of Ubuntu.## mirror = http://gb.archive.ubuntu.com/ubuntu/## If you like you could use per-distribution mirrors, which will# be more useful if you’re working in an environment where you want# to regularly use multiple distributions:## mirror_sid=http://ftp.us.debian.org/debian# mirror_sarge=http://ftp.us.debian.org/debian# mirror_etch=http://ftp.us.debian.org/debian# mirror_dapper=http://archive.ubuntu.com/ubuntu# mirror_edgy=http://archive.ubuntu.com/ubuntu# mirror_feisty=http://archive.ubuntu.com/ubuntu# mirror_gutsy=http://archive.ubuntu.com/ubuntu## Filesystem options for the different filesystems we support.#ext3_options = noatime,nodiratime,errors=remount-roext2_options = noatime,nodiratime,errors=remount-roxfs_options = defaultsreiser_options = defaults## Uncomment if you wish newly created images to boot once they’ve been# created.#boot = 1## If you’re using the lenny or later version of the Xen guest kernel you will# need to make sure that you use ‘hvc0′ for the guest serial device,# and ‘xvdX’ instead of ’sdX’ for serial devices.## You may specify the things to use here:#serial_device = hvc0 #default# serial_device = tty1#disk_device = xvda #default# disk_device = sda### Here we specify the output directory which the Xen configuration# files will be written to, and the suffix to give them.## Historically xen-tools have created configuration files in /etc/xen,# and given each file the name $hostname.cfg. If you want to change# that behaviour you may do so here.### output = /etc/xen# extension = .cfg#- Download this code: xen-tools.conf
Now you can use:
xen-create-image --hostname test1 --role=udev
to install a new Debian Lenny as guest system. If everything went as it should, you should see your new client after that in “xm list”. Otherwise it doesn’t show up and you can try to manuelly create it with “xm create
By the way “–role=udev” is needed, to install the package udev automatically in the guest. Without it, you can’t use ssh with your new guest and get the following error if you try to log in:
PTY allocation request failed on channel 0
stdin: is not a tty
If you use images for your guest (like shown here) you get very fast to the standard loopback limit of Debian Lenny. With that limit you can’t create more than 3 or 4 guests. It’s recommended to edit the file /etc/modprobe.d/local-loop (or create it) to adjust that limit:
options loop max_loop=64
Some more basics besides “xm list”: You can use “xm top” to monitor the activity of your guests (like top for processes). You can start, reboot and shutdown a guest with “xm start
You can enter a guest system directly with “xm console
For more commands you should read “xm help”