Configuring Gentoo with Xen Sven Vermeulen This guide describes how to start using Xen on your Gentoo system 4 2011-03-02 Introduction



Preparing Domain0


Rebuilding the Gentoo Installation?


~# nano -w /etc/make.conf

~# emerge -e world


Installing Xen


~# emerge xen xen-tools xen-sources
Building the Kernel


Of course, don't forget to select Xen-compatible at Processor type and features. If you're wondering about networking: each interface in a domain has a point-to-point link to an interface on domain 0 (called vifX.Y where X is the domain number and Y the Yth interface of that domain), so you can configure your network the way you want (bridging, NAT, etc.)

Processor type and features  --->
      Subarchitecture Type (Xen-compatible)
Processor type and features  --->
      Subarchitecture Type (PC-compatible)
  [*] Enable Xen compatible kernel
  [*] Support for hot-pluggable CPUs
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


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.

Creating an Unpriviledged Domain
Building the Kernel

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 XEN settings where drivers should now have their frontend implementation selected instead of the backend. Then build the kernel and place the resulting vmlinuz file where you want (we assume this is /mnt/data/xen/kernel):

~# 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.

Creating the Domain Disks


You can create a file based filesystem using dd and mke2fs (or any other file system creation tool). For instance, to create a 2Gbyte ext3 filesystem:

~# dd if=/dev/zero of=/mnt/data/xen/disks/ext3root.img bs=1M count=2048
~# mke2fs -j /mnt/data/xen/disks/ext3root.img
Configuring a Domain



kernel = "/mnt/data/xen/kernel/kernel-2.6.x.y-xen"
memory = 512
name   = "gentoo"
disk   = ['file:/mnt/data/xen/disks/ext3root.img,sda1,w']
root   = "/dev/sda1 ro"


(LVM Volume)

(Physical Partition)
disk = [ 'phy:sdb6,sda1,w' ]

You can find example configuration files in /etc/xen.

Launching the New Domain

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 command (Xen manager):

~# xm create /mnt/data/xen/configs/gentoo -c


If you want to disconnect from the domain, press Ctrl+]. You can always reconnect to the domains' console using xm console gentoo. However, there is only one console per domain, so only use it when you can't access the domain otherwise (for instance, through SSH).

Networking on Unpriviledged Domains

Xen supports at least two ways of configuring your (virtual) network: routed and bridged.

When selecting the routed approach, the interface inside your unpriviledged domain is connected to the virtual interface on your administrative domain. On your administrative domain (domain 0), the virtual interface is linked together with eth0. The interface inside your unpriviledged domain should have an IP address on the same network as the interface on the administrative domain. Any communication to that IP address can only occur from the administrative domain, unless you set up specific routing rules.

When selecting the bridged approach, your default network interface on the administrative domain becomes a bridge which accepts connections to the virtual domains as well as to the IP address your administrative domain has.

Regular Routed Interfaces

Before you set up the interface on your unpriviledged domain, make sure that Xen's netloop and netbk drivers are loaded. A quick hint: if you have netloop as a module, load it with nloopbacks=0 so that it doesn't create pointless interfaces to the loopback device. Then, edit your domain configuration file and add a vif instruction to it.


(Add the vif instruction)
vif    = [ 'ip=, vifname=veth1' ]

In the above example, the interface will be created for the unpriviledged domain (in which it will be called eth0) and Xen will ensure that address will be reachable from the administrative domain through interface veth1.

This doesn't mean that the virtual eth0 interface will automatically have IP assigned to it, but rather that, if you don't give it that IP, it will not be connected with the administrative domain and thus cannot be reached.

Now edit /etc/xen/xend-config.sxp as follows to select routed network configuration:

~# nano -w /etc/xen/xend-config.sxp

(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)
Bridged Interfaces

Unlike the routed interfaces you now need to load the netloop driver with nloopbacks=1 (or higher) as the additional loopback devices are used to create the bridge. For the other modules you still need the netbk module as well as briding functionality (bridge module if build as such).

Now edit your virtual domain and add the vif construct:


(Add the vif instruction)
vif    = [ 'ip=, vifname=veth0' ]

Next edit /etc/xen/xend-config.sxp as follows to select bridged network configuration:


(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 ip route list). If you want to alter this behavior, edit the xend-config.sxp as follows:


(Edit the network-script line)
(network-script 'network-bridge netdev=eth0 bridge=xenbr0 vifnum=0')

Once the configuration is done, restart the xend init script to have Xen build the bridge:

~# /etc/init.d/xend restart
Further Resources
Xen Documentation
  • Xen Users' Manual
  • Xen Community Documentation
  • Xen Wiki
Xen Tools