Custom Kernel

 

Custom Kernel


 

A.4.2. Useful Websites

 

Configuring the Boot Loader

Making sure the boot loader configuration file has been correctly modified is a crucial step. If the file is modified incorrectly, the system may not boot into Red Hat Linux. If this happens, boot the system with the boot diskette created earlier and try configuring the boot loader again.

In order to provide a redundant boot source to protect from a possible error in a new kernel, keep the original kernel available.

 

GRUB

If GRUB is the boot loader, the new-kernel-pkg script should have modified /boot/grub/grub.conf to include a section for the new kernel.

The default GRUB configuration file looks similar to the following:

 # NOTICE:  You have a /boot partition.  This means that
#          all kernel paths are relative to /boot/
default=0
timeout=30
splashimage=(hd0,0)/grub/splash.xpm.gz

title Red Hat Linux (2.4.20-2.47.1)
        root (hd0,0)
        kernel /vmlinuz-2.4.20-2.47.1 ro root=/dev/hda3
        initrd /initrd-2.4.20-2.47.1.img

If a separate /boot partition exists, the paths to the kernel and initrd image are relative to the /boot partition.

By default, Red Hat Linux uses Red Hat Linux and the kernel version in parentheses to differentiate between different kernels for GRUB to boot. In our example, the new /boot/grub/grub.conf file created by the new-kernel-pkg script would look like the following:

 # NOTICE:  You have a /boot partition.  This means that
#          all kernel paths are relative to /boot/
default=1
timeout=30
splashimage=(hd0,0)/grub/splash.xpm.gz

title Red Hat Linux (2.4.20-2.47.1custom)
        root (hd0,0)
        kernel /vmlinuz-2.4.20-2.47.1custom ro root=/dev/hda3
        initrd /initrd-2.4.20-2.47.1custom.img

title Red Hat Linux (2.4.20-2.47.1)
        root (hd0,0)
        kernel /vmlinuz-2.4.20-2.47.1 ro root=/dev/hda3
        initrd /initrd-2.4.20-2.47.1.img

Notice that the default boot entry is set to 1. The script does not change the default kernel to boot; it only adds a new section for the new kernel.

If the file is not modified correctly and no error messages were shown during the make install step, add the new section manually.

After rebooting, selecting the new kernel from the list, and seeing that the new kernel works, make the new kernel the default. Either place its section first or change the default entry number to the appropriate number (remember that it starts counting with 0). For GRUB, no commands need to be run after modifying the configuration file.

 

LILO

If LILO is the boot loader, the new-kernel-pkg script should have modified /boot/lilo.conf to include a section for the new kernel and run /sbin/lilo.

The default LILO configuration file looks similar to the following:

 prompt
timeout=50
default=linux
boot=/dev/hda
map=/boot/map
install=/boot/boot.b
message=/boot/message
lba32

image=/boot/vmlinuz-2.4.20-2.47.1
 label=linux
        initrd=initrd-2.4.20-2.47.1.img
 read-only
 append="root=LABEL=/"

The modified /etc/lilo.conf should look similar to the following:

 prompt
timeout=50
default=linux
boot=/dev/hda
map=/boot/map
install=/boot/boot.b
message=/boot/message
lba32
 
image=/boot/vmlinuz-2.4.20-2.47.1custom
        label=2.4.20-2.47.1custom
        initrd=initrd-2.4.20-2.47.1custom.img
        read-only
        append="root=LABEL=/" 
image=/boot/vmlinuz-2.4.20-2.47.1
       label=linux
       initrd=initrd-2.4.20-2.47.1.img
       read-only
       append="root=LABEL=/"

If the file is not modified correctly and no error messages were shown from the make install step, add the new section manually.

To activate the changes, run the command /sbin/lilo -v. If all goes well, the output should be similar to the following:

 LILO version 21.4-4, Copyright (C) 1992-1998 Werner Almesberger
'lba32' extensions Copyright (C) 1999,2000 John Coffman

Reading boot sector from /dev/hda
Merging with /boot/boot.b
Mapping message file /boot/message
Boot image: /boot/vmlinuz-2.4.20-2.47.1custom
Added 2.4.20-2.47.1custom *
Boot image: /boot/vmlinuz-2.4.20-2.47.1
Added linux
Writing boot sector.

Be sure the messages contains Writing boot sector. The * after linux means that the section labeled linux is the default kernel that LILO will boot.

From now on, when the system boots the the old and new entries are listed.

To boot the new kernel, select it and press [Enter].

Begin testing the new kernel by rebooting the computer and watching the messages to ensure the hardware is detected properly. If it is successful, change LILO to boot the new kernel by default by changing the label after default= in the configuration file and running the command lilo -v.

 

Making an initrd Image

An initrd image is needed to load a SCSI module at boot time or if the kernel was compiled with ext3 support as a module. To verify that a new initrd file was created, view the contents of the /boot directory and look for initrd-2.4.20-2.47.1custom.img, where 2.4.20-2.47.1custom is the name of the kernel just built.

If it does not exist, use the /sbin/mkinitrd shell script to create it:

 /sbin/mkinitrd /boot/initrd-2.4.20-2.47.1custom.img 2.4.20-2.47.1custom

In the above example, /boot/initrd-2.4.20-2.47.1custom.img is the file name of the new initrd image. 2.4.20-2.47.1custom is the kernel whose modules (from /lib/modules) should be used in the initrd image. This is not necessarily the same as the version number of the currently running kernel.

 

A.2. Building the Kernel

The instructions in this section apply to building a custom modularized kernel. To build a monolithic kernel instead, see Section A.3 Building a Monolithic Kernel for an explanation of the different aspects of building and installing a monolithic kernel.

This example uses 2.4.20-2.47.1 as the kernel version (the kernel version might differ). To determine the kernel version, type the command uname -r and replace 2.4.20-2.47.1 with the kernel version that is returned.

To build a custom kernel for the x86 architecture (perform all these steps as root):

  1. Open a shell prompt and change to the directory /usr/src/linux-2.4/. All commands from this point forward must be executed from this directory.

  2. It is important that kernel build starts with the source tree in a known condition. Therefore, it is recommended that the command make mrproper is issued first to remove any configuration files along with the remains of any previous builds that may be scattered around the source tree. If an existing configuration file already exists as the file /usr/src/linux-2.4/.config, back it up to a different directory before running this command and copy it back afterward.

  3. It is recommended that the configuration of the default Red Hat Linux kernel be used as a starting point. To do this, copy the configuration file for the system's architecture from the /usr/src/linux-2.4/configs/ directory to /usr/src/linux-2.4/.config. If the system has more than four gigabytes of memory, copy the file that contains the keyword bigmem.

  4. Next, customize the settings. If the X Window System is available, the recommended method is to use the command make xconfig to run the Linux Kernel Configuration.

    To use the graphical tool started with the make xconfig command, the tk package, which provides the wish command, must be installed.

    Figure A-1. Configuring Kernel Component Categories

    Select a category to configure by clicking on it. Within each category are components. Select y (yes), m (module), or n (no) beside the component to compile it into the kernel, compile it as a kernel module, or not compile it. To learn more about the component, click the Help button beside it.

    Click Main Menu to return to the categories list.

    After finishing the configuration, click the Save and Exit button in the main menu window to create the configuration file /usr/src/linux-2.4/.config and exit the Linux Kernel Configuration program.

    Even if no changes were made to any of the settings, running the make xconfig command (or one of the other methods for kernel configuration) is required before continuing.

    Other available methods for kernel configuration include:

    • make config — An interactive text program. Components are presented in a linear format and answered one at a time. This method does not require the X Window System and does not allow answers to be changed for previous questions.

    • make menuconfig — A text mode, menu driven program. Components are presented in a menu of categories; select the desired components in the same manner used in the text mode Red Hat Linux installation program. Toggle the tag corresponding to the item to be included: [*] (built-in), [ ] (exclude), <M> (module), or < > (module capable). This method does not require the X Window System.

    • make oldconfig — This is a non-interactive script that sets up the configuration file to contain the default settings. If the system is using the default Red Hat Linux kernel, it creates a configuration file for the kernel that shipped with Red Hat Linux for the architecture. This is useful for setting up the kernel to known working defaults and then turning off features not wanted.

    To use kmod and kernel modules answer Yes to kmod support and module version (CONFIG_MODVERSIONS) support during the configuration.

  5. After creating a /usr/src/linux-2.4/.config file, use the command make dep to set up the dependencies correctly.

  6. Use the command make clean to prepare the source tree for the build.

  7. It is recommended that the custom kernel have a modified version number so that the existing kernel is not overwritten. The method described here is the easiest to recover from in the event of a mishap. For other possibilities, details can be found at http://www.redhat.com/mirrors/LDP/HOWTO/Kernel-HOWTO.html or in the Makefile in /usr/src/linux-2.4.

    By default, /usr/src/linux-2.4/Makefile includes the word custom at the end of the line beginning with EXTRAVERSION. Appending the string allows the system to have the old working kernel and the new kernel (version 2.4.20-2.47.1custom) on the system at the same time.

    If the system contains more than one custom kernel, a good method is to append the date at the end (or another identifier).

  8. Build the kernel with make bzImage.

  9. Build any modules configured with make modules.

  10. Use the command make modules_install to install the kernel modules (even if nothing was actually built). Notice the underscore ( _) in the command. This installs the kernel modules into the directory path /lib/modules/<KERNELVERSION>/kernel/drivers (where KERNELVERSION is the version specified in the Makefile). In this example it would be /lib/modules/2.4.20-2.47.1custom/kernel/drivers/.

  11. Use make install to copy the new kernel and its associated files to the proper directories.

    In addition to installing the kernel files in the /boot directory, this command also executes the /sbin/new-kernel-pkg script that builds a new initrd image and adds new entries to the boot loader configuration file.

    If the system has a SCSI adapter and the SCSI driver was compiled as a module or if the kernel was built with ext3 support as a module (the default in Red Hat Linux), the initrd image is required.

  12. Even though the initrd image and boot loader modifications are made, verify that they were done correctly and be sure to use the custom kernel version instead of 2.4.20-2.47.1.

 

A.3. Building a Monolithic Kernel

To build a monolithic kernel, follow the same steps as building a modularized kernel, with a few exceptions.


 

Home