-->

Previous | Table of Contents | Next

Page 71

Before you begin, however, be prepared to wait. Depending on system speed, available memory, and other processes, compiling the kernel can take from 10 minutes for a fast Pentium to 1.5 hours for a slow i386. The process will also slow down your system for other tasks. If you are sharing CPU time with other people, you might want to wait until the CPU is less busy before embarking on this task.

The magic command to start the build is as follows:


make dep;make clean;make zImage

This line actually contains three commands in one. The first one, make dep, actually takes your configuration and builds the corresponding dependency tree. This process determines what gets compiled and what doesn't. The next step, make clean, erases all previous traces of a compilation so as to avoid any mistakes in which version of a feature gets tied into the kernel.
Finally, make zImage does the full compilation. After the process is complete, the kernel is compressed and ready to be installed.

NOTE
As the kernel compiles, all the commands necessary to do the actual compilation will scroll down your screen. Although you don't need to understand the compilation process in detail, having some background in C programming and Makefiles is useful. Having this knowledge typically makes troubleshooting a little easier because the error messages make more sense. If you do not have this sort of background, look out for messages such as

make:***[directory/file.o] Error 1



where [directory/file.o] is the file at which the compilation failed. Take note of the first message starting with gcc after the preceding line. For example, if the output looks like

gcc -D__KERNEL__ -I/usr/src/linux/include -Wall -Wstrict-prototypes -O2

Â-fomit-frame-pointer -fno-strength-reduce -pipe -m486 -malign-loops=2

Â-malign-jumps=2 -malign-functions=2 -DCPU=586  -c -o init/main.o init/main.c

init/main.c:53: warning: function declaration isn't a prototype

init/main.c: In function `main':

init/main.c:53: storage class specified for parameter `_stext'

[...]

make:***[init/main.o] Error 1



you're interested in the line that says

init/main.c:53: warning function declaration isn't a prototype



Be sure to include this information when requesting help.

Before you can install the new kernel, you need to compile the corresponding modules. You do so by using the following command:


make modules

Again, watch for errors in the compilation.

Page 72

Installing the Kernel

After the kernel and its corresponding modules are compiled, you're ready to start the installation.

Begin by checking the current /boot directory to see which kernels are presently installed. Most kernels' filenames begin with the vmlinuz string, but if you aren't sure, check the /etc/lilo.conf file to see which kernels are currently offered at boot time and their locations. (See Chapter 3 for additional information about LILO.)

After you know what the current kernels are, copy the file /usr/src/linux/arch/i386/boot/zImage from the kernel source tree to /boot, and give it an appropriate new name. For example, the sample kernel is the first kernel compiled with SCSI support in it, so you can use the following copy command:


cp /usr/src/linux/arch/i386/boot/zImage /boot/vmlinuz-2.0.30-scsi

The unique name enables you to see easily why that kernel is different from the others.

With the kernel in place, you're ready to start installing the appropriate kernel modules. As you do with the kernel, you should make a backup of the existing modules before installing the new ones.

To make a backup of the current modules, go into the /lib/modules directory and rename the current kernel version number to something else. For example, if the current version is 2.0.30, you can use the following:


cd /lib/modules

mv 2.0.30 2.0.30-working

This command renames the modules to 2.0.30-working so that, in the event the new modules don't work as advertised, you can erase the new ones and rename this directory to 2.0.30 and regain control of the system.

After you back up the modules, change back into the kernel source directory and type


make modules_install

to install the modules into the /lib/modules/version_number directory, where version_number is the version number of the kernel you just compiled.

Finally, you need to edit the /etc/lilo.conf file to make your new kernel one of the boot time options. Do not remove the currently working kernel as an option! You will need it in case the new kernel doesn't work the way you expect it to. Remember to rerun LILO after making changes. Reboot and then test your results.

Page 73

WARNING
When loading your kernel for the first time after a reboot, you might get the error that the kernel is too large. This happens because the kernel is compressed during the build procedure and then decompressed at boot time. Because of the nature of the Intel architecture, the kernel must be able to decompress within the first 1MB of memory, and if it can't, the system can't boot.
If you receive the "Kernel is too large" message, reboot and choose your old backup kernel to boot from.
At this point you have two choices: You can either go reconfigure your kernel and trim down unnecessary items by either not including them or using them as modules, or you can use make bzImage to build a kernel that can work around the kernel size limitation.

Recovering from Faulty Kernels

While you're learning the nuances of the Linux kernel and its parameters, you might make some mistakes and need to recover the system in its prior state. Having backed up your kernels and modules (you did that, right?), this process is relatively easy.

Begin by rebooting the system into single user mode. At the lilo: prompt, select the previously working kernel to boot with the kernel parameter single. As it boots up, you will notice errors as part of the process. Don't worry; the errors are caused by the mismatched modules in the /lib/modules directory.

After you log in, go to the /lib/modules directory and erase the current module installation. For example, if you renamed your old modules 2.0.30-working and your new modules are 2.0.30, then use the following command:


rm -rf 2.0.30

Using this command removes all the current modules for the broken kernel. With the broken programs gone, rename the stable kernel with its original name and reboot. This procedure should give you full control of your system again.

Summary

The kernel is the heart of Linux as well as one of its key features; other versions of UNIX have kernels three to four times the size without three to four times the functionality. Of course, this kernel provides the added benefit of the source code as well.

Previous | Table of Contents | Next