Chapter 1. The Linux Kernel

Table of Contents

1.1. Kernel Components
1.1.1. Modules
1.1.2. Types of Kernel Images
1.1.3. Documentation
1.2. Compiling a Kernel
1.3. Patching a Kernel
1.3.1. Applying the Patch
1.3.2. Testing the Patch
1.3.3. Recovering the Old Source Tree
1.3.4. Building the New Kernel after a patch
1.4. Customising a Kernel
1.4.1. Loading Kernel modules
1.4.2. The /proc/ directory
1.4.3. Task
1.4.4. A quick test

This module will describe the kernel source tree and the documentation available. We will also apply patches and recompile patched kernels. Information found in the /proc directory will be highlighted.

1.1. Kernel Components

1.1.1. Modules

1.1.1.1. Module Components in the Source Tree

In the kernel source tree /usr/src/linux, the kernel components are stored in various subdirectories:

SubdirectoryDescriptionExample
./driverscontains code for different types of hardware supportpcmcia
./fscode for filesystem supportednfs
./netcode for network supportipx

These components can be selected while configuring the kernel (see Section 1.2, “Compiling a Kernel”).

1.1.1.2. Module Components at Runtime

The /lib/modules/kernelversion/kernel directory has many of the same subdirectories present in the kernel source tree. However only the modules that have been compiled will be stored here.

1.1.2. Types of Kernel Images

The various kernel image types differ depending only on the type of compression used to compress the kernel.

The make tool will read the /usr/src/linux/Makefile to compile:

  • A compressed linux kernel using gzip is compiled with make zImage. The compiled kernel will be /usr/src/linux/arch/i386/boot/zImage.

  • A compressed linux kernel using better compression is compiled with: make bzImage. The compiled image will be /usr/src/linux/arch/i386/boot/bzImage.

  • One can also use make zdisk or make bzdisk to create compressed kernels on a floppy. The compiled kernel will be written to /dev/fd0. Remember to put a floppy in the drive!

1.1.3. Documentation

Most documentation is available in the /usr/src/linux/Documentation directory. The main files are the following:

FileDescription
00-INDEXSummary of the contents for each file in the Documentationdirectory
Configure.helpContains the help displayed when configuring a kernel

The Configure.help file also provides further information for when a kernel module doesn't load properly. Specific options and aliases for /etc/modules.conf are specified in that file.

Information about compiling and documentation is available in /usr/src/linux/README.

The version of the kernel is set at the beginning of the Makefile.

 
VERSION = 2
PATCHLEVEL = 4
SUBLEVEL = 22
EXTRAVERSION =

Make sure to add something to the EXTRAVERSION line like EXTRAVERSION=-test.

This will build a kernel called 2.4.22-test

[Note]Note

You need the - sign in EXTRAVERSION or else the version will be 2.4.22test