Installing Xen 3.0 upon Debian Unstable, with a custom Kernel
Posted by Steve on Wed 28 Dec 2005 at 06:14
Recently we demonstrated the process of installing a binary release of Xen 3.0 on Sarge, since the packages on Debian Unstable are not yet available for Xen 3.0 we're now going to look at installing it via the packages provided by Ralph Passgang. This also includes building a custom Xen kernel from source.
The advantage to building the Xen kernel from source is that you can add, or remove, drivers - so the kernel is utterly customised for your system.
This is useful as I had problems with the binary kernel release upon my Sarge server, when booting Xen I lost access to my sound-card! When building the kernel from source this isn't a problem, as I can compile in the driver I need. (Or have it otherwise available as a module.)
Currently the Xen package in Debian's unstable release, sid, is a little behind the curve, so we're going to use a well-tested external source for our installation:
- Packages are available for x86
To get started we'll need to add the relevant lines to our /etc/apt/sources.list file. I've added:
# # Xen 3.0 packages by Ralph Passgang # deb http://packages.debianbase.de/sid/i386/xen3/ ./ deb-src http://packages.debianbase.de/sources/xen3 ./
(Note that packages are also available for Sarge, and Etch.)
Once the lines have been added update your APT lists by running:
root@itchy:~# apt-get update
Now we can install the software with the following command:
root@itchy:~# apt-get install xen Reading package lists... Done Building dependency tree... Done The following extra packages will be installed: fxload hotplug libxen-python libxen3.0 Suggested packages: ifrename The following NEW packages will be installed: fxload hotplug libxen-python libxen3.0 xen 0 upgraded, 5 newly installed, 0 to remove and 8 not upgraded. Need to get 0B/1093kB of archives. After unpacking 3304kB of additional disk space will be used. Do you want to continue [Y/n]?
The installation will install the xen hypervisor and userspace tools, as well as the required libraries for your system which might be different to those shown above.
Once the packages have been installed we're ready to start building a kernel to use for the server. To do that we need to install the Xen patch:
root@itchy:~# apt-get install linux-patch-xen
This patch is applied to the source code of a Linux kernel, so we'll need to fetch the kernel sources too - and also the required packages to build it. We'll get those first:
root@itchy:~# apt-get install kernel-package libncurses-dev wget
Once we have these packages installed we should be able to successfully fetch and build the kernel for our Xen installation. Firstly we'll fetch the code, and extract it:
root@itchy:~# wget ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.12.tar.bz2 root@itchy:~# tar -xjf linux-2.6.12.tar.bz2 root@itchy:~# cd linux-2.6.12
Now we can apply the patch, from within the kernel source directory:
root@itchy:~/linux-2.6.12# /usr/src/kernel-patches/i386/apply/xen START applying xen patch (xen kernel patch) Testing whether "xen kernel patch" patch for 2.6.12 applies "xen kernel patch" patch for 2.6.12 succeeded Removing empty files: Done. END applying xen patch root@itchy:~/linux-2.6.12#
To configure the kernel to our liking we can use the menuconfig option, making sure we specify that the kernel is being built for the Xen platform:
root@itchy:~/linux-2.6.12# make ARCH=xen menuconfig
Running the menuconfig target will save a configuration file which we need to build. So make sure you run that even if you don't intend to make any changes to the standard configuration.
Once the kernel has been configured to your liking you may use the make-kpkg command, included in the kernel-package package, to build a Debian package of the Xen kernel:
root@itchy:~/linux-2.6.12# make-kpkg --revision skx1 \ --append-to-version .6-xen \ --arch xen kernel_image
The "--revision skx1" argument will give your kernel package a unique name. Typically the --append-to-version flag isn't needed, but in this case it is required as the Xen patch silently updates the kernel to 188.8.131.52 - so we need to reflect this.
Eventually your new kernel should be successfully built. Once the build process has completed you should find the .deb file in the parent directory:
root@itchy:/home/xen/tmp/linux-2.6.12# cd .. root@itchy:/home/xen/tmp# ls *.deb linux-xen0-184.108.40.206-xen_skx1_i386.deb
Install the kernel with:
root@itchy:/home/xen/tmp# dpkg --install linux-xen0-220.127.116.11-xen_skx1_i386.deb
Once you've installed the kernel the next step is to build the initrd image, but before doing that you must disable TLS upon your host system:
root@itchy:~/linux-2.6.12# cd root@itchy:~# mv /lib/tls /lib/tls.disabled root@itchy:~# mkinitrd -o /boot/xen-modules-18.104.22.168-xen 22.214.171.124-xen
(Disabling the TLS libraries speeds up Xen, so it is a recommended option. However if you do it after building the initrd image Xen will be fooled into thinking that those libraries are still active and will complain. So we disable them beforehand to avoid this problem.)
Now that we've installed the Xen package, built and installed our custom kernel, we've only one thing left to do: Update the grub bootloader, and reboot!
Add the following to your /boot/grub/menu.lst file:
title Xen 3.0 / XenLinux 2.6 kernel /boot/xen-3.0.gz module /boot/xen-linux-126.96.36.199-xen root=/dev/hda1 ro console=tty0 module /boot/xen-modules-188.8.131.52-xen
Note: make sure you adjust the root parameter which is the root filesystem.
Once you've rebooted you should be ready to create and install a new Xen instance. I wrote some simple software to automate this [which is available in Sid] - but you can use debootstrap to create your own image manually if you wish.
If you're running a Debian Sid system you can create and boot a new instance of Debian Sarge, which will obtain its networking details via DHCP, by running:
root@itchy:~# apt-get install xen-tools root@itchy:~# mkdir -p /home/xen root@itchy:~# xen-create-image --dir=/home/xen --hostname=test.my.flat --dhcp \ --fs=ext3 --size=2Gb --swap-128Mb --kernel=/boot/xen-modules-184.108.40.206-xen root@itchy:~# xm create test.my.flat.cfg -c
For alternative options, (such as a static IP address, or different distribution of Debain), please see the manpage.