how
to build Linux kernel? how
to build Linux kernel?
Building a Custom Kernel
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 already know why you need to build your own kernel, you probably do not need to."
The kernel provided with Red Hat Enterprise Linux and via the Red Hat Enterprise Linux Errata system provides support for most modern hardware and kernel features. For most users, it does not need to be recompiled. This appendix is provided as a guide for users who want to recompile their kernel to learn more about it, for users who want to compile an experimental feature into the kernel, and so on.
To upgrade the kernel using the kernel packages distributed by Red Hat, Inc., refer to Chapter 39 Upgrading the Kernel.
| Warning | |
|---|---|
Building a custom kernel is not supported by the Installation Support Team. For more information on upgrading the kernel using the RPM packages distributed by Red Hat, Inc., refer to Chapter 39 Upgrading the Kernel.
|
A.1. Preparing to Build
Before building a custom kernel, it is extremely important to make sure that a working emergency boot diskette exists in case a mistake is made. To make a boot diskette that will boot using the currently running kernel, execute the following command:
/sbin/mkbootdisk `uname -r` |
After making the diskette, test it to make sure that it boots the system.
To recompile the kernel, the kernel-source package must be installed. Issue the command
rpm -q kernel-source |
to determine if it is installed. If it is not installed, install it from the Red Hat Enterprise Linux CD-ROMs or Red Hat Network. For more information on installing RPM packages.
Building the Kernel
To build a custom kernel (perform all these steps as root):
| Note | |
|---|---|
This example uses 2.4.21-1.1931.2.399.ent as the kernel version (the kernel version might differ). To determine the kernel version, type the command uname -r and replace 2.4.21-1.1931.2.399.ent with the kernel version that is returned.
|
- 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.
- It is important that kernel build starts with the source tree in a known condition. Therefore, it is recommended that the command make mrproper is issued first to remove any configuration files along with the remains of any previous builds that may be scattered around the source tree. If an existing configuration file already exists as the file/usr/src/linux-2.4/.config, back it up to a different directory before running this command and copy it back afterward.
- It is recommended that the configuration of the default Red Hat Enterprise Linux kernel be used as a starting point. To do this, copy the configuration file for the system's architecture from the /usr/src/linux-2.4/configs/ directory to /usr/src/linux-2.4/.config. If the system has more than one processor, copy the file that contains the keyword smp. However, if the system has more than four gigabytes of memory, copy the file that contains the keyword hugemem.
- Next, customize the settings. The recommended method is to use the command make menuconfig to run the Linux Kernel Configuration program. The X Window System is not required.After finishing the configuration, select Exit and select Yes to save the new kernel configuration file (/usr/src/linux-2.4/.config).Even if no changes were made to any of the settings, running the make menuconfig command (or one of the other methods for kernel configuration) is required before continuing.Other available methods for kernel configuration include:
- make config — An interactive text program. Components are presented in a linear format and answered one at a time. This method does not require the X Window System and does not allow answers to be changed for previous questions.
- make xconfig — The method requires the X Window System and the tk package. This method is not recommended because it does not parse the configuration files reliably.
- make oldconfig — This is a non-interactive script that reads the existing configuration file (.config) and only prompts for answers to any new questions that did not previously exist.
Note To use kmod and kernel modules 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 the dependencies correctly.
- Use the command make clean to prepare the source tree for the build.
- It is recommended that the custom kernel have a modified version number so that the existing kernel is not overwritten. The method described here is the easiest to recover from in the event of a mishap. For 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/.By default, /usr/src/linux-2.4/Makefile includes the word custom at the end of the line beginning with EXTRAVERSION. Appending the string allows the system to have the old working kernel and the new kernel (version 2.4.21-1.1931.2.399.entcustom) on the system at the same time.If the system contains more than one custom kernel, a good method is to append the date at the end (or another identifier).
- For the x86 and AMD64 architectures, build the kernel with make bzImage. For the Itanium architecture, build the kernel with make compressed. For the S/390 and zSeries architectures, build the kernel with make image. For the iSeries and pSeries architectures, build the kernel with make boot.
- Build any modules configured with make modules.
- Use the command make modules_install to install the kernel modules (even if nothing was actually built). Notice the underscore (_) in the command. This installs the kernel modules into the directory path /lib/modules/<KERNELVERSION>/kernel/drivers (where KERNELVERSION is the version specified in the Makefile). In this example it would be /lib/modules/2.4.21-1.1931.2.399.entcustom/kernel/drivers/.
- Use make install to copy the new kernel and its associated files to the proper directories.In addition to installing the kernel files in the /boot directory, this command also executes the /sbin/new-kernel-pkg script that builds a new initrd image and adds new entries to the boot loader configuration file.If the system has a SCSI adapter and the SCSI driver was compiled as a module or if the kernel was built with ext3 support as a module (the default in Red Hat Enterprise Linux), theinitrd image is required.
- Even though the initrd image and boot loader modifications are made, verify that they were done correctly and be sure to use the custom kernel version instead of 2.4.21-1.1931.2.399.ent. Refer to Section 39.5 Verifying the Initial RAM Disk Image and Section 39.6 Verifying the Boot Loader for instructions on verifying these modifications
Additional Resources
For more information on the Linux kernel, refer to the following resources.
A.3.1. Installed Documentation
- /usr/src/linux-2.4/Documentation/ — This directory contains advanced documentation on the Linux kernel and its modules. These documents are written for people interested in contributing to the kernel source code and understanding how the kernel works.
A.3.2. Useful Websites
- http://www.redhat.com/mirrors/LDP/HOWTO/Kernel-HOWTO.html — The Linux Kernel HOWTO from the Linux Documentation Project.
- http://www.kernel.org/pub/linux/docs/lkml/ — The linux-kernel mailing list.
No comments:
Post a Comment