|Red Hat Linux 7.1: The Official Red Hat Linux Customization Guide|
|Prev||Chapter 16. Building a Custom Kernel||Next|
The instructions in this section apply to building a modularized kernel. If you are interested in building a monolithic kernel instead, see the section called Building a Monolithic Kernel for an explanation of the different aspects of building and installing a monolithic kernel.
The following steps will guide you through building a custom kernel for the x86 architecture:
This example uses 2.4.2-0.1.21 as the kernel version. Your kernel version might differ. To determine your kernel version, type the command uname -r. Replace 2.4.2-0.1.21 with your kernel version.
The most important step is to make sure that you have a working emergency boot disk in case you make a mistake. If you didn't 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.2-0.1.21). Once done, test the boot disk to make sure that it will boot the system.
You must have both the kernel-headers and kernel-source packages installed. Issue the commands rpm -q kernel-headers and rpm -q kernel-source to determine their versions, if they are installed. If they are not installed, install them from the Red Hat Linux CD 1 or the Red Hat FTP site available at ftp://ftp.redhat.com (a list of mirrors is available at http://www.redhat.com/mirrors.html). Refer to Chapter 17 for information on installing RPM packages.
At a shell prompt and change to the directory /usr/src/linux-2.4. All commands from this point forward must be issued from this directory.
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 already have a working configuration file (/usr/src/linux-2.4/.config) that you want to use, back it up to a different directory before running this command and copy it back after running the command. If you use an existing configuration file, skip the next step.
Now you must create a configuration file that will determine which components to include in your new kernel.
If you are running the X Window System, the recommended method is to use the command make xconfig. Components are listed in different levels of menus and are selected using a mouse. You can select Y (yes), N (no), or M (module). After choosing your components, click the Save and Exit button to create the configuration file /usr/src/linux-2.4/.config and exit the Linux Kernel Configuration program.
Other available methods for kernel configuration are listed below:
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.
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. Toggle the tag corresponding to the item you want included: [*] (built-in), [ ] (exclude), <M> (module), or < > (module capable). This method does not require the X Window System.
make oldconfig — This is a non-interactive script that will set up your configuration file to contain the default settings. If you're using the default Red Hat kernel, it will create a configuration file for the kernel that shipped with Red Hat Linux for your architecture. This is useful for setting up your kernel to known working defaults and then turning off features that you don't want.
To use kmod (see the section called Loading Kernel Modules for details) and kernel modules you must answer Yes to kmod support and module version (CONFIG_MODVERSIONS) support during the configuration.
After creating a /usr/src/linux-2.4/.config file, use the command make dep to set up all the dependencies correctly.
Use the command make clean to prepare the source tree for the build.
The next step in making a modularized kernel is to 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. If you are interested in other possibilities, details can be found at http://www.redhat.com/mirrors/LDP/HOWTO/Kernel-HOWTO.html or in the Makefile in /usr/src/linux-2.4 on your Linux system.
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 string. For example, if you are compiling kernel version 2.4.2-0.1.21 you can append the flag to look similar to EXTRAVERSION = -0.1.21-feb2001). This will allow you to have the old working kernel and the new kernel, version 2.4.2-0.1.21-12feb2001, on your system at the same time.
Build the kernel with make bzImage.
Build any modules you configured with make modules.
Install the kernel modules (even if you didn't build any) with make modules_install. Make sure that you type the underscore (_). This will install the kernel modules into the directory path /lib/modules/ using the path name that was specified in the Makefile. Our example would be /lib/modules/2.4.2-0.1.21-12feb2001/.
If you have a SCSI adapter and you made your SCSI driver modular, build a new initrd image (see the section called Making an initrd Image; note that there are few practical reasons to make the SCSI driver modular in a custom kernel). Unless you have a specific reason to create an initrd image, do not create one and do not add it to lilo.conf.
Use make install to copy your new kernel and its associated files to the proper directories.
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. This can be accomplished by updating the /etc/lilo.conf file and running /sbin/lilo.
The default /etc/lilo.conf file looks similar to the following:
boot=/dev/hda map=/boot/map install=/boot/boot.b prompt timeout=50 message=/boot/message linear default=linux image=/boot/vmlinuz-2.4.2-0.1.21 label=linux initrd=initrd-2.4.2-0.1.21.img read-only root=/dev/hda5
boot=/dev/hda map=/boot/map install=/boot/boot.b prompt timeout=50 message=/boot/message linear default=linux image=/boot/vmlinuz-2.4.2-0.1.21-12feb2001 label=linux initrd=initrd-2.4.2-0.1.21-12feb2001.img read-only root=/dev/hda5 image=/boot/vmlinuz-2.4.2-0.1.21 label=linux-old initrd=initrd-2.4.2-0.1.21.img read-only root=/dev/hda5
To activate your changes, run the command /sbin/lilo. If all goes well, you will see output similar to the following:
Added linux * Added linux-old
From now on, when the system boots you will see linux and linux-old as LILO boot options.
To boot the new kernel (linux)
You can begin testing your new kernel by rebooting your computer and watching the messages to ensure your hardware is detected properly.