Building a CentOS/Redhat NFSRoot Kernel

By default the Centos Kernel does not seem to support NFS Root.  Here is an example of how to build a Centos/REL NFSRoot Kernel

1.  Setup your build environment

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

2.  Install necessary packages
yum groupinstall "Development Tools"
yum install ncurses-devel

3.  Obtain the kernel source package

Open your browser and look for the kernel source rpms:

4. Extract your kernel into the build environment

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

5. Unpack the kernel using the RPM Build command.  The kernel comes compressed.  

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

6.  Customize the kernel by generating a .config file which we then will later copy to the SOURCES directory.

cd ~/rpmbuild/BUILD/kernel-<version>/linux-<version>
cp /boot/config-<version> .config
make silentoldconfig or yes "" |make oldconfig

make menuconfig

7.  Edit the menu, and set the following options:

Network->Networking Options->IP: Kernel level autoconfiguration = YES
File Systems->Network:  Set NFS Client to "*" instead of "M" and select NFS root, which only will show when NFS client is built into the kernel, not as a module.

8.  Save the config by selecting exit, until a save prompt is presented, select SAVE.

9.  Edit the configuration file and add:

# x86_64

10.  Copy the config file to ~/rpmbuild/SOURCES/

cp .config ~/rpmbuild/SOURCES/kernel-2.6.18-<arch>.config

11. The next step is to make some minor modifications to the ~/rpmbuild/SPECS/kernel-2.6.spec file. Load this file into an editor and change the build id definition such that it will be easy to distinguish the custom kernel from the original kernel. For example change:

#% define buildid


%define buildid .mycustom

12.  Also comment out the following lines:

#if a rhel kernel, apply the rhel config options
%if 0%{?rhel}
  for i in %{all_arch_configs}
    mv $i $i.tmp
    $RPM_SOURCE_DIR/ $RPM_SOURCE_DIR/config-rhel-generic $i.tmp > $i
    rm $i.tmp
  #CONFIG_FB_MATROX is disabled for rhel generic but needed for ppc64 rhel
  for i in $RPM_SOURCE_DIR/kernel-%{kversion}-ppc64.config
    mv $i $i.tmp
    $RPM_SOURCE_DIR/ $RPM_SOURCE_DIR/config-rhel-ppc64-generic $i.tmp > $i
    rm $i.tmp

13.  Save the spec file and then initiate the build as follows:

rpmbuild -bb --target=`uname -m` kernel-2.6.spec

14.  Once the build is complete rpm packages will be located in ~rpmbuild/RPMS/<arch>. Install the custom Xen kernel on the system:

rpm -ihv kernel-xen-<version>.el5.mycustom.i686.rpm

15.  The /boot directory will contain the necessary files to boot from the custom kernel, either for the host system or for a Xen domainU system