Xen Paravirtualization under Gentoo Jan Kundrát This guide shows you how to get Xen up and running on your Gentoo box. 1 2006-11-10 Introduction
This guide is currently x86-centric as that's the platform I've set up the Xen on. It'd be great if someone adds notes about using Xen on different platforms.

Before we into the installation and configuration of the virtual machine, we should explain some basic terms that are quite common in the world of Xen.

Domain
An instance of your "virtual computer", running its own kernel and user level applications
Dom0
The "primary" domain that is running all the time and is usually responsible for things like setting up another domains and other management tasks. It's "automatically" launched by the Xen hypervisor during the boot process. When the dom0 exists, Xen by default reboots the machine.
DomU
"Regular" instances of the unprivileged virtual machines. Each of them can be running different kernel version with wildly differing userspace environment, even another operating system.
Hypervisor
A Xen-supplied software that runs at the "bare metal" of your computer and is responsible for low-level tasks like CPU scheduling, memory management and dom0 launching upon boot.

Xen comes with extensive documetnation. It's a good idea to read through it to get familiar with its internal structure as it's out of scope of this guide.

Installing Xen
Installation of necessary packages

Installing the Xen hypervisor under Gentoo is a breeze, as usually :). The following will install both the hypervisor and a userspace management tools:

# emerge app-emulation/xen

As Xen requires a modified kernel, at least for domain0, you'll have to install patched kernel sources, unless you choose to manage them manually. It's generally not a good idea, so we suggest just plain old boring installation of the sys-kernel/xen-sources package:

# emerge sys-kernel/xen-sources
Building the Xen-patched kernel FIXME: add blurb about genkernel stuff

If you choose to configure and build the kernel yourself (which isn't a bad idea at all), you'll notice some differences from the general instructions.

As Xen requires each domain to have its own kernel image loaded into memory, you usually want to strip the domU kernels to the bare minimum that's required for a proper function. Unlike the dom0 which is generally responsible for tasks like I/O to hard drives, networking stuff and graphics output, the domUs don't require to worry about your HW devices at all. There's simply no need to include a driver for your SCSI controller into domU kernel as it's already handled by dom0.

Xen itself supports a delegating of some device directly to the domU instance. You can, for example, have a domain with a dedicated NIC or another one handling a TV-capture card. Such setups, usually called Driver Domains, are out of scope of this guide, so you should better consult the Xen wiki page and/or the official documentation.

As we have installed only one kernel source package, we'll have to create a directory where the different kernels are to be built. Let's start with the dom0. Please substitute 2.6.16.28 with the version of xen-sources you've installed earlier.

# mkdir -p ~/xen-build/2.6.16.28-dom0

Now you should configure the kernel for dom0. Please note that there are some differences from the general kernel config and don't forget to customize the examples according to your needs, especially with regard to kernel versions and file paths.

# cd /usr/src/linux-2.6.16.28-xen
# make O=~/xen-build/2.6.16.28-dom0 menuconfig

Here are the most importand Xen-related settings that should take care about:

General setup  --->
  Local version - append to kernel release
  (It's a good idea to set it to "-dom0" in order to distinguish between the dom0 and domU kernel images)

Processor type and features  --->
  Subarchitecture Type
  (Set to "Xen-compatible")

XEN  --->
  [*] Privileged Guest (domain 0)
  <*> PCI device backend driver
  <*> Block-device backend driver
  (You usually want your domUs to be able to access some kind of storage :) )
  <*> Network-device backend driver
  <*>   Network-device loopback driver
  < >  TPM-device backend driver
  < >  Block-device frontend driver
  < >  Network-device frontend driver
  < >  Block device tap driver
  < >  TPM-device frontend driver
  [*] Scrub memory before freeing it to Xen
  [*] Disable serial port drivers
  <*> Export Xen attributes in sysfs

FIXME: add a blurb about various config options and their meaning

Now thaty you've configured your dom0 kernel, it's time to build it. Standard make suggestions like -j3 when on a two-way SMP systems apply here as well.

# make O=~/xen-build/2.6.16.28-dom0

(Only if you've included module support:)
# make O=~/xen-build/2.6.16.28-dom0 modules modules_install

Now let's install your dom0 kernel image to the /boot directory and ask your favourite bootloader to use the new image instead of an old and not-so-sexy virtualization-unaware Linux kernel.

# cp ~/xen-build/2.6.16.28-dom0/vmlinuz /boot/linux-2.6.16.28-xen0-vmlinuz
FIXME: when you use LILO, you're screwed as I haven't worked with it. Just go and search the web, I'm sure you'll find a manual about how to set it up.
(Please make sure you include the correct names of the Xen and kernel images:)

# Example Xen settings for Grub
title=Xen-3.0.2, Linux 2.6.16.28
kernel /boot/xen-3.0.2.gz dom0_mem=64M
module /boot/linux-2.6.16.28-xen0-vmlinuz <<your-regular-kernel-options-go-here>>

After you've double-checked that everything at least seems to be okay and/or that you have console access to the box being Xenized, try to reboot it. If it comes back up, chances are that you can proceed with the real joy, creating virtual domains.

Ttroubleshooting

TODO