Linux-Mandrake:
User Guide and
Reference Manual

MandrakeSoft

 
 
January 2000
http://www.linux-mandrake.com


Next : Building and installing free software
Previous : Filesystems and mount points
Up

(Back to the table of contents)

Chapter 11 : Compiling and installing new kernels


Along with filesystem mounting and source compilation, this is undoubtedly the subject which causes the most problems for beginners. Compiling a new kernel is not generally necessary, since the kernels installed by Linux-Mandrake contain support for a significant number of devices, but...

It may be, why not, that you want to do it, for no other reason than to see "what it does". Apart from making your PC and your coffee machine work a bit harder than usual, not a lot. However, the aim of this chapter is that your coffee machine should still work after compilation.

There are also valid reasons. For example, you have read that the kernel you are using has a security bug, a bug which is corrected in a more recent version; or else, a new kernel includes support for a device you need. You have the choice of waiting for upgrades or else compiling a new kernel yourself, and opt for the second solution.

Whatever you do, stock up with coffee.

Where to find kernel sources

The main kernel source host site is ftp.kernel.org, but it has a large number of mirrors, all named ftp.xx.kernel.org, where xx represents the country's ISO code. Following the official announcement of the availability of the kernel, you should allow two hours for all the mirrors to be supplied.

On all these FTP servers, the sources are in the directory /pub/linux/kernel. Next, go to the directory with the series that interests you: it will undoubtedly be v2.2. There is nothing to prevent you trying version 2.3 kernels, but remember that these are experimental kernels. The file containing the kernel sources is called linux-<kernel.version>.tar.gz, e.g. linux-2.2.11.tar.gz.

There are also patches for application to kernel sources to upgrade it incrementally: thus, if you already have kernel sources version 2.2.11 and want to update to kernel 2.2.13, you do not need to download all the sources, but can simply download the patches patch-2.2.12.gz and patch-2.2.13.gz. As a general rule, this is a good idea, since sources currently take up more than 12 MB.

Unpacking sources, patching the kernel (if necessary)

Kernel sources should be placed in /usr/src. So you should go into this directory then unpack the sources there:

$ cd /usr/src
$ mv linux linux.old
$ tar xzf /path/to/linux-2.2.11.tar.gz

The command mv linux linux.old is required: this is because you may already have sources of another version of the kernel. This command will ensure that you do not overwrite them. Once the archive is unpacked, you have a linux directory with the sources of the new kernel.

Now, the patches. We will assume that you do want to patch from version 2.2.11 to 2.2.13 and have downloaded the patches needed to do this: go to the newly created linux directory, then apply the patches:

$ cd linux
$ gzip -dc /path/to/patch-2.2.12.gz | patch -p1 #
$ gzip -dc /path/to/patch-2.2.13.gz | patch -p1
$ cd ..

Generally speaking, moving from a version 2.2.x to a version 2.2.y requires you to apply all the patches numbered 2.2.x+1, 2.2.x+2, ..., 2.2.y in order . To "descend" from 2.2.y to 2.2.x, repeat exactly the same procedure but applying the patches in reverse order and with option -R from patch (R stands for Reverse). So, to go back from kernel 2.2.13 to kernel 2.2.11, you would do:

$ gzip -dc /path/to/patch-2.2.13.gz | patch -p1 -R
$ gzip -dc /path/to/patch-2.2.12.gz | patch -p1 -R

Next, for the sake of cleanness (and so that you know where you are), you can rename linux to reflect the kernel version and create a symbolic link:

$ mv linux linux-2.2.11
$ ln -s linux-2.2.11 linux

It is now time to move on to configuration. For this you have to be in the source directory:

$ cd linux

Configuring the kernel

To configure the kernel you have the choice between:

We will go through configuration section by section, but you can skip sections and jump to the ones that interest you if you are using menuconfig or xconfig. The choice for options is 'y' for Yes (functionality hard compiled into the kernel), 'm' for Module (functionality compiled as a module), or 'n' for No (do not include in the kernel).

For xconfig, you will have guessed what the Main Menu, Next and Prev buttons are for. For menuconfig, use the Enter key to select a section, and change options with 'y', 'm' or 'n' to change its status or else press the Enter key and make your choice for the multiple choice options. Exit will take you out of a section and out of configuration if you are in the main menu. And obviously, there is Help.

So here is a somewhat rough list of the options and the choices recommended for those options, gilded with explanations when necessary. The options not covered here are left to your discretion. Leaving them "as is" is generally a good idea.

And voilą! Configuration is finally over. Save your configuration and quit.

The configuration file is /usr/src/linux/.config. In general, it is a very good idea to make a backup copy! Preferably, put this copy in the personal directory of user root. As the configuration changes very little between kernel revisions (i.e. between two versions 2.2.x or 2.3.x or... kernels), you can use it again to configure your future kernels.

Next, time for compilation.

Compiling the kernel and the modules, installing modules

Small point to begin with: if you are recompiling a kernel with exactly the same version as the one already present on your system, the latter's modules must be deleted first. For example, if you are recompiling 2.2.10, you must delete directory /lib/modules/2.2.10.

Compiling the kernel and modules, and installing the modules is done in a single line:

$ make dep && make bzImage && make modules &&
  make modules_install

If you are asking what this famous && is for, here is the explanation: a && b first runs a, and runs b if and only if a was completed successfully. By extension, you can imagine what the above command line does: if one of the commands fails, the subsequent commands will not be run. Another thing that failure means is that there is a bug in the kernel! If that happens, tell us...

One more thing: no, compiling a new kernel will not invalidate the old one! If compilation fails here, it does not mean that your system will no longer start. To prevent your system from booting, you have to do something really stupid -- which, honestly, will not happen if you follow the instructions in this chapter to the letter :)

Installing the new kernel, updating LILO

With your kernel now successfully compiled, all you need to do now is install it. Again for the sake of cleanness and to identify your kernels unambiguously, it is preferable to maintain a certain discipline in naming. Let us assume that you are installing a 2.2.13 kernel. Here, the types of commands are as follows:

$ cp arch/i386/boot/bzImage /boot/vmlinuz-2.2.13
$ cp System.map /boot/System.map-2.2.13

After this, you still have to update the file /etc/lilo.conf. Obviously, retain the possibility of starting your current kernel! This is what a typical lilo.conf looks like, after you have installed your Linux-Mandrake distribution and before modification:

boot=/dev/hda
map=/boot/map
install=/boot/boot.b
prompt
timeout=50
image=/boot/vmlinuz-2.2.9-19mdk
        label=linux
        root=/dev/hda1
        read-only
other=/dev/hda2
        label=dos
        table=/dev/hda
Warning: This exemple assumes that you are using LILO as the main loader! If you are using System Commander, the boot= directive will be different, and you will probably have no other section.

A lilo.conf file consists of a main section, followed by a section for starting each operating system. In the example of the file above, the main section is made up of the following directives:

boot=/dev/hda
map=/boot/map
install=/boot/boot.b
prompt
timeout=50

The boot= directive tells LILO where to install its boot sector; in this case, it is the MBR (Master Boot Record) of the first IDE hard disk. If you want to make a LILO floppy disk, you simply replace /dev/hda with /dev/fd0 :) The prompt directive asks LILO to show the prompt on startup and to start the procedure after 5 seconds (timeout=50). If you remove the directive timeout=, LILO will wait until you have typed something.

Then comes a linux section:

image=/boot/vmlinuz-2.2.9-19mdk
        label=linux
        root=/dev/hda1
        read-only

A linux section always begins with the directive image=, followed by the full path to a valid Linux kernel. Like any section, it contains a label= directive as a unique identifier. The root= directive tells LILO which partition hosts the root filesystem for this Linux system. It may be different for you. The read-only directive orders LILO to mount this root filesystem as read-only on startup: if this directive is not there, you will get a warning message.

Then comes the Windows section:

image=/boot/vmlinuz-2.2.9-19mdk
        label=linux
        root=/dev/hda1
        read-only

In fact, a section beginning with other= is used by LILO to start any operating system other than Linux: the argument of this directive is the location of this system's boot sector, and in this case it is a Windows system. To find the boot sector, located at the beginning of the partition hosting this other system, Linux also needs to know the location of the partitions table which will enable it to locate the partition in question, which is done by the table= directive. The label= directive, as with a linux section, identifies the system.

Before adding our linux section, we will kill two birds with one stone :) Let's compose a message to be displayed on startup before the LILO prompt appears, to explain how to use LILO:

$ cat >/boot/message <<EOF
> Welcome , this is  LILO (LInux LOader).
> press the TAB key for a list of boot images .
> You have:
> * exp : start of Linux-Mandrake  with your new kernel
> * linux : original Linux-Mandrake  kernel
> * dos : Windows
> Pressing ENTER without entering an image name  will start
> the first image in the list, i.e. exp .
> EOF
$

And voilą! To display this message at boot up, you simply add the directive:

message=/boot/message

in the main section of lilo.conf. Now, you need to add the Linux section in order to start on the new kernel. In this example, it will be placed at the top, but nothing prevents you putting it somewhere else:

image=/boot/vmlinuz-2.2.13
        label=exp
        root=/dev/hda1
        read-only

If you compiled your kernel with the framebuffer, you will probably want to use it: in this case, you need to add a directive to the section which tells it what resolution you want to start in. The list of modes is available in the file /usr/src/linux/Documentation/fb/vesafb.txt (only in the case of the VESA framebuffer! Otherwise, refer to the corresponding file). For the 800x600 mode in 32 bits[22], the mode number is 0x315, so you need to add the directive:

vga=0x315

to our new LILO section. So this is what our lilo.conf looks like after modification, decorated with a few additional comments (all the lines beginning with #), which will be ignored by LILO:

#
# Main section
#
boot=/dev/hda
map=/boot/map
install=/boot/boot.b
# Our prompt message
message=/boot/message
# Show prompt...
prompt
# ... wait 5 seconds
timeout=50
#
# Our new kernel: default image
#
image=/boot/vmlinuz-2.2.13
        label=exp
        root=/dev/hda1
        read-only
# If the VESA framebuffer is used:
        vga=0x315
#
# The original kernel
#
image=/boot/vmlinuz-2.2.9-19mdk
        label=linux
        root=/dev/hda1
        read-only
#
# Windows Section
#
other=/dev/hda2
        label=dos
        table=/dev/hda

Don't forget to adapt the file to your configuration! The Linux root filesystem here is /dev/hda1 but it may well be somewhere else on your system, and the same thing applies for Windows. Now that the file has been modified appropriately, you must tell LILO to change the boot sector:

$ lilo
Added exp *
Added linux
Added dos
$

In this way, you can compile as many kernels as you want, by adding as many Linux sections as necessary. All you need to do now is restart to test your new kernel.

Part III : Appendix, Glossary and Index



Next : Building and installing free software
Previous : Filesystems and mount points
Up

Copyright © 2000 MandrakeSoft