Part V The Kernel and Its Parameters 315 Chapter 13 The Kernel The standard SuSE kernel, which is written to disk after installation (and which is found in a correctly installed system under /boot), is configured to support as wide a range of hardware and other kernel features as possible. For this reason this kernel is not specifically tuned to your own hardware. If you have made the right selection during the installation or update, then this kernel will be specifically optimised for your processor. However, it is possible that this kernel may not be ideal for your purposes, most of which relate to network server and routing tasks. In addition, a small amount of RAM will be wasted as a small number of unnecessary drivers are loaded. Thus, there are some advantages to building a kernel of your own. Further- more, creating your own kernel can, in some cases, provides access to exotic hardware which is not supported by our standard kernels (e. g., exotic bus- mice). Additionally, kernel configuration provides a view into the current status of development of the Linux kernel. Several Makefiles are provided with the kernel to help automate the pro- cess. These Makefiles handle nearly all the details for you. The only thing you have to do by hand is to make selections which correspond to hardware settings and other kernel features. Installation support is not provided for kernels that are not included with SuSE Linux (see Section H.1.2 page 493); we will be pleased to help you, however, in the context of our Professional Services (see Section H.3 page 497). The description below is based on kernel series 2.2.x. Many of the issues mentioned here will be valid for 2.0.x but they might differ in the details!' 13.1 Kernel Sources To build a kernel the following packages must be installed: the kernel sources (obviously!), (package lx suse), the C compiler (package gcc), the GNU binutils (package binutils) and the include files for the C compiler (pack- age libc). They are located in series D (Development) on the CD-ROM. It is highly recommended to install the C compiler in any case, since the C language is inseparable from UNIX operating systems. 317 13. The Kernel The kernel sources are located in /usr/src/linux. If you plan to experi- ment with different kernel sources, you can unpack them in different directo- ries under the directory /usr/src and create a symbolic link, /usr/src/ linux , to the current kernel source. This is what YaST does automatically. Since there is a lot of software that relies on the sources being in /usr/src/ linux, you should maintain this directory as a symbolic link to your current kernel source to provide an error-free compilation of system programs which need to access the kernel sources. 13.2 Kernel Modules Many drivers and features no longer have to be compiled directly into the kernel, but can be loaded at runtime via kernel modules. Which drivers are to be compiled into the kernel, and which are loaded as runtime modules, is defined in the kernel configuration. Kernel modules are located at /lib/modules/ , where is the actual kernel version. The use of this feature decreases the size and RAM requirements of the ker- nel, which is quite desirable. For this reason, it is best to use this feature wherever it is reasonable. Basically, components which are not required for the system to boot up may be built as modules. This makes sure that the ker- nel doesn't get too big to be loadable by the BIOS or a bootloader. Drivers which are required for boot, such as ext2, the SCSI drivers on a SCSI-based system, and similar items should be compiled into the kernel. In contrast, items such as isofs, msdos, or sound, which are not needed for starting up your computer system, may be built as modules. Handling Modules The following commands are available for your use: * insmod insmod loads the requested module after searching for it in a subdirectory of /lib/modules/. It is preferable, however, to use modprobe (see below) rather than insmod, which should no longer be necessary. * rmmod Unloads the requested module. This is only possible if this module is no longer needed. It is not possible to unload the isofs module (the CD-ROM filesystem), for example, while a CD is still mounted. * depmod Creates the file modules.dep in /lib/modules/ where dependencies of all of the modules are defined. This is necessary to ensure that all dependent modules are loaded along with the selected ones. If START KERNELD is set in /etc/rc.config, this file is created each time the system is started. * modprobe Loads or unloads a given module, while taking into account dependen- cies of this module. This command is extremely powerful and can be 318 13.2. Kernel Modules used for a lot of things (e. g., probing all modules of a given type un- til one is successfully loaded). In contrast to insmod, modprobe checks /etc/modules.conf and is the preferred way for loading modules. For detailed information on this topic, please refer to the corresponding manual page. * lsmod Shows you which modules are currently loaded and by how many other modules they are being used. Modules started by the kernel daemon are tagged by autoclean, which shows that these modules will be removed automatically when they reach their idle time limit. /etc/modules.conf Loading of modules is further influenced by /etc/modules.conf. see also manpage for depmod (man depmod). NOTE: From SuSE Linux 6.3 the file name was changed from /etc/conf.modules to /etc/ modules.conf. In this file the parameters for modules which access hardware directly can be entered, as such modules may need system-specific options (e. g. CD-ROM- driver or network driver). The parameters entered here are in principle iden- tical to those at the boot prompt of the kernel (e. g. for LILO (see Chapter 14 page 325), but they differ in a number of details. If loading a module failed, you can try again after specifying your hardware in /etc/modules.conf. Kmod ­ The "Kernel Module Loader" From version 2.2.x, the kernel module loader is the most elegant way to use modules, and replaces the old kernel daemon (kerneld). This kernel feature allows the kernel to launch modprobe directly and ensures that the necessary modules are loaded as soon as this is required by the kernel. To use the kernel module loader, you must set the corresponding variable in the kernel configuration `Kernel module loader' (CONFIG KMOD) The drivers needed to access the root filesystem should be compiled directly into the kernel. So you should not configure your SCSI driver or your filesys- tem (normally: ext2) as modules! Because SuSE Linux however, now uses initrd initial ramdisk and integrates the SCSI driver, for example, using this method, you must make sure when compiling your own kernel you adjust the vari- able INITRD MODULES in the file /etc/rc.config (Section 17.6 page 402) and comment out the initrd line in /etc/lilo.conf (see Section 16.2.5 page 381). If you don't do this the kernel will hang when you boot. Kernel modules come in handy for rarely used functionality, such as parport and printer support, drivers for floppy drives and filesystems that are rarely used). The Kmod is not designed to automatically unload modules; the potential saving in memory is only marginal for the RAM capacity of computers today; 319 13. The Kernel see also /usr/src/linux/Documentation/kmod.txt. For reasons of performance it is better for server machines, which have special tasks to perform, and need only a few drivers, to have a "monolithic" kernel. 13.3 Kernel Configuration The configuration of the kernel that was set up during installation or during an update can be taken from the file /usr/src/linux/.config (see Section 2.2.9 page 33) This file, however, describes only the kernel, and not the modules, which come from the package kernmod. If you also want to compile new modules, you must select these manually. Configuring the kernel can be done in three different ways: 1. On the command line 2. In a menu in text mode 3. In a menu under the X Window System Here is a short overview of these three methods. Configuring on the Command Line To configure the kernel, just change to /usr/src/linux and enter: earth:/usr/src/linux # make config You are asked to choose the options that you want supported by the kernel you are about to build. There are two or three possible answers here: y , n or m . `m' means that this device is not compiled directly into the kernel but as a module instead. Any driver that is needed to boot the system should be integrated into the kernel, and not be loaded as a module. If you press any other key, you get a short help text about the current option. Configuring in Text Mode A much more convenient way of configuring the kernel can be achieved by typing: earth:/usr/src/linux # make menuconfig With make menuconfig, you can review your changes, go through the ques- tions in your own preferred order, and in the event of a mistake, you do not have to go through all the questions again. Configuring Under the X Window System If you have installed and configured the X Window System (package xf86) and Tcl/Tk (package tcl and package tk), you can use: earth:/usr/src/linux # make xconfig as an alternative. You will be presented with a GUI (Graphical User Interface) which makes kernel configuration very user-friendly. You should have started the X Window System as `root' or you will have to take additional steps into consideration (e. g., taking over the display from another user). 320 13.4. Settings in the Kernel Configuration 13.4 Settings in the Kernel Configuration All the individual configuration possibilities of the kernel cannot be covered Help Texts here in detail. Please make use of the numerous help texts available on kernel configuration. The latest kernel documentation is always in /usr/src/ linux/Documentation. 13.5 Compiling the Kernel You may remove the comment in the main Makefile (app. line 74). That's the line containing: INSTALL PATH=/boot. This lets you install your own kernel to /boot. We recommend that you compile a "bzImage". As a rule this avoids the problem of the kernel getting too large, as can easily happen if you select too many features and create a "zImage" (messages such as "kernel too big" or "System is too big") are then typical. After adapting the kernel configuration to your needs, start compilation by entering: earth:/usr/src/linux # make dep earth:/usr/src/linux # make clean earth:/usr/src/linux # make bzImage These three commands can be entered on one line as well. They are started one after the other. This might be useful if you want to compile a kernel overnight, for example. Just enter: earth:/usr/src/linux # make dep clean bzImage Depending on your system, it now takes from just a few minutes (AMD Athlon / Intel Pentium III)1 to up to several hours for a 386 with 8 MB. While compiling, you can still work on one of the other consoles. After a successful compilation, you will find the kernel in the directory /usr/src/ linux/arch/i386/boot The kernel image ­ the file which contains the kernel ­ is called bzImage If this file does not exist, then your compile was not successful. The error may have been lost in all the output. You can verify if mistakes were made by entering: earth:/usr/src/linux # make bzImage and watch for error messages. But do not panic: errors are very rare! If you are using the Bash shell you may enter: earth:/usr/src/linux # make bzImage 2>&1 | tee ker- nel.out for writing the compilation output to kernel.out. Using the Tcsh this command is invoked as: earth:/usr/src/linux # make bzImage |& tee kernel.out 1 A very popular test for hardware and software is to compile the kernel with make -j. You will need quite a lot of RAM (more than 100 MB). This launches a compiler for each source file. 321 13. The Kernel If you have configured parts of your kernel to be loaded as modules you need to launch the compilation of modules after you have compiled the kernel. This may be achieved by typing: earth:/usr/src/linux # make modules After the modules have been compiled successfully, you must install them into the appropriate directories (/lib/modules/) by enter- ing: earth:/usr/src/linux # make modules install 13.6 Installing the Kernel After having compiled a kernel, you have to make sure that it is available for use from now on. If you use LILO, you have to run it again, so that the new kernel is recognized. Normally, you can just copy the new kernel to /boot/vmlinuz and invoke LILO: After you have compiled the kernel you must ensure that it can be booted. If you use LILO, then this must be re- installed. In the simplest case, copy the the new kernel to /boot/vmlinuz (see Section 13.5 on the preceding page) and then run LILO to protect yourself from unpleasant surprises, however, it is recommended that you initially retain the old kernel (/boot/vmlinuz.old), so that you can still boot it if the new kernel does not function as expected: earth:/usr/src/linux # cp /boot/vmlinuz /boot/vmlinuz.old earth:/usr/src/linux # cp arch/i386/boot/bzImage /boot/vmlinuz earth:/usr/src/linux # lilo The Makefile target make bzlilo performs these three steps, by the way, in one go. Now the compiled modules still need to be installed; by entering earth:/usr/src/linux # make modules install you can have these copied to the correct target directories in /lib/ modules/. To accomplish this, enter an additional label to /etc/lilo.conf , such as old-linux. Select /boot/vmlinuz.old as the boot image, or ker- nel to boot, and copy the old kernel to /boot/vmlinuz.old. This will allow you to boot the old kernel if the new one happens to fail, by entering old-linux at the kernel boot: prompt. This is thoroughly described in Chapter 4 page 103. When you have adapted /etc/lilo.conf to your needs, you can enter: earth:/usr/src/linux # lilo If you boot Linux via DOS using linux.bat (loadlin), you have to copy the kernel to /dosc/loadlin/bzimage (or to the directory where you have installed loadlin) for it to become active at the next boot. Furthermore, the file /System.map contains kernel symbols which are needed by the modules to launch kernel functions correctly. This file depends on the current kernel. Therefore, you should copy /usr/src/linux/ System.map2 to the root directory (/). If you create your kernel using make zlilo, this is done for you automatically. 2 This file is created every time you create a new kernel. 322 13.7. Creating a Boot Disk If you get an error message like "System.map does not match current kernel", then probably System.map has not been copied. 13.7 Creating a Boot Disk If you want to create a boot disk with the new kernel, you can use the follow- ing command: earth:/usr/src/linux # make bzdisk 13.8 Cleaning Your Hard Drive After Compilation If you are low on hard disk space, you can regain some of the hard drive space used during compilation, with: earth: # cd /usr/src/linux earth:/usr/src/linux # make clean If there is plenty of space and you plan to compile a new kernel from the same sources, you might skip the last step. A new compilation will then be faster, as only those parts of the system which must change based on your choices are re-compiled. 323 13. The Kernel 324