With the introduction of modularization in the Linux 2.0.x kernel there have been some significant changes in building customized kernels. In the past you were required to compile support into your kernel if you wanted to access a particular hardware or filesystem component. For some hardware configurations the size of the kernel could quickly reach a critical level. To require ready support for items that were only occasionally used was an inefficient use of system resources. With the capabilities of the 2.0.x kernel, if there are certain hardware components or filesystems that are used infrequently, driver modules for them can be loaded on demand. For information on handling kernel modules see Chapter 8.2, Section 8.2.2.
Many people new to Linux often ask, ``why should I build my own kernel''. Given the advances that have been made in the use of kernel modules, the most accurate response to that question is, ``unless you know why you need to build your own kernel, you probably don't''. So unless you have a specific reason to build a customized kernel (or you're just the curious sort), you may skip ahead to Section 11.7.
These instructions provide you with the knowledge required to take advantage of the power and flexibility available through kernel modularization. If you do not wish to take advantage of modularization, please see Section 11.6.3 for an explanation of the different aspects of building and installing a monolithic kernel. It is assumed that you have already installed the kernel-headers and kernel-source packages and that you issue all commands from the /usr/src/linux directory.
It is important to 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. Now you must create a configuration file that will determine which components to include in your new kernel. Depending upon your hardware and personal preferences there are three methods available to configure the kernel.
Please Note: In order to use kerneld (see Section 8.2.2 for details) and kernel modules you must answer Yes to kerneld support and module version (CONFIG_MODVERSIONS) support in the configuration.
Please Note: If you are building a Linux/Intel kernel on (or for) a
machine that uses a ``clone'' processor (for example, one made by Cyrix
or AMD), it is recommended to choose a Processor type of
386.
If you wish to build a kernel with a configuration file
(/usr/src/linux/.config) that you have already created with one
of the above methods, you can omit the make mrproper and
make config commands and use the command make dep followed
by make clean to prepare the source tree for the build.
The next step consists of the actual compilation of the source code
components into a working program that your machine can use to boot.
The method described here is the easiest to recover from in the event
of a mishap. If you are interested in other possibilities details can
be found in the Kernel-HOWTO or in the Makefile in
/usr/src/linux on your Linux system.
Of course, if you have upgraded your kernel, replace 2.0.29
with the version you are using.
If you have a SCSI adapter and made your SCSI driver modular, build a
new initrd image (see Section 11.6.2; note that there
are few practical reasons to make the SCSI driver modular in a custom
kernel).
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.
Adding a kernel to the LILO menu is as simple as renaming the original
kernel in /boot, copying the new kernel to /boot, adding a
few lines in /etc/lilo.conf and running /sbin/lilo. Here
is an example of the default /etc/lilo.conf file shipped with
Red Hat Linux:
Now you must update /etc/lilo.conf. If you built a new initrd
image you must tell LILO to use it. In this example of
/etc/lilo.conf we have added four lines at the bottom of the file
to indicate another kernel to boot from. We have renamed
/boot/vmlinuz to Now when the system boots and you press [Tab] at the LILO
boot: prompt two choices will be shown;
To boot the new kernel (linux) simply press [Enter], or wait
for LILO to time out. If you want to boot the old kernel (old),
simply enter old and press [Enter].
Here is a summary of the steps;
You can begin testing your new kernel by rebooting your computer and
watching the messages to ensure your hardware is detected properly.
An initrd image is needed for loading your SCSI module at boot
time. The shell script To build the new initrd image, run /sbin/mkinitrd
with parameters such as this:
where /boot/newinitrd-image is the file to use for your new
image, and 2.0.12 is the kernel whose modules (from
/lib/modules) should be used in the initrd image (not
necessarily the same as the version number of the currently running
kernel).
To build a monolithic kernel you follow the same steps as building a
modularized kernel with a few exceptions.
rm -rf /lib/modules/2.0.29-old
mv /lib/modules/2.0.29 /lib/modules/2.0.29-old
make modules_install.
boot=/dev/hda
map=/boot/map
install=/boot/boot.b
prompt
timeout=100
image=/boot/vmlinuz
label=linux
root=/dev/hda1
read-only
/boot/vmlinuz.old and changed its label to old. We have also
added an initrd line for the new kernel:
boot=/dev/hda
map=/boot/map
install=/boot/boot.b
prompt
timeout=100
image=/boot/vmlinuz
label=linux
initrd=/boot/initrd
root=/dev/hda1
read-only
image=/boot/vmlinuz.old
label=old
root=/dev/hda1
read-only
LILO boot:
linux old
11.6.2 Making an initrd image
/sbin/mkinitrd can build a proper
initrd image for your machine if the following conditions are met:
alias scsihostadapter BusLogic
/sbin/mkinitrd /boot/newinitrd-image 2.0.12
11.6.3 Building a monolithic kernel
make modules
make modulesinstall