There are several reasons why you might want to customize the Linux kernel. For example, you might want to make the kernel as small as possible to minimize its memory usage. You might be running a Linux server, and you need support for the latest networking features.

Whatever the reason, customizing the Linux kernel is not difficult, provided you follow a step-by-step process. In this Daily Drill Down, I’ll explain a process for you to follow when compiling a custom Linux kernel.

What you needFor this Daily Drill Down, I’ll be using the 2.2.14-12 version of the Linux kernel. A new version of the kernel may be available when you read this, but the process will be the same. The new kernel may provide some configuration options that were not available at the time of this writing. To obtain these files, go to the Red Hat mirror listing and download the files from the mirror site closest to you:

Kernel-2.2.14-12.i386.rpm—The kernel itself

Kernel-source-2.2.4-12.i386.rpm—Kernel source required for compiling a new kernel

Kernel-headers-2.2.4-12.i386.rpm—C language headers; required for compiling a new kernel

Configuring the kernel for a Linux serverBefore we actually hack the kernel, let's look at some of the methods available to us. In most situations, X Windows will not be installed on a Linux server. There are two ways to configure the kernel without having X Windows installed. Regardless of the method chosen, the choices available when configuring the kernel are the same.

Using configThe config method is the oldest way of configuring the kernel. This method is not recommended for users who are not completely comfortable installing and compiling a custom kernel. To use the config method, run the following commands from the command prompt:cd /usr/src/linux-kernel-version

where kernel-version is the kernel RPM file you just installed. On my system, I run the command:cd /usr/src/linux-2.2.14

Then, I run the command:make config

The config method prompts the user to select kernel options at the command line. Don't worry about what config is asking for—I’ll discuss the options in detail later.If you’re not an experienced kernel hacker, don’t use the config option! You cannot correct any mistakes you make using this method. The make menuconfig methodThe make menuconfig method is the better choice for a beginning kernel hacker. By using make menuconfig, the user is presented with a menu-driven configuration tool that is easier to use than the command-line prompt associated with the make config method. To use the make menuconfig method, run the following commands from the command prompt:cd /usr/src/linux-2.2.14

followed by the command:make menuconfig

The menuconfig option presents the user with a menu-driven interface. The menuconfig option is a lot easier to use than the make config method. This is the recommended method for beginning hackers to configure kernel options from the command prompt.

It’s possible to configure a kernel remotely, using Telnet. If you’d like to use make menuconfig to configure a kernel remotely, make sure the remote server has a Telnet client that’s capable of good terminal emulation in order to present the full-screen menu.

The xconfig methodThe xconfig method is the most user-friendly way of configuring the Linux kernel. To use the xconfig method, run the following commands from an X Windows terminal:cd /usr/src/linux-2.2.14

followed by the command:make xconfig

One of the biggest advantages to using xconfig is that the user is able to have multiple sections open at the same time. This allows for easy confirmation when more than one option is required to enable support for a specific option.

Selecting options for the kernelRegardless of the method you choose, the options available remain the same. Now, let's select the options to include in the kernel. When using the config or makeconfig option, the default option is always capitalized in the square brackets. Help is available by entering a question mark (?) and pressing [Enter].

Code Maturity LevelThis option allows you to be prompted for kernel options that are still under development. This option is for experienced kernel hackers only. Select No.

Processor Type And FeaturesYou need to select the type of processor your system is running:Math Emulation

Select No unless your system is running a very old processor.Config MTRR

Memory Type Range Registers (MTRR) are used for video support. Select Yes for a workstation or desktop installation. Select No for a server without X Windows installed.Symmetric Multi-Processing Support

Select Yes only if your system is running multiple CPUs.

Loadable Module SupportThe strength of the Linux kernel lies in its ability to use loadable modules. Loadable modules are code for device drivers and filesystem features that are compiled with the kernel but are not necessarily loaded when the system is booted. The advantage to using loadable modules is that support for hardware is available when needed. This allows for less memory usage by the kernel and means more hardware independence. It’s difficult to imagine a situation where you wouldn’t want to load module support. When deciding whether to use loadable modules, there are some questions you’ll need to answer:Enable Loadable Module Support

Always answer Yes, and set version information on all symbols for modules. Selecting Yes allows new kernels to be configured without recompiling the modules. Normally, modules are recompiled with each new kernel.Kernel Module Loader

Select Yes. Modules may be loaded by the kernel daemon (kerneld) or by a module loader.

General SupportYou configure general options in this section:Networking Support

Always answer Yes.PCI Quirks

Select the default.System V IPC

Always select the default.PCI Support

Always answer Yes.MCA Support

This is required for IBM PS/2 systems only.BSD Process Accounting

Either Yes or No is acceptable.PCI Mode

Select the default (any).SGI Visual Workstation Support

This is required only for SGI workstations.Sysctl Support

Sysctl support allows the kernel to be changed dynamically in the /proc filesystem without rebooting. Select Yes.

Plug And Play SupportPlug and play (PNP) is not as advanced in Linux as it is in some other operating systems. You may select Yes, but it is always best to use hardware that has the ability to turn off PNP.Plug And Play Support

Answer Module or Yes.Auto-Probe For Parallel Devices

Select Module [m].Block Devices

This is the section where you will be asked about your system's disk drives.Normal PC Floppy Disk Support

Select Yes.Enhanced IDE/MFM/RLL Disk/Carom/Tape/Floppy Support

Select Yes.Use Old Disk-Only Driver On Primary Interface

Select No.Include IDE/ATA-2 Disk Support

Select Yes.Include IDE/ATAPI CD-ROM Support

Select Yes.Include IDE/ATAPI Tape Support

Select No if you don’t use a tape drive.Include IDE/ATAPI floppy support

Select Yes or Module [m].SCSI Emulation Support

Select No.CMD640 Chipset Bugfix/Support

Select Yes.

Networking OptionsThis is one of the most important areas of kernel configuration. Study the present requirements of your network, and prepare for future needs.Packet Socket

The packet protocol is required by several programs, including tcpdump. Always select Yes.Kernel/User Netlink Socket

This is required if you want to use your system as a packet-filtering firewall. Select Yes.Routing Messages

Select Yes.Socket Filtering

Select Module or Yes.Netlink Device Emulation

Select Yes.Unix Domain Sockets

Select Yes.Network Firewalls

This is required to run a firewall. Select Yes for gateway and router configuration.TCP/IP Networking

No TCP/IP, no Internet. Select Yes.IP: Multicasting

This is required to transfer large amounts of data, such as real-time video. Select Yes or Module.IP: Advanced Router

This is required if you want to run your Linux server as a router or gateway. Select Yes.QoS And/Or Fair Queuing

Select No.Telephony Support

For most systems, select Module [m].

SCSI SupportThis section allows you to configure support for SCSI tape drives and disks. Answer the questions based on your system hardware. The following selections are typical for this section:SCSI Support

In most cases, you may accept the default answer in all categories.Mice

Mouse support may not be required on a server. On a desktop or workstation, it almost certainly will be required. Answer Yes for PS/2 mouse support. This will provide support for the Microsoft PS/2 mouse and compatible mice. Answer Yes, or select Module [m] for the other options.Joysticks

Select Yes for the type of joystick you have on your system. Selecting Module [m] will make joystick support available later. Select the defaults here.Selecting Video For Linux

This section enables support for video capture cards and FM radio cards. Selecting Module [m] will allow for support of any of these devices you install in the future.Ftape, Floppy Tape Device Support

Answer Yes here if you are using a tape drive that is connected to your floppy drive controller. If you don't use a floppy tape device, answer No.Filesystems

In this section, the kernel is configured for filesystem-specific features. If you’re on a multiuser system, you should consider quota support. This will allow the administrator to set limits on the amount of disk space available to users. Select Yes or Module [m] for Kernel Automounter Support. Select the defaults for the remaining options, or select Yes if you want to provide support for a specific filesystem.

Network FilesystemsThe network filesystems required may vary greatly from system to system. Preparation is the key here. You will need to know both the present and future requirements for your system. If you think your system will require support for a particular filesystem in the future, compile it as a module, and the support will be there when you need it.Coda

The coda filesystem is experimental and is not recommended. Select No or module.NFS Support

If you want to use NFS, select the default.NFS Server Support

Select the default.SMB Filesystem Support

Select Yes or Module if you want to mount Windows 9x/NT filesystems as SMB shares under Linux.NCP Support

Select Yes only if you want to mount NetWare volumes on a Linux system. The default is fine for most systems. Select Yes for all other options. Select Yes for any partition type you will want to support under Linux. Beginners should stick to the defaults.Native Language Support

Select the defaults.Console Drivers

Beginners should accept the defaults.Sound

Select Yes or Module [m] for these options. This will ensure that sound support is available when you need it. This option is not necessary for a server.Additional Low Level Sound Drivers

Accept the defaults. Select Yes if you want support for a specific device on your system. This option is usually required on a server.Kernel Hacking

This section relates to an advanced kernel topic. Beginners should accept the default.

Compiling and booting the kernelAt this point, you have selected the options you want included with the new kernel. Before you compile the new kernel, you need to run a series of commands.

First, ensure that all dependencies within the kernel source code are correct. This is accomplished with the command:make dep

This command may take several minutes to run. There should be no errors unless there is a problem with the kernel source code.

The next step is to install the modules in the /lib/modules/2.2.14 directory. Run the command:make modules_install

Next, copy the new kernel to the /boot directory. Run the command:cp /usr/src/linux-2.2.14/arch/i386/boot/bzImage /boot/vmlinuz-2.2.14

After that, copy the new System.map file to the /boot directory with the command:cp /usr/src/linux-2.2.14/System.map /boot/System.map-2.2.14

The next step is to create a new symbolic link called /boot/System.map with the command:ln -s /boot/System.map-2.2.14 /boot/System.map

Next, install lilo. Run the following command:/sbin/lilo

The last step is to edit /etc/lilo.conf to create a new configuration for the kernel you’ve just installed. Open /etc/lilo.conf in any text editor. From there, you may create a new configuration section, or you may edit the existing one to reflect your new kernel. The kernel configuration section begins with the line image= and continues until the next section begins with the line other=. You may edit the existing section at the image line to reflect the new kernel version or copy and paste the section within the lilo.conf file. Then, edit the image=line. The second option will give you two possibilities for booting into Linux. Now, reboot your system. Your Linux system should now be running under the new kernel.

Patching the Linux kernelIt’s quite common for an administrator to patch the kernel source and then rebuild. This eliminates the requirement to install a new kernel. There are two ways to patch the Linux kernel. The first way is to use this command:zip -cd patchxx.gz | patch –p0

The second way is to use the patch-kernel script, located in the /usr/src/linux/scripts directory. Copy the patch file in the /usr/src directory, and in this directory, run the command:./patch-kernel

Then, recompile and reinstall the kernel.

SummaryThe kernel is the heart of the Linux operating system. The ability to install a new kernel suitable to your system requirements is a valuable skill for administrators. In this Daily Drill Down, I’ve explained how to compile and install a Linux kernel to meet the needs of your system.

Jim McIntyre has been training users on IT-related subjects since 1988. He began his training career as a sonar operator in the Canadian Navy. After retiring early from the military in 1996, Jim completed the Novell CNE program, the Adult Education program at Saint Francis Xavier University, and the Webmaster Program at Dalhousie University. He also graduated from the Train the Computer Trainer program at Dalhousie, where he now serves as a contract instructor. Jim has extensive technical support experience, and he tries to see technical problems as training opportunities. If Jim had a motto, it would be: "Share what you know; learn what you don't." He didn't come up with that phrase, but he likes it.

The authors and editors have taken care in preparation of the content contained herein, but make no expressed or implied warranty of any kind and assume no responsibility for errors or omissions. No liability is assumed for any damages. Always have a verified backup before making any changes.