4.8. Tutorial: configuring de kernel to the requirements of the user

In this section we will have a look at a small interactive workshop for the process of updating and configuring the kernel in the two distributions used: Debian and Fedora.

The first essential thing, before starting, is to know the current version of the kernel we have with uname -r, in order to determine which is the the next version that we want to update to or personalise. And the other is to have the means to boot our system in case of errors: the set of installation CDs, the floppy disc (or CD) for recovery (currently the distribution's first CD is normally used) or some Live CD distribution that allows us to access the machine's file system, in order to redo any configurations that may have caused problems. It is also essential to back up our data or important configurations.

We will look at the following possibilities:

1) Updating the distribution's kernel. Automatic case of Debian.

2) Automatic update in Fedora.

3) Adapting a generic kernel (Debian or Fedora). In this last case, the steps are basically the same as those presented in the section on configuration, but we will make a few more comments:

4.8.1. Configuring the kernel in Debian

In the case of the Debian distribution, the installation can also be done automatically, using the APT packages system. It can be done either from the command line or with graphic APT managers (synaptic, gnome-apt...).

We are going to carry out the installation using the command line with apt-get, assuming that the access to the apt sources (above all to the Debian originals) is properly configured in the /etc/apt/sources.list file. Let's look at the steps:

1) To update the list of packages.

# apt-get update

2) To list the packages associated with images of the kernel:

# apt-cache search linux-image

3) To select a version suitable for our architecture (generic, 386/486/686 for Intel, k6 or k7 for amd or in particular for 64Bits versions amd64, intel and amd or ia64, for Intel Itanium). The version is accompanied by kernel version, Debian revision of the kernel and architecture. For example: 2.6.21-4-k7, kernel for AMD Athlon, Debian revision 4 of the kernel 2.6.21.

4) Check for the selected version that the extra accessory modules are available (with the same version number) With apt-cache we will search for whether there are other dynamic modules that could be interesting for our hardware, depending on the version of the kernel to be installed. Remember that, as we saw in the Debian way, there is also the module-assistant utility, which allows us to automate this process after compiling the kernel. If the necessary modules are not supported, this could prevent us from updating the kernel if we consider that the functioning of the problematic hardware is vital for the system.

5) Search, if we also want to have the source code of the kernel, the Linux-source-version (only 2.6.21, that is, the principal numbers) and the corresponding kernel headers, in case we later want to make a personalised kernel: in this case, the corresponding generic kernel patched by Debian.

6) Install what we have decided: if we want to compile from the sources or simply to have the code:

# apt-get install linux-image-version # apt-get install xxxx-modules-version (if some modules are necessary)


# apt-get install linux-source-version-generic # apt-get install linux-headers-version

7) Install the new kernel, for example in the lilo bootloader (check the boot utility used, some recent Debian versions use grubas boot loader), this is done automatically. If we are asked if the initrd is active, we will have to verify the lilo file (/etc/lilo.conf) and, in the lilo configuration of the new image, include the new line:

initrd = /initrd.img-version (or /boot/initrd.img-version)

once this is configured, we would have to have a a lilo of the mode (fragment), supposing that initrd.img and vmlinuz are links to the position of the files of the new kernel:

default = Linux

image = /vmlinuz 
			label = Linux 
			initrd = /initrd.img
#		restricted
#		alias = 1 
image = /vmlinuz.old
			label = LinuxOLD
			initrd = /initrd.img.old
#		restricted
#		alias = 2

We have the first image by default, the other is the former kernel. Thus, from the lilo menu we can ask for one or the other or, simply by changing the default, we can recover the former. Whenever we make any changes in /etc/lilo.conf we should not forget to rewrite in the corresponding sector with the command /sbin/lilo or /sbin/lilo -v.

4.8.2. Configuring the kernel in Fedora/Red Hat

Updating the kernel in the Fedora/Red Hat distribution is totally automatic by means of its package management service or else by means of the graphic programs that the distribution includes for updating; for example, in business versions of Red Hat there is one called up2date. Normally, we will find it in the task bar or in the Fedora/Red Hat system tools menu (check the available utilities in tools/Administration menus, the currently available graphic tools are highly distribution version dependent).

This updating program basically checks the packages of the current distribution against a Fedora/Red Hat database and offers the possibility of downloading the updated packages, including those of the kernel. This Red Hat service for businesses works via a service account and Red Hat offers it for payment. With this type of utilities the kernel is updated automatically.

For example, in figure 10, we can see that once running, a new available version of the kernel has been detected, which we can select for downloading:

In Fedora we can either use the equivalent graphic tools or simply use yum directly, if we know that new kernels are available:

# yum install kernel kernel-source

Once downloaded, we proceed to install it, normally also as an automatic process, whether with grub or lilo as boot managers. In the case of grub, it is usually automatic and leaves a pair of options on the menu, one for the newest version and the other for the old one. For example, in this grub configuration (the file is in /boot/grub/grub.conf or else /boot/grub/menu.lst), we have two different kernels, with their respective version numbers.

#file grub.conf default = 1 timeout = 10 splashimage = (hd0,1)/boot/grub/splash.xpm.gz

title Linux (2.6.20-2945) root (hd0,1) kernel /boot/vmlinuz-2.6.20-2945 ro root = LABEL = / initrd /boot/initrd-2.6.20-18.9.img

title LinuxOLD (2.6.20-2933) root (hd0,1) kernel /boot/vmlinuz-2.4.20-2933 ro root = LABEL = / initrd /boot/initrd-2.4.20-2933.img

Each configuration includes a title that appears during start up. The root or partition of the disc from where it boots, the directory where the file corresponding to the kernel is found and the corresponding initrd file.

In the case of having lilo (by default grub is used) in the Fedora/Red Hat as manager, the system will also update it (file /etc/lilo.conf), but then we will have to rewrite the boot manually with the command /sbin/lilo.

It is also important to mention that with the previous installation we had the possibility of downloading the sources of the kernel; these, once installed, are in/usr/src/linux-version and can be compiled and configured following the usual procedure as if it was a generic kernel. We should mention that the Red Hat company carries out a lot of work on the patches and corrections for the kernel (used after Fedora) and that its kernels are modifications to the generic standard with a fair number of additions, which means that it could be better to use Red Hat's own sources, unless we want a newer or more experimental kernel than the one supplied.

4.8.3. Configuring a generic kernel

Let's look at the general case of installing a kernel starting from its sources. Let's suppose that we have some sources already installed in /usr/src (or the corresponding prefix). Normally, we would have a Linux directory or linux-version or simply the version number. This will be the tree of the sources of the kernel.

These sources can come from the distribution itself (or we may have downloaded them during a previous udpate), first it will be interesting to check whether they are the latest available, as we have already done before with Fedora or Debian. Or if we want to have the latest and generic versions, we can go to kernel.org and download the latest available version (better the stable one than the experimental ones), unless we are interested in the kernel's development. We download the file and in /usr/src (or another selected directory, even better) decompress the kernel sources. We can also search to see if there are patches for the kernel and apply them (as we have seen in section 4.4).

Next, we will comment on the steps that will have to be carried out: we will do it briefly, as many of them have been mentioned before when working on the configuration and tailoring.


It would be advisable to reread section 3.4.3.

1) Cleaning the directory of previous tests (where applicable):

make clean mrproper

2) Configuring the kernel with, for example: make menuconfig (or xconfig, gconfig or oldconfig). We saw this in section 4.3.

4) Dependencies and cleaning of previous compilations:

make dep

5) Compiling and creating an image of the kernel: make bzImage. zImage would also be possible if the image was smaller, but bzImage is more normal, as it optimises the loading process and compression of larger kernels. On some ancient hardware it may not work and zImage may be necessary. The process can last from a few minutes to an hour on modern hardware and hours on older hardware. When it finishes, the image is found in: /usr/src/directory-sources/arch/i386/boot.

6) Now we can compile the modules with make modules. Until now we have not changed anything in our system. Now we have to proceed to the installation.

7) In the case of the modules, if we try an older version of the kernel (branch 2.2 or the first ones of 2.4), we will have to be careful, since some used to overwrite the old ones (in the last 2.4.x or 2.6.x it is no longer like this).

But we will also need to be careful if we are compiling a version that is the same (exact numbering) as the one we have (the modules are overwritten), it is better to back up the modules:

cd /lib/modules tar -cvzf old_modules.tgz versionkernel-old/

This way we have a version in .tgz that we can recover later if there is any problem And, finally, we can install the modules with:

make modules install

8) Now we can move on to installing the kernel, for example with:

# cd /usr/src/directory-sources/arch/i386/boot # cp bzImage /boot/vmlinuz-versionkernel # cp System.map /boot/System.map-versionkernel # ln -s /boot/vmlinuz-versionkernel /boot/vmlinuz # ln -s /boot/System.map-versionkernel /boot/System.map

This way we store the symbols file of the kernel (System.map) and the image of the kernel.

9) Now all we have to do is put the required configuration in the configuration file of the boot manager, whether lilo (/etc/lilo.conf) or grub (/boot/grub/grub.conf) depending on the configurations we already saw with Fedora or Debian. And rememeber, in the case of lilo, that we will need to update the configuration again with /sbin/lilo or /sbin/lilo -v.

10) Restart the machine and observe the results (if all has gone well).