Building a custom kernel is not as scary as it sounds, just follow these steps.

First, download the kernel source, I’m using 2.6.10 as that is the latest version that LKCD patches support.

cd /usr/src
tar xjvf linux-2.6.10.tar.bz2
ln -s linux-2.6.10 linux

Apply Patches To The Kernel Sources (Optional)

If you want to patch the kernel, apply them after the source is extracted.

cd /usr/src/linux
zcat /usr/src/lkcd-6.2.0_2.6.10.patch.gz | patch -p1

You could also add xen, or any other patches you want.

Configure The Kernel

It’s a good idea to use the configuration of your current working kernel as a basis for your new kernel. Therefore we copy the existing configuration to /usr/src/linux:

make clean && make mrproper cp /boot/config-`uname -r` ./.config

Then we run

make menuconfig

which brings up the kernel configuration menu. Go to Load an Alternate Configuration File and choose .config (which contains the configuration of your current working kernel) as the configuration file:

Then browse through the kernel configuration menu and make your choices. Make sure you specify a kernel version identification string under General Setup —> () Local version – append to kernel release. I use -default so our kernel rpm package will be named kernel- You can leave the string empty or specify a different one which helps you identify the kernel (e.g. -custom or whatever you like).

Please note: After you have installed kernel- and decide to compile another kernel rpm package, it is important to use a different version string, e.g. -default1, -default2, etc., because otherwise you can’t install your new kernel because rpm complains that kernel- is already installed!

When you are finished and select Exit, answer the following question (Do you wish to save your new kernel configuration?) with Yes:
‘Build The Kernel’

To build the kernel, simply execute this command:

make rpm

Now be patient, the kernel compilation can take some hours, depending on your kernel configuration and your processor speed.
‘Install The New Kernel’

After the successful kernel build, a src.rpm and an rpm package have been created. The src.rpm package can be found in the /usr/src/redhat/SRPMS/ directory, you can find out about its name by running

ls -l /usr/src/redhat/SRPMS/

On my system it was called kernel-

The rpm package can be found in /usr/src/redhat/RPMS/i386/, /usr/src/redhat/RPMS/i586/, /usr/src/redhat/RPMS/i686/, /usr/src/redhat/RPMS/x86_64/, etc., depending on your architecture. On my system it was located in /usr/src/redhat/RPMS/i386/, and by running

ls -l /usr/src/redhat/RPMS/i386/

I found out that its name was kernel-

Now we can install our kernel rpm package like this:

cd /usr/src/redhat/RPMS/i386/
rpm -ivh --nodeps kernel-

Please note the –nodeps switch: if you don’t use it, you will see an error like this:

error: Failed dependencies:

       kernel >= 2.6.10 conflicts with lksctp-tools-1.0.2-6.4E.1.i386

I found that ignoring this dependency didn’t cause any problems on my system.

You can now even transfer the kernel rpm package to other CentOS systems and install it there exactly the same way, which means you don’t have to compile the kernel there again.

Next we create a ramdisk for our new kernel, because otherwise the system will most likely not boot our new kernel:

mkinitrd /boot/initrd-

2.7 Configure The GRUB Boot Loader

Now we must configure our GRUB boot loader so that our new kernels gets booted when we restart the system.


ls -l /boot

to find out about your new kernel (typically begins with vmlinuz, e.g. vmlinuz- and ramdisk (typically begins with initrd, e.g. initrd-

Then edit /boot/grub/menu.lst. Have a look at your existing (working) kernel stanzas there and take one of them as a sample for your new stanza and replace the kernel and ramdisk, then add the stanza above all other stanzas.

vi /boot/grub/menu.lst
# grub.conf generated by anaconda
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/VolGroup00/LogVol00
#          initrd /initrd-version.img
title CentOS (
        root (hd0,0)
        kernel /vmlinuz- ro root=/dev/VolGroup00/LogVol00
        initrd /initrd-
title CentOS (2.6.9-42.0.3.EL)
        root (hd0,0)
        kernel /vmlinuz-2.6.9-42.0.3.EL ro root=/dev/VolGroup00/LogVol00
        initrd /initrd-2.6.9-42.0.3.EL.img
title CentOS-4 i386 (2.6.9-42.EL)
        root (hd0,0)
        kernel /vmlinuz-2.6.9-42.EL ro root=/dev/VolGroup00/LogVol00
        initrd /initrd-2.6.9-42.EL.img

Now reboot the system:

shutdown -r now

If everything goes well, it should come up with the new kernel. You can check if it’s really using your new kernel by running

uname -r

This should display something like

If the system doesn’t start, restart it, and when you see this:

press any key to enter the GRUB menu:

Select your old kernel and start the system. You can now try again to compile a working kernel. Don’t forget to remove the stanza of the not-working kernel from /boot/grub/menu.lst.