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/portage/make.conf(Add -mno-tls-direct-seg-refs ONLY if you have a 32-bit dom0) (You don't need this flag if you have a 64-bit dom0) 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 few packages.
~# emerge xen xen-tools gentoo-sources
Next we'll build the Linux kernel with Xen support. This kernel, whose sources
are available at
If you're wondering about networking: each interface in a domain
has a point-to-point link to an interface on domain 0 (called
Processor type and features --->
[*] Paravirtualized guest support --->
[*] Xen guest support
Bus options (PCI etc.) --->
[*] Xen PCI Frontend
[*] Networking support --->
Networking options --->
<*> 802.1d Ethernet Bridging
[*] Network packet filtering framework (Netfilter) --->
[*] Advanced netfilter configuration
[*] Bridged IP/ARP packets filtering
Device Drivers --->
[*] Block devices (NEW) --->
<*> Xen block-device backend driver
[*] Network device support --->
<*> Xen backend network device
Xen driver support --->
[*] Xen memory balloon driver (NEW)
[*] Scrub pages before returning them to system (NEW)
<*> Xen /dev/xen/evtchn device (NEW)
[*] Backend driver support (NEW)
<*> Xen filesystem (NEW)
[*] Create compatibility mount point /proc/xen (NEW)
[*] Create xen entries under /sys/hypervisor (NEW)
<M> userspace grant access device driver (NEW)
<M> user-space grant reference allocator driver (NEW)
<M> xen platform pci device driver (NEW)
The shown kernel configuration should allow the kernel image to boot both as a host as well as a guest. However, if you want to, you can slim down the guest image kernel considerably. Refer to the Xen documentation for more information.
Once the kernel is built you'll find the kernel image immediately in the
build directory (not inside
title Xen Gentoo Linux 3.5 root (hd0,0) kernel /boot/xen.gz module /boot/kernel-3.5.x.y-xen0 root=/dev/sda3
Now reboot your system into Xen and 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.
Go to the Xen-powered Linux kernel source and, if necessary, update the
configuration. It is wise to keep as many topics as possible similar to
the main kernel. Then build the kernel
and place the resulting
~# make O=~/build/domU ~# cp ~/build/domU/vmlinuz /mnt/data/xen/kernel/kernel-3.5.x.y-xen
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/ext4root.img bs=1M count=4096 ~# mkfs.ext4 /mnt/data/xen/disks/ext4root.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-3.5.x.y-xen" memory = 512 name = "gentoo"(Map the disk image to the virtual /dev/sda1) disk = ['file:/mnt/data/xen/disks/ext4root.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
~# xl 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 works best when using a bridged mode network configuration. This means that 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.
Create a bridge interface by creating a new link to the networking init script as provided by Gentoo:
# cd /etc/init.d # ln -s net.lo net.br0
Next, edit
# nano -w /etc/conf.d/net bridge_br0="eth0" config_br0="192.168.1.200 netmask 255.255.255.0 brd 192.168.1.255" routes_br0="default via 192.168.1.1"
Finally, install the
# emerge net-misc/bridge-utils # rc-update add net.br0 default