The
This guide will talk you through the configuration steps necessary to get Xen up
and running on Gentoo Linux. We will not discuss Xen itself (the Xen project has
A dramatic change that might be necessary is to rebuild the entire Gentoo
installation with a different
~# nano -w /etc/make.conf(Add -mno-tls-direct-seg-refs) CFLAGS="-O2 -march=pentium4 -pipe -mno-tls-direct-seg-refs" ~# emerge -e world
If you boot your system using an initial ramdisk (initrd) you need to rebuild the initrd as well (which is best done by running all steps you would do when you rebuild your kernel).
Xen actually contains many components, so you'll need to install a couple of
packages. Because it is still
~# nano -w /etc/portage/package.keywords app-emulation/xen app-emulation/xen-tools sys-kernel/xen-sources ~# emerge xen xen-tools xen-sources
Next we'll build the Linux kernel with Xen support. This kernel, whose sources
are available at
Of course, don't forget to select
Processor type and features --->
Subarchitecture Type (Xen-compatible)
Processor type and features --->
Subarchitecture Type (PC-compatible)
[*] Enable Xen compatible kernel
Bus options (PCI etc.) --->
[*] PCI support
[ ] Xen PCI Frontend Debugging
Networking --->
Networking options --->
<*> 802.1d Ethernet Bridging
Only required by bridged networking.
XEN --->
[*] Privileged Guest (domain 0)
<*> Backend driver support
<*> Block-device backend driver
<*> Network-device backend driver
<*> PCI-device backend driver
PCI Backend Mode (Virtual PCI) --->
[*] Scrub memory before freeing it to Xen
[*] Disable serial port drivers
Xen version compatibility (3.0.4 and later)
Bus options (PCI etc.) --->
[ ] PCI support
Device Drivers --->
SCSI device support --->
< > SCSI device support
Disabling SCSI support frees up the /dev/sd* device names
for use as Xen virtual block devices.
XEN --->
[ ] Privileged Guest (domain 0)
<*> Block-device frontend driver
<*> Network-device frontend driver
[*] Scrub memory before freeing it to Xen
[*] Disable serial port drivers
Xen version compatibility (3.0.4 and later)
A nice hint is to have the kernel make process store its intermediate object files elsewhere so that you can reuse the same kernel tree to build different configurations:
~# mkdir -p ~/build/dom0 ~/build/domU ~# make O=~/build/dom0 menuconfig(Configure the kernel) ~# make O=~/build/dom0 && make O=~/build/dom0 modules_install
Once the kernel is built you'll find the kernel image immediately in the
build directory (not inside
title Xen 3.0 / Gentoo Linux 2.6.x.y root (hd0,0) kernel /boot/xen.gz module /boot/kernel-2.6.x.y-xen0 root=/dev/hda3
Now reboot your system into Xen. Once you are booted, you need to load the Xen daemon:
~# /etc/init.d/xend start
Now check if you can do whatever you normally do on your system. If this is the case, you can edit your bootloader configuration to always boot into Xen and add the Xen deamon to the default runlevel so that it is started automatically next time you boot.
Go to the Xen-powered Linux kernel source and update the configuration. It is
wise to keep as many topics as possible similar to the main kernel except the
~# make O=~/build/domU ~# cp ~/build/domU/vmlinuz /mnt/data/xen/kernel/kernel-2.6.x.y-xen
It is also possible to create a single kernel image for both the administrative domain and the unpriviledged domain. More information about this can be found in the Xen user manual.
For best performance, it is best to dedicate a partition (or logical volume) to a domain rather than a file based filesystem. However, if you are going to use Xen primarily for tests using a file based filesystem does have its advantages (especially regarding maintenance).
You can create a file based filesystem using
~# dd if=/dev/zero of=/mnt/data/xen/disks/ext3root.img bs=1M count=2048 ~# mke2fs -j /mnt/data/xen/disks/ext3root.img
Next we create a Xen configuration file for a domain. You can store these
configuration files where you want, for instance at
~# nano -w /mnt/data/xen/configs/gentoo kernel = "/mnt/data/xen/kernel/kernel-2.6.x.y-xen" memory = 512 name = "gentoo"(Map the disk image to the virtual /dev/sda1) disk = ['file:/mnt/data/xen/disks/ext3root.img,sda1,w'] root = "/dev/sda1 ro"
If you are using a block device (such as an lvm volume or partition) for the disk use 'phy:' instead of 'file:' and leave off /dev. For example:
(LVM Volume) disk = [ 'phy:lvm/xen-guest-root,sda1,w' ](Physical Partition) disk = [ 'phy:sdb6,sda1,w' ]
You can find example configuration files in
Now we're all set and we can launch the new domain. If the disk image contained
an operating system, we could just create and attach the domain using the
~# xm create /mnt/data/xen/configs/gentoo -c
The domain would be booted inside the terminal in which you executed the command. However, in our case, the disk image is empty so the domain won't boot up in anything useful. To fix this, you can loop-mount the image and install Gentoo as you're used to.
If you want to disconnect from the domain, press
Xen supports at least two ways of configuring your (virtual) network:
When selecting the
When selecting the
Before you set up the interface on your unpriviledged domain, make sure that
Xen's
~# nano -w /mnt/data/xen/configs/gentoo(Add the vif instruction) vif = [ 'ip=192.168.1.101, vifname=veth1' ]
In the above example, the interface will be created for the unpriviledged domain
(in which it will be called
This doesn't mean that the virtual
Now edit
~# nano -w /etc/xen/xend-config.xsp(Comment out the following lines) #(network-script network-bridge) #(vif-script vif-bridge)(Enable the following lines) (network-script network-route) (vif-script vif-route)
Unlike the routed interfaces you now need to load the
Now edit your virtual domain and add the
~# nano -w /mnt/data/xen/configs/gentoo(Add the vif instruction) vif = [ 'ip=192.168.1.101, vifname=veth0' ]
Next edit
~# nano -w /etc/xen/xend-config.xsp(Enable the following lines) (network-script network-bridge) (vif-script vif-bridge)(Comment out the following lines if not done already) # (network-script network-route) # (vif-script vif-route)
By default, the bridge will contain whatever interface is configured to be the
default interface (the device that is listed under the default route through
~# nano -w /etc/xen/xend-config.xsp(Edit the network-script line) (network-script 'network-bridge netdev=eth0 bridge=xenbr0 vifnum=0')
Once the configuration is done, restart the
~# /etc/init.d/xend restart