Certification Objective 8.03-Kernel Sources


One of the strengths of Linux is the ease with which the kernel can be customized to meet your precise needs. But before starting this process, you need the Linux kernel source code. Kernel modules and associated configuration files are covered in this section.

If you choose to recompile the Linux kernel, you'll need several GB of free space available in the partition or volume that contains the /usr directory.

image from book
Exam Watch

While the Red Hat Exam Prep guide no longer includes references to recompiling the kernel, you may still need to find kernel modules and configuration files. And I would not be surprised to see a requirement to recompile the kernel return in future RHCE exams.

image from book

The Kernel Source Tree and Documentation

When you install the generic kernel source code, it's normally installed in (or linked to) the /usr/src/linux directory. If you install the source code from a Red Hat/Fedora source RPM, the code gets installed in the /usr/src/redhat/BUILD/kernel-2.6.18/ linux-2.6.18.i386/ subdirectory. It can be helpful to link that directory to /usr/src/ linux. Once linked, the /usr/src directory should look similar to the following:

 # ls -l /usr/src/ total 20 drwxr-xr-x   3 root  root  4096 Mar 14 09:32 kernels lrwxrwxrwx   1 root  root    54 Mar 14 14:44 linux ->        /usr/src/redhat/BUILD/kernel-2.6.18/linux-2.6.18.i386/ drwxr-xr-x   7 root  root  4096 Mar 14 09:37 redhat 

In this case, the actual directory is /usr/src/redhat/BUILD/kernel-2.6.18/linux-2.6.18 .i386/, and there is a soft link from /usr/src/linux that points to this directory. I created this link with the following command:

 # ln -s /usr/src/redhat/BUILD/kernel-2.6.18/linux-2.6.18.i386/ /usr/src/linux 

The /usr/src/linux directory on my RHEL 5 system includes the following files and directories:

 arch     Documentation    ipc          mm               sound block    drivers          Kbuild       net              usr configs  fs               kernel       README COPYING  hdrwarnings.txt  lib          REPORTING-BUGS CREDITS  include          MAINTAINERS  scripts crypto   init             Makefile     security 

Begin your study of the current kernel with the README file. While the instructions in this chapter work with the current configuration of RHEL 5 on my computer, details can change from kernel to kernel. Also, examine the Documentation directory. It contains everything you need, from information on setting up symmetrical multiprocessors to serial consoles.

The other directories mainly contain source code, and you probably won't need to spend time examining those files (unless, of course, you are a developer). There is also a hidden file, .config, that may be present in this directory. I'll describe this file in more detail later in this chapter.

For the rest of the chapter, I'll refer to the source code directory as the directory with source code files, which could be /usr/src/redhat/BUILD/linux-2.6.18/kernel-2.6.18.`uname -m`, or if you've linked it as suggested, /usr/src/linux.

The Kernel RPMs

If you don't see the directories mentioned in the preceding section, then you haven't installed the Linux kernel source code. There are three ways to install the source code. You could access the kernel source RPMs from appropriate download media, directly as a package from the RHN or repository associated with your rebuild distribution, or even from the public ftp.redhat.com server. Remember, in contrast to the past, there is no unique binary kernel-source RPM; you'll need the kernel-`uname -r`.src.rpm package.

On the Job 

Red Hat more than complies with the GPL by posting the source code for its RHEL 5 packages at ftp.redhat.com. You can find them with .src.rpm file name extensions.

On the Job 

Depending on the kernel source, and the actions you take, this process could easily take 3GB of space or more.

When you download the kernel src.rpm package, make sure it corresponds to the current kernel version (or the one you want to compile). Then take the following step to unload the source RPM:

 # rpm -ivh kernel-`uname -r`.src.rpm 

You may get warning messages related to users and groups that do not exist. As long as ownership is assigned to the root user, these are of no concern.

Next, navigate to the /usr/src/redhat/SPECS directory. You'll see a kernel-2.6.spec file. Assuming you've installed the rpm-build package, you can now build the source code with the following command. The `uname -m` in the command uses the architecture for the current system:

 # cd /usr/src/redhat/SPECS # rpmbuild -bp --target=`uname -m` kernel-2.6.spec 

This command takes a few minutes to load the source code into the /usr/src/redhat/ BUILD/kernel-2.6.18/linux-2.6.18.`uname -m`/ directory. It also loads the "vanilla" version of the given kernel in the /usr/src/redhat/BUILD/kernel-2.6.18/vanilla/ directory.

Sometimes the unpacking stalls with an error like:

 gpg: WARNING: unsafe permissions on homedir `. .+++++++++++++++...... Not enough random bytes available. Please do some other work to give the OS a chance to collect more entropy! (Need 258 more bytes) 

In this case, I opened a second console and ran the /etc/cron.daily/mlocate script. You don't have to run the same script; you just need to create the equivalent amount of activity to help Linux complete the unpacking process. Sometimes a few df and ls commands are sufficient.

Required Kernel Customization RPMs

To build a kernel from the source code, you need the RPMs not only for the kernel, but also for the tools needed to build the kernel (as well as dependencies). You can check your system to ensure you have the RPM packages described in Table 8-2. Many of these packages have a number of other dependencies, so it's best to use the yum command to install them from associated repositories or the RHN.

Table 8-2: Kernel Configuration RPMs

Package

Description

glibc-headers

Kernel header files (formerly glibc-kernheaders)

glibc-devel

Required for C libraries

cpp

C language preprocessor

ncurses

Required for menuconfig screen

ncurses-devel

Development libraries for ncurses

binutils

Required binary utilities

gcc

C language compiler

tcl

TCL scripting language-required for xconfig screen

gtk2-devel

TK X Window widgets-required for xconfig screen

qt-devel

QT development libraries required for xconfig screen; requires many additional packages to satisfy dependencies (a good reason to use yum)

glib2-devel

Glib2 development header files required for gconfig screen

libglade2-devel

Libglade2 libraries required for gconfig screen; requires several additional packages to satisfy dependencies

The objective is to install these packages with dependencies; for example, to install the gtk2-devel package with dependencies from the RHN or a repository, all you need is the yum install gtk2-devel command.

The Linux Kernel Tar File

Alternatively, you can download the newest kernel from the Linux kernel home page at www.kernel.org. The version numbers are discussed in the next section. Once you have downloaded the kernel source, you will need to install it properly. This example assumes you downloaded linux-2.6.22.tar.gz into the /usr/src/ directory.

 # cd /usr/src # tar xzvf linux-2.6.22.tar.gz # ln -s linux-2.6.22 linux 

These commands navigate to the /usr/src directory, uncompress the tarball, which creates a linux-2.6.22/ subdirectory, and then link it to the linux/ subdirectory.

On the Job 

Compressed tar files are shown in .tar.gz or .tgz format; they are also known as "tarballs." Some compressed tarballs are compressed in .bz2 format; to uncompress and unpack them, you'd apply the tar xjvf (instead of the tar xzvf) command to the tarball.



RHCE Red Hat Certified Engineer Linux Study Guide (Exam RH302)
Linux Patch Management: Keeping Linux Systems Up To Date
ISBN: 0132366754
EAN: 2147483647
Year: 2004
Pages: 227
Authors: Michael Jang

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