This will be a somewhat comprehensive guide to compiling and installing the Linux kernel on a modern Linux environment. If you would like to contribute to this guide, or correct my errors, please contact me at metiscus@gmail.com.
Introduction
The Linux kernel is the i/o manager for the Linux system. Shells, applications and drivers interact with the kernel for access to system resources. Since the kernel is central to a Linux system, we must approach its modification with great care and preparation.
Step 1 - Safety net
Before we begin, we should ensure that we have a way to run the old kernel, in case we forget to compile something important into our new kernel. There are two main things to back up, the kernel itself and its modules.
Backing up the kernel
The kernel is typically kept in the /boot partition (or directory). You must ensure that you have the proper permissions to modify this root-only-edit file. This is done either by logging in as root, or using sudo. It is unlikely that your kernel will be corrupted during a compilation, but it is nevertheless prudent to have a backup. I usually backup the entire boot partition (or directory) with the following command. This will make a tarball (compressed archive) of your entire boot partition and place it in your home directory.
tar c /boot/* | gzip -c > ~/boot.tar.gz
The kernel consists of more than just a binary, there is also a configuration file that will allow you to rebuild your kernel from scratch should anything ever happen to it. It is typically located at /usr/src/{kernel version}/.config. Should anything go wrong, you will also want this file, so put a copy someplace safe.
The next step is to back up any modules that came with your kernel, so that in the case that you need to load this kernel again, you will be able to access these important drivers. Your kernel modules are typically located at /lib/modules/KERNELVERSION/kernel/. You can use the command above, changing /boot/* to /lib/modules/KERNELVERSION/kernel/* and ~/boot.tar.gz to ~/kernel-modules.tar.gz to do this.
With your kernel, its configuration files and modules safely tucked away we can now start the next step.
Step 2 - Preparations
We need to obtain a list of all of the devices connected to our system. To do this, we can use two commands. The first, is dmesg. This command lists all of the diagnostic messages from the kernel when it starts up. This can be useful in diagnosing why your newly compiled kernel doesn't do x or y. A good thing to do is save the output of this message to a text file for review or printing at a later time.
The second command gives us a little bit more information about the connected devices, but is sligltly more cryptic. LSPCI as the name lends, lists the connected pci devices giving the pci device name and a variety of other information. Our best bet here is to dump the content of this file to a text document for printing while we configure the kernel.
This article is ©2008 by the respective authors. Reproduction is prohibited without express permission from all contributors.