Customizing a Kernel

Customizing the kernel is a long process. In this section, you ll look at the basic steps. Later in the chapter, you ll go through the graphical configuration menu in detail. First, you ll edit the Makefile to label your new kernel. Then, once you ve cleaned up your source files, you ll save your current configuration.

Next , you ll customize your kernel, using what you ve learned earlier in this chapter. When you ve saved your new configuration, you ll organize dependencies and create a new kernel image.

At this point in the process, you will have made the changes you want to the kernel; activated the settings you need; included appropriate hardware as modules; minimized the size of the kernel by deactivating items that you don t need; and saved your changes. The next step will be to compile and create your new kernel.

Kernels vary. The steps you need to take may vary. The first thing you should do is read the README file in the /usr/src/linux- x directory for any major changes in procedure.

Preparing the Source

You may have downloaded a new kernel. Perhaps you just want to change some settings on the kernel that you re currently using. In either case, you need to prepare the source code.

Remember, the source code is located in the /usr/src/linux- x directory, where x stands for the linux- versionnumber of your kernel. Navigate to this directory. Read the following sections in sequence.

Tip  

It s important to follow these instructions in the right order when revising and recompiling your Linux kernel. If you have problems, refer to the Linux Kernel HOWTO at www.tldp.org .

The Makefile

Open the file named Makefile from the /usr/src/linux- x directory in your favorite text editor. The first four lines in this file should look similar to:

 VERSION = 2 PATCHLEVEL = 4 SUBLEVEL = 20 EXTRAVERSION =  something  

If you re new to Linux kernels, this may be confusing. The labels in the Makefile are not consistent with the standard kernel numbering format: PATCHLEVEL is the minor version revision level of the kernel, and SUBLEVEL is the patch revision level of the kernel.

EXTRAVERSION is what Linux adds to the end of the kernel files that you can transfer to the /boot directory at the end of this process. It also helps you identify your new kernel in a bootloader such as GRUB.

Change the EXTRAVERSION variable to something you ll recognize. For the purpose of this chapter, I m editing my Makefile with the following:

 EXTRAVERSION = sugaree 
Tip  

Be very careful with the EXTRAVERSION variable; an extra space after sugaree would create an error during the kernel module configuration process.

Saving the Current Kernel Configuration

If you ve never revised your kernel before, Red Hat already has your current kernel configuration on file. As described earlier, it s located in the /boot/config- x file. This is also true if you ve installed a different Red Hat Linux kernel from a "stock" kernel RPM.

If you ve recompiled your kernel before, your current configuration should be in the hidden file, .config , in the /usr/src/linux- x directory. Save it now. The step described in the next section deletes that file.

In either case, back up your current configuration. These files are small enough to fit on a regular floppy disk.

Cleaning the Source

Now that your Makefile is ready, it s time to clean the source code. If you aren t already there, navigate to the /usr/src/linux- x directory. The following command uses the Makefile script to clean files and directories that would interfere with compiling the kernel source code:

 # make mrproper 
Tip  

Each of the make commands in this chapter may run through thousands of lines of code. While some may take minutes, others may take hours, especially on slower computers. Be patient.

A Standard Starting Point

When you download a kernel from a non “Red Hat source such as ftp.kernel.org , you may have to adjust several hundred settings to match the current Red Hat configuration. That process can be painful.

Alternatively, you can set a Red Hat starting point for your kernel; some might call this a baseline configuration . There are four basic options for your baseline Linux kernel; each is mutually exclusive:

The saved .config file If you saved the .config file earlier, you can restore it to the /usr/src/linux- x directory.

The /boot/config-x file This file contains the configuration of your kernel when you installed it from an RPM, or when you installed Red Hat Linux. You can copy this to the /usr/src/ linux- x /.config file.

Your current configuration Use the make oldconfig command to set up your current configuration in the /usr/src/linux- x /.config file.

The appropriate file in /usr/src/linux-x/ configs The configs subdirectory includes a series of configuration files, customized for different CPUs. You can copy the file closest to your kernel to the /usr/src/linux- x /.config file.

Customizing the Configuration

You ve seen three menus that you can use to customize your kernel configuration: make config , make menuconfig , and make xconfig . Select one and make the desired changes to your kernel, using the techniques and criteria described earlier. Generally, you ll want to:

  • Use modules. Make sure they re enabled in the Loadable Module Support menu. The alternative is to use a monolithic kernel, which may be too big for your system.

  • Be sure to cite the correct CPU in the Processor Type And Features menu.

  • Remove unneeded devices and modules. This can minimize the size of your kernel and associated driver files. For example, if you re not planning to connect a Ham Radio to your Linux computer, you won t need the modules associated with Amateur Radio Support.

  • If in doubt, don t remove it. Assuming you re starting from a baseline or standard kernel configuration, many of the settings are interdependent. If you remove the wrong device, you might make this kernel unusable.

    Note  

    Previous kernels required symmetric multiprocessing (SMP) support, even for computers with one CPU. That is no longer required for the kernel included with Red Hat Linux 9.

When you ve made your changes, save your configuration. By default, the make tools save your settings to the .config file in the /usr/src/linux- x directory.

Creating Dependencies

Now you can force your source code to read your Linux kernel configuration. The following command resolves all dependencies. It takes the settings from your new .config file and uses them to customize your source code:

 # make dep 
Note  

The make dep process took 5 minutes on my 660MHz computer. Your experience depends in part on the speed of your CPU and the size of your kernel.

Making a Kernel Image

Now that the dependencies are satisfied, you re ready to make the kernel image. This process can take minutes or even all night, depending on the speed of your CPU. You want the image to be compressed so that you can fit it on a boot or rescue floppy disk. To create a compressed kernel image, run the following command:

 # make bzImage 

You ll see a very long series of messages. When this command is complete, watch for the following message:

 warning: kernel is too big for standalone boot from floppy 

If this is what you see, you probably can t use the mkbootdisk command from Chapter 11 to create a boot floppy. If you re motivated to make your kernel smaller, you may want to start the make xconfig process again and remove more settings.

Note  

The make bzImage process took 15 minutes on my 660MHz computer. Your experience depends in part on the speed of your CPU and the size of your kernel.

You may not need a customized boot disk. In many cases, you can use the Red Hat Linux installation boot disk in rescue mode to boot your system. For more information on the linux rescue process, see Chapter 11 .

Tip  

The Red Hat Linux installation boot disk in linux rescue mode may not rescue all systems. You might need a customized boot disk for your new kernel.

Make a note of the directory cited in the last message. You ll need it again in a moment. For now, assume you re recompiling kernel version 2.4.20-8:

 /usr/src/linux-2.4.20-8/arch/i386/boot 
Note  

If you re using a PC that does not use an Intel 32-bit CPU, the i386 in the directory may be different.

After Compiling

Now you can move your kernel to the /boot directory and update your bootloader. As we noted earlier, the new kernel is in the /usr/src/linux-2.4.20-8/arch/i386/boot directory. Copy it to the /boot directory, and name it vmlinuz-2.4.20sugaree .

You also need to create an Initial RAM disk. Based on the noted kernel version and value of EXTRAVERSION , you can do so with the following command:

 # mkinitrd /boot/initrd-2.4.20sugaree.img 2.4.20sugaree 

Building Modules

At this point, we ve assumed that you ve configured module support into your kernel. The next step is to make your modules. The first command organizes the modules that you ve configured in various /usr/src/linux- x subdirectories:

 # make modules 
Note  

The make modules process took 45 minutes on my 660MHz computer. As always, your experience depends in part on the speed of your CPU and the size of your kernel.

The next command organizes your modules in the /lib/modules/2.4.20-4 directory:

 # make modules_install 
Note  

The make modules_install process took 30 minutes on my 660MHz computer.

Tip  

If you see the when making multiple links, last argument must be a directory error message, check the EXTRAVERSION variable in the /usr/src/linux-x/Makefile . There may be an extra space at the end of that line.

Now you re ready to get to the nitty-gritty of customizing the kernel, based on one of three different configuration menus.

 


Mastering Red Hat Linux 9
Building Tablet PC Applications (Pro-Developer)
ISBN: 078214179X
EAN: 2147483647
Year: 2005
Pages: 220

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net