CentOS 5 - Build a Custom Xen Kernel with NFS Root Filesystem (CONFIG ROOT NFS) Support

From Virtuatopia
Revision as of 16:39, 25 April 2008 by Neil (Talk | contribs) (Preparing for the Custom Kernel Build)

Jump to: navigation, search

In order to boot and run a Xen guest domain a key requirement (amongst other items) is a root filesystem populated with the files and directories necessary for the guest operating system to function. One of the most flexible Xen configurations involves the installation of the root filesystem on an NFS server such that it can be accessed and booted on a client system. This approach is of particular use when the need to migrate Xen domainU guests from one host to another arises. Since both the original host and the target host to which the guest is migrating need access to the domainU's root filesystem, NFS provides an ideal mechanism for achieving this by allowing the root filesystem located on the NFS server to be mounted on both client hosts.

In order to boot a Xen guest domain with an NFS mounted root filesystem a version of the Linux kernel with root NFS support is required. Unfortunately this functionality is not enabled by default in most standard kernels. It is necessary, therefore, to build a custom kernel with this capability enabled. In this tutorial we will work through an example of building a custom CentOS 5.1 kernel with NFS root filesystem support.

Obtaining the Kernel Sources

The first step in building a custom kernel involves the download and installation of the latest kernel sources. These can be obtained from the CentOS repository which is online at http://mirror.centos.org/centos/5/updates/SRPMS.


where <version> represents the version of kernel currently running on your system. This information can be obtained by running:

 uname -mr

For example, at time of writing the latest kernel sources are contained in the package named kernel-2.6.18-53.1.14.el5.src.rpm.

Download the appropriate kernel sources for your environment to your home directory.

Preparing for the Custom Kernel Build

While logged in as yourself (do not perform these tasks as root) it is necessary to perform th3e following steps in preparation for installing the sources:

echo "%_topdir %(echo $HOME)/rpmbuild" > .rpmmacros

Next, you will need to install (as root) the rpm-build package if it is not already installed on your system:

su - 
yum install rpm-build

Be sure to exit from su to revert to your original user account.

Next, we can install the kernel sources from the rpm file downloaded previously:

rpm -Uvh kernel-<version>.el5.src.rpm

Once the packages are installed the sources need to unpacked using the rpmbuild command:

cd ~/rpmbuild/SPECS
pmbuild -bp --target=`uname -m` kernel-2.6.spec

Once this task completes the sources will be located in ~/rpmbuild/BUILD/.

Customizing the Kernel for NFS Root Support

Now that we have the kernel sources installed we are ready to being the process of customizing the kernel to support the an NFS based root filesystem. The first step is to copy the configuration file from the running operating system to the appropriate directory of the kernel build tree:

cd ~/rpmbuild/BUILD/kernel-2.6.18/linux-2.6.18.i686
cp /boot/config-`uname -r` .config
make oldconfig

We are now ready to begin the customization process. For the purposes of this tutorial we will be using the make menuconfig mechanism which requires that the ncurses-devel package. If this is not installed, install it now as follows:

su -
yum install ncurses-devel

Be sure to exit from the su session before proceeding beyond this point.

Configuring the Kernel with make menuconfig

Whilst still in the ~/rpmbuild/BUILD/kernel-2.6.18/linux-2.6.18.i686 directory, start the kernel configuration tool:

make menuconfig

The following screen should appear:

The main menuconfig screen

In order to configure root NFS support it is first necessary to enable