Configuring and Compiling the Linux Kernel


Configuring and Compiling the Linux Kernel

This section describes how to configure the kernel to meet your needs and how to compile it.

Cleaning the Source Tree

If you want to save an existing configuration file (/usr/src/linux/.configure), copy it to another directory (such as your home directory) or rename it before you proceed, because the next command will remove it. Purge the source tree (all subdirectories and files within /usr/src/linux) of all configuration and potentially stale *.o files by giving the following command:

$ make mrproper

Configuring the Linux Kernel

Before you can compile the code and create a Linux kernel, you must decide and specify which features you want the kernel to support. You can configure the kernel to support most features in two ways: by building the feature into the kernel or by specifying the feature as a loadable kernel module page , which is loaded into the kernel only as needed. In deciding which method to use, you must weigh the size of the kernel against the time it takes to load a module. Make the kernel as small as possible while minimizing how often modules have to be loaded. Do not make the SCSI driver modular unless you have a reason to do so.

The configs directory provides sample configuration files for various processors, multiple processors, and configurations. You may want to look at these files before you get started or even use one of them as your starting point. To use one of these files, copy it from the configs directory to the linux directory and rename it .config.

Three standard commands are used to configure the Linux kernel:

$ make config
$ make menuconfig
$ make xconfig

The make xconfig command uses Qt (), which is normally installed with KDE or GNOME under FEDORA. If you prefer to use GTK+ () and it is installed on the local system, give the command make gconfig.

Under RHEL you may need to install the qt-devel package. Give the command up2date qt-devel to install this package and several packages that it is dependent on.

Each command asks the same questions and produces the same result, given the same responses. The first and second commands work in character-based environments; the second and third commands work in graphical environments. For most administrators in most situations, the third (graphical) method is the easiest to use ( and ). The figures show the windows displayed by FEDORA; RHEL windows look different but perform the same function.

Figure 15-1. The qconf window as displayed by make xconfig on Centos Linux

Figure 15-2. The qconf Power Management support submenu

The make xconfig command displays the qconf window. You can view the qconf window in three configurations: single, split, or full view. Choose a view by clicking one of the three icons to the right of the floppy diskette on the toolbar. shows the default split view. In this view, the left frame shows the options and the top-right view lists the features for each option. The bottom-right view describes the highlighted option or feature. shows the full view.

In any view, you click the boxes and circles next to the choices and subchoices. An empty box/circle indicates the feature is disabled, a check mark indicates it is to be included in the kernel, and a dot means it is to be compiled as a module. Select Menubar: Option Show All Options to display all options and features.

Go through the options and mark the features as you would like them to be configured in the new kernel. At any time during the configuration process, you can store the currently defined configuration to a file, load a configuration from a file, or exit with or without saving your changes. See the selections in File on the Menubar. When you are done, select Menubar: File Save and close the window.

EXTRAVERSION Number

To prevent overwriting existing kernel files and to identify various compilations of the kernel, you can use the EXTRAVERSION variable in Makefile. This variable is initially set to prep. Whatever value you assign to this variable is placed at the end of the kernel name and release number to identify the kernel. You can make note of patches applied to the kernel in this string to help people track down problems later on.

Compiling the Linux Kernel

Before compiling the kernel, make sure, once again, that no files are in the source tree from previous work:

$ make clean

Then give the following command to compile the kernel:

$ make bzImage
CHK     include/linux/version.h
UPD     include/linux/version.h
SYMLINK include/asm -> include/asm-i386
HOSTCC  scripts/basic/fixdep
HOSTCC  scripts/basic/split-include
HOSTCC  scripts/basic/docproc
...

Using Loadable Kernel Modules

A (page ) (sometimes called a module or ) is an object filepart of the kernelthat is linked into the kernel at runtime. Modules are compiled separately from the kernel and can be inserted into and removed from a running kernel at almost any time except when the module is being used. This ability gives the kernel the flexibility to be as small as possible at any given time. Modules are a good way to code some kernel features, including drivers that are not used continually (such as a tape driver).

Tip: Module filename extensions have changed

Filenames of modules in the Linux 2.4 and earlier kernels ended in .o. Starting with the 2.6 kernel (introduced in Centos Linux 2 and CentOS Linux version 4), module filenames end in .ko.

When you configure the kernel to support loadable modules, you need to build and install the modules. Give the following command to compile the modules that you specified when you configured the kernel:

$ make modules

Compiling the modules typically takes longer than compiling the kernel. The next command installs the modules in the /lib/modules/kernel-versionEXTRAVERSION directory. Run this command as root even if you did not build any modules:

# make modules_install

lists some of the tools available to help you work with modules. Refer to the corresponding man pages for options and more information.

Table 15-1. Tools for working with modules

Tool/utility

Function

depmod

Works with dependencies for modules.

insmod

Loads modules in a running kernel.

lsmod

Lists information about all loaded modules.

modinfo

Lists information about a module.

modprobe

Loads, unloads, and reports on modules. When it loads a module, it also loads dependencies.

rmmod

Unloads modules from a running kernel.