The Xen packages are arch masked for both x86 and x86_64 platforms at the moment so before they can be installed they will need to be added to the keyword list. This can be easily accomplished using the following commands.
Before we install the Xen hypervisor and associated management tools it is a good idea to check that the correct use-flags have been selected. A pretend merge, as shown in the example below, will show the available and selected use-flags so that we can be sure they are correct.
Once we are satisfied that the correct use-flags are enabled we can install the Xen hypervisor and associated management tools using the emerge command below.
Assuming that the Xen virtual machine monitor and management tools built and installed correctly we can continue the installation process by installing a Xen compatible kernel. As of the date of writing domain 0 support has yet to be merged into the main-line kernel so a special patched version of the kernel is required. The sources for this kernel are also arch masked for all compatible architectures and will need to be added to the keyword list before installing as shown below.
Now that we have installed the kernel sources for a Xen domain 0 compatible kernel we can import our existing kernel configuration to simplify the task of configuring the new kernel.
With the kernel sources installed and our existing, presumably functioning, kernel configuration imported we can start to reconfigure the kernel for use with the Xen virtual machine monitor. The example screen below shows the first critical configuration change which must be made to enable use of the kernel with Xen. Enabling this option also enables the other Xen related options which we shall need to configure later.
|
|
|
Once we have enabled Xen support we can configure the various Xen options using the Xen sub-menu which can be found under Device Drivers on the main kernel configuration page as shown in the example below. As you can see we have enabled the Privileged Guest (domain 0) option and the various Back-end driver support options. As this is a domain 0 kernel none of the front-end driver options are required. Feel free to enable more of the back-end driver options if you wish to experiment with their usage, only the options whose use is explored in this guide are enabled in the example below.
|
|
|
There are also two options of interest in the Xen driver support menu, as shown below.
|
|
|
Now that the kernel is correctly configured for our target system and for Xen we can build a kernel image, install the required modules and copy the kernel image to the boot partition ready for use. The example commands below show how to perform this task for a 64bit x86 system. If you are using a 32bit machine then the last line will need to be modified accordingly.
With a suitable kernel image for domain 0 successfully built and copied to the boot partition we must update the boot-loader configuration to offer the Xen hypervisor, with this kernel as the target for domain 0, as the default option. We shall leave our original kernel and the associated lines in our boot-loader configuration intact in case Xen fails to boot correctly for some reason.
The example grub.conf below shows how the Xen hypervisor is loaded in place of the usual kernel by the kernel command with the actual Linux kernel we are using for domain 0 loaded by the module command on the following line. As you can see options can be passed to the Xen hypervisor on the kernel line, in this case we are specifying the sEDF scheduler be used, while the normal kernel options are passed on the module line. Both kernel and module lines require the boot device to be specified using standard grub notation and this, as well as the root device to boot from, may need changing according to the specific configuration of the target machine.
default 0
timeout 30
# XEN 4.0.1
title XEN 4.0.1 (sEDF) / Linux 2.6.34-xen-r4 (hd0,0)
kernel (hd0,0)/xen-4.0.1.gz sched=sedf
module (hd0,0)/kernel-2.6.34-xen-r4 root=/dev/md2
# Fall-back
title Gentoo Linux 2.6.38-r6
root (hd0,0)
kernel /boot/kernel-2.6.38-gentoo-r6 root=/dev/md2
Since the stabilisation of sys-apps/baselayout-2.0 and the migration to sys-apps/openrc an attempt to auto-detect the runtime environment during the boot sequence is no longer made by default. So that the openrc scripts know that we are running as a Xen domain 0 we should supply this information by modifying the rc_sys entry in the /etc/rc.conf file as shown in the example below.
rc_sys=""
rc_sys="xen0"
Now that the Xen hypervisor and domain 0 kernel have been installed and the boot-loader and openrc appropriately reconfigured we can unmount the boot partition and reboot the machine as shown below.
If everything went well you should see the Xen hypervisor initialise and then pass control to the domain 0 kernel which should boot in the normal way. If the reboot was done remotely and you are in doubt as to the identity of the kernel which is currently running you can check that it is indeed the Xen compatible kernel we built earlier with the command shown below.
Linux 2.6.34-xen-r4