Preparing the Source Code


Before you can start rebuilding the kernel, you must locate, install, and clean the source code. If you want to use code that has not been customized (patched) by Red Hat, visit kernel.org.

Locating the Source Code

When you have the kernel source on the system, the /usr/src directory will look similar to the following:

$ ls -l /usr/src total 20 lrwxrwxrwx  1 root root   17 Jan 27 18:25 linux -> linux-2.6.15.i686 drwxr-xr-x 21 root root 4096 Jan 27 22:12 linux-2.6.15.i686 drwxr-xr-x  8 root root 4096 Jan 27 18:20 redhat


In the preceding example, the name linux-2.6.15.i686 means that the directory contains version 2.6 of the Linux kernel, release 15, and is set up for a Pentium Pro (P6 core) architecture.

The /usr/src directory is the traditional location for the kernel source. Also check whether the kernel code appears in /usr/src/redhat, as that is where it is installed by default. If it is there, see step 4 on page 528.

If the source code is present on the system, skip to "Cleaning the Source Tree" on page 529.

Installing the Source Code

When the source is not present on the system, you need to install it.

FEDORA


Before you start, install rpmbuild. You will need this program to unpack and apply patches to the source files. The rpmbuild utility is part of the fedora-rpmdevtools package. You can use pirut (page 483) to install this package (the package is an optional package in Developer Tools) or you can issue the following yum command.

Install rpmbuild


# yum install fedora-rpmdevtools


With rpmbuild installed, follow these steps to install the kernel source code:

1.

To download the source code for the Fedora Core 5 kernel, point a browser at

download.fedora.redhat.com/pub/fedora/linux/core/5/SRPMS


If you want the source code for a version other than the Fedora Core 5 kernel, substitute the release number of the kernel you want for 5 in the preceding URL.

Download the rpm file for the kernel source code. It will have a name similar to kernel-2.6.15-1.1955_FC5.src.rpm. The src indicates that the package contains source files. Firefox with its default setup will download the file to ~/Desktop.

Alternatively, you can use yumdownloader to download the kernel for the local system. See page 482 for instructions.

2.

Working as root, use rpm to install the package you just downloaded. You need either to cd to the directory that holds the rpm file or to specify the pathname of the rpm file in the following command:

# rpm -Uvh kernel*rpm


3.

The preceding command installs the kernel specification file as /usr/src/redhat/SPECS/kernel-2.6.spec. This file holds the instructions that rpmbuild uses to unpack the kernel source files and apply patches to those files. Change directories to /usr/src/redhat/SPECS and run rpmbuild:

# cd /usr/src/redhat/SPECS # rpmbuild -bp --target $(arch) kernel-2.6.spec


This command take a few minutes to run and generates a lot of output.

4.

Traditionally the source for the kernel that the system is running is kept in /usr/src/linux. The following commands move the source to the /usr/src directory and create a symbolic link to linux there. This example shows the names of the kernel directories as kernel-2.6.15 and linux-2.6.15.i686. The names on the system you are working on will be slightly different.

# cd /usr/src/redhat/BUILD/kernel-2.6.15 # ls Config.mk  linux-2.6.15.i686  vanilla  xen # mv linux-2.6.15.i686 /usr/src # cd /usr/src # ln -s /usr/src/linux-2.6.15.i686 /usr/src/linux


After you give these commands, the patched kernel source is located in /usr/src/linux. The rest of this chapter assumes that the kernel source is in this location.

RHEL


Installing the kernel source code on a RHEL system is similar to installing it on FEDORA. Review the preceding procedure as you read this section for a better understanding of what each step does.

Before you start, use up2date (page 494) to install two packages that you will need to install the kernel:

# up2date redhat-rpm-config rpm-build


Download the kernel source code:

# up2date --get-source kernel


Use rpm to install the kernel source code:

# rpm -ivh /var/spool/up2date/kernel*.src.rpm


After you install the code, unpack it and apply the patches:

# cd /usr/src/redhat/SPECS # rpmbuild -bp --target $(arch) kernel-2.6.spec


Finally, move the source tree to its classic location. See step 4, substituting the names of the kernel directories on the RHEL system for those in the example.

Tip: Now the working directory is /usr/src/linux

All commands in this section on building a kernel are given relative to the top-level directory that holds the kernel source. Traditionally this directory is /usr/src/linux. Make sure that this directory is your working directory before proceeding. If necessary, link the directory holding the kernel source in /usr/src to /usr/src/linux as explained in step 4.





A Practical Guide to Red Hat Linux
A Practical Guide to Red HatВ® LinuxВ®: Fedoraв„ў Core and Red Hat Enterprise Linux (3rd Edition)
ISBN: 0132280272
EAN: 2147483647
Year: 2006
Pages: 383

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