Howto: Virtualisierung mit Xen unter Debian Lenny (Linux Kernel 2.6.26)
In diesem Howto geht es darum, die Linux Distribution Debian Lenny um die Xen Virtualisierung zu erweitern. Es werden auch einfache Schritte zum erstellen und verwalten von Images gezeigt.
Xen gehört zur Gruppe der Paravirtualisierung, hierbei wird einem sogennaten Hypervisor (der auf dem Hostsystem läuft) die Aufgabe zugeteilt Resourcen virtuell an Gastsysteme zu verteilen. Das Gastsystem wird dabei direkt auf der CPU ausgeführt, mit Ausnahme von Systemcalls, die an den Hypervisor weitergeleitet werden. Damit kann ohne spezielle Hardwareerweiterung eine erstaunliche Performance erzielt werden, die der nativen sehr Nahe kommt. Der einzige Nachteil ist, dass das Gastsystem angepasst werden muss, um nicht echte Syscalls zu benutzten, sonden die des Hypervisors. Anpassungen für Linux, Freebsd, Solaris und andere freie Betriebsysteme stehen bereits, für Windows gibt es sowas leider nicht.
Aber nun zur Installation, die ich Beispielsweise an einem 64-bit Debian Lenny vormache:
Nachdem man Lenny installiert hat, installiert man den angepassten Xen-Kernel und die Xen-Tools:
apt-get install xen-linux-system-2.6.26-1-xen-amd64 xen-utils-3.2-1 lvm2 python-xml xen-tools
Um die Netzwerk-devices unserer Gastsysteme im folgenden zu bridgen, editieren wir die Datei /etc/xen/xend-config.sxp
Folgender Abschnitt ist 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)
Dabei muss (network-script network-dummy) wie ihm Codelisting auskommentiert werden und für das Bridging (network-script network-bridge) einkommentiert werden.
Nun muss man das System mit dem neuen Kernel booten:
shutdown -r now
Um zu checken, ob alles geklappt hat, führen wir:
xm list aus. Xm steht da bei für Xen Management, womit man seine virtuellen Systeme verwalten kann.
Es sollte dabei etwas ähnliches wie das hier:
olymp:~# xm list
Name ID Mem VCPUs State Time(s)
Domain-0 0 3242 4 r----- 266.8
erscheinen. Domain-0 ist unser Hostsystem, wir haben noch keine Gäste erstellt.
Das geht sehr bequem mit den Xen-Tools, die wir bereits installiert haben. Mit der Datei /etc/xen-tools/xen-tools.conf können die Vorgaben bequem editiert werden. Um standartmäßig Debian Lenny 64bit als Gastsystem zu installieren, kann man folgende Anpassungen verwenden:
### /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
Nun kann mittels
xen-create-image --hostname test1 --role=udev
bequem eine neue Lenny Installation eingerichtet werden. Da wir in xen-tools.conf eingestellt haben, den neuen virtuellen Gast automatisch zu booten, sollten wir ihn auch schon mit “xm list” sehen können. Sollte etwas schief gelaufen sein, erscheint der Gast nicht und man kann mittels “xm create
–role=udev ist übrigens nötig, um automatisch udev im Gast zu installieren. Ohne udev kann man sich nicht per ssh in den Gast einloggen und erhält diese Fehlermeldung:
PTY allocation request failed on channel 0
stdin: is not a tty
Desweiteren kommt man bereits nach 3-4 Gästen an das Standart-Limit der Loopback-Device von Lenny. Es empfiehlt sich in jedem Fall die Datei /etc/modprobe.d/local-loop zu editieren und folgende Zeile hinzuzufügen:
options loop max_loop=64
Ein paar weitere Basics neben “xm list” zum Management der Gäste: mit “xm top” kann die Auslastung der Gäste betrachtet werden. Es ähnelt dem Tool top, zur Anzeige der Prozessauslastung. Mit “xm start
Mit “xm console
Für weitere Kommandos empfehle ich einen Blick auf den Hilfetext, “xm help”
Klasse Kurztrip zu XEN! Danke
Die Seite rufe ich bei jeder neuen Erstellung einer DomU auf.
Kurz, knapp, alles Wichtige zusammengefasst. Die beste Kurzdoku die ich bisher gefunden habe.
Vielen Dank!
Na bitte, da hat mir deine config doch glatt den Abend gerettet.
Wie schon gesagt: kurz, knapp, klasse. *Daumen hoch*