You are on page 1of 14

Chapter – 21

Building a Custom Kernel


At the end of this module, you would have

gained fair knowledge on:

•The necessity of customizing kernel

•How to make a customized kernel
•How to configure the boot loader to boot
the customized kernel
Building a Modularized Kernel
The following steps will guide you through building a
custom kernel for the x86 architecture:
1. The most important step is to make sure that you have a
working emergency boot disk in case you make a mistake. If
you did not make a boot disk during the installation, use the
mkbootdisk command to make one now.
The standard command is similar to
mkbootdisk --device /dev/fd0 2.4.x (where
2.4.x is the full version of your kernel such as 2.4.18-0.12).
Once done, test the boot disk to make sure that it will boot the
2. You must have the kernel-source package installed.
Issue the command rpm -q kernel-source to determine
the package version, if it is installed. If it is not installed, install
them from the Red Hat Linux CD #1
3. Open a shell prompt and change to the directory
/usr/src/linux-2.4. All commands from this
point forward must be executed from this directory.
4. It is important that you begin a kernel build with
the source tree in a known condition. Therefore, it is
recommended that you begin with the command
make mrproper. This will remove any
configuration files along with the remains of any
previous builds that may be scattered around the
source tree. If you
5. Now you must create a configuration file that will
determine which components to include in your new
Other available methods for kernel configuration are listed below:
o make config — An interactive text program. Components are
presented in a linear format and you answer them one at a time.
This method does not require the X Window System and does not
allow you to change your answers to previous questions.
o make menuconfig — A text mode, menu driven program.
Components are presented in a menu of categories; you select
the desired components in the same manner used in the text
mode Red Hat Linux installation program.
o make oldconfig — This is a non-interactive script that will set
up your configuration file to contain the default settings. If you are
using the default Red Hat Linux kernel, it will create a
configuration file for the kernel that shipped with Red Hat Linux for
your architecture.
6. After creating a /usr/src/linux-2.4/.config file, use
the command make dep to set up all the dependencies
7. Use the command make clean to prepare the
source tree for the build.
8. Edit /usr/src/linux-2.4/Makefile so that
you do not overwrite your existing kernel. The method
described here is the easiest to recover from in the
event of a mishap.
Edit /usr/src/linux-2.4/Makefile and modify the
line beginning with EXTRAVERSION = to match a
"unique" name by appending the date to the end of the
9. Build the kernel with make bzImage.
10. Build any modules you configured with make modules.
11. Use the command make modules_install to install the
kernel modules (even if you did not build any). Make sure that you
type the underscore (_).
12. If you have a SCSI adapter and you made your SCSI driver
modular, build a new initrd image Also, if you build your kernel
with ext3 support as a module (the default in Red Hat Linux), you
must create an initrd image.
13. Use make install to copy your new kernel and its
associated files to the proper directories.
14. The kernel is built and installed now. The next step is
configuring the boot loader to boot the new kernel. Refer to
the Section called Configuring the Boot Loader for more
Making an initrd Image
An initrd image is needed for loading your
SCSI module at boot time or if you are compiling the
kernel with ext3 support as a module. If you do not need
an initrd image, do not make one and do not edit lilo.conf
or grub.conf to include this image.
Use the /sbin/mkinitrd shell script to build an
initrd image for your machine. To use this command, the
loopback block device must be available.
To build the new initrd image, run
/sbin/mkinitrd with parameters such as this:
/sbin/mkinitrd /boot/initrd-2.4.18-0.12-jul2001.img
Configuring the Boot Loader
Now that you have recompiled your kernel,
you must configure the boot loader to boot the new
kernel. This is a crucial step. If you do not perform this
step or if you perform it incorrectly, you will not be able
to boot your system. If this happens, boot your system
with the boot diskette you created earlier and try
configuring the boot loader again.
In order to provide a redundant boot source
to protect from a possible error in a new kernel, you
should keep the original kernel available. During the
installation of Red Hat Linux 7.3, you had the option to
choose either GRUB or LILO as your boot loader.
# NOTICE: You have a /boot partition. This
# all kernel
means that paths are relative to /boot/
title Red Hat Linux (2.4.18-0.12)
root (hd0,0)
kernel /vmlinuz-2.4.18-0.12 ro
initrd /initrd-2.4.18-0.12.img

If you created a separate /boot partition, the paths

to the kernel and initrd image are relative to the /boot
To configure LILO to boot the new kernel, you need to
update the /etc/lilo.conf file and run the command /sbin/lilo -v.
The default /etc/lilo.conf file looks similar to the following:

To add your new kernel to LILO,
copy the existing image section to a new
one and modify it to boot your new kernel
image (and initrd image if you have any
SCSI devices and have created an initrd
image). Also, rename the label of the old
kernel to something such as linux-old. Your
/etc/lilo.conf should look similar to the


Building a Monolithic Kernel
To build a monolithic kernel, follow the same
steps as building a modularized kernel, with a few
• When configuring the kernel, do not compile
anything as a module. In other words, only answer Yes
or No to the questions. Also, you should answer No to
kmod support and module version
• Omit the following steps:
make modulesmake modules_install
• Edit lilo.conf to include the line append=nomodules
or append the kernel line in grub.conf with nomodules.