Certification Objective 5.05: Kernel Sources

 < Day Day Up > 



One of the strengths of Linux is the ease with which you can customize your kernel to precisely meet your needs. But before you can start this process, you need the Linux kernel source code.

While references to recompiling the kernel have been removed from the Red Hat exam requirements, you may still need to find kernel modules and configuration files, which I cover in this section.

Exam Watch 

Fortunately, the Red Hat exams no longer specify requirements to recompile the Linux kernel. Nevertheless, it is a very important skill for any Linux administrator.

The Kernel Source Tree and Documentation

Once installed, you can easily access the kernel source code through the /usr/src/linux-2.4 directory. Installation procedures are addressed in the following sections. Once the source code is installed, the /usr/src directory should look similar to the following:

# ls -l /usr/src/ total 12 drwxr-xr-x   2 root  root  4096 Jan 24  2003 debug  lrwxrwxrwx   1 root  root    17 Oct 23 16:12 linux-2.4 -> linux-2.4.21-4.EL drwxr-xr-x  16 root  root  4096 Nov  7 15:56 linux-2.4.21-4.EL drwxr-xr-x   8 root  root  4096 Nov  9 12:13 redhat

In this case, the physical directory is /usr/src/linux-2.4.21-4.EL, and there is a soft link called linux-2.4 that points to this directory.

Periodically, you may wish to upgrade your kernel. If you use Red Hat sources, the new RPM packages should automatically update the symbolic link from /usr/src/linux-2.4 to the real directory with the new kernel's source code (for example, sym-link it to linux-2.4.21-4.1.EL). If necessary, you could perform the same action with the following command:

# ln -s linux-2.4.21-4.1.EL linux-2.4

The /usr/src/linux-2.4 directory on my RHEL 3 computer includes the following files and directories:

arch             Documentation   kernel        README configs          drivers         lib           REPORTING-BUGS COPYING          fs              MAINTAINERS   Rules.make COPYING.modules  include         MAKEFILE      scripts CREDITS          init            mm            tmp_include_depends crypto           ipc             net

Begin your study of the current kernel with the README file. While the instructions in this chapter work with the current configuration of RHEL 3 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 you really want to see how TCP/IP works). 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.

The Kernel RPMs

If you don't see the directories mentioned in the preceding section, then you haven't installed your Linux kernel's source code. There are two ways to install the source code for your RHEL 3 system. You could access the Red Hat RPMs from CD or a network source and install the kernel RPM. Alternatively, you could install the packages through the redhat-config-packages utility. The following example is based on an installation from the appropriate Red Hat Installation CD:

# mount /mnt/cdrom # rpm -Uvh /mnt/cdrom/RedHat/RPMS/kernel-source-*

Depending on the packages you've specified when you installed RHEL 3, this may be all you need. However, this command may bring up some error messages similar to the following:

error: Failed dependencies:         gcc >= 2.96-98 is needed by kernel-source-2.4.21-4.EL

which suggests that you need to install some other RPM packages, as described in the next section.

Required RPMs

In order to build a kernel from the source code, you need to ensure you have all the RPMs necessary, not only for the kernel, but also for the tools needed to build the kernel. You can check your system to ensure you have the RPM packages described in Table 5-3. Many of these packages have a number of other dependencies.

Table 5-3: Kernel Source RPMs

Package

Description

kernel-source-*

Kernel source files

glibc-kernheaders-*

Kernel header files

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

tk-*

TK X Window widgets-required for xconfig screen

If not, mount the appropriate Red Hat installation CDs or network installation source and install the needed packages with the rpm -Uvh packagename command. If the revision associated with your package and architecture are different, revise the package names accordingly.

The packages shown in Table 5-3 end with an * because version numbers do change frequently. In any case, the objective is to install these packages. For example, in order to install the tk package from a mounted CD, all you need is the rpm -Uvh /mnt/cdrom/RedHat/RPMS/tk-* command.

However, you'll also need to install any related dependent packages. For example, the kernel-source-* RPM requires the appropriate GNU C Compiler, which is the gcc-* RPM.

On The Job 

Wildcards such as an * are often also known as globbing.

GUI Kernel Source Management

It can take time to load all of the RPMs required to compile and customize the Linux kernel. It can be difficult to remember to install every RPM. There is an alternative: the Red Hat Package Management utility. I'll show you how to use this tool to load the kernel source packages in Exercise 5-3.

Exercise 5-3: Loading the Kernel Source Graphically

start example

In this exercise, we'll install the source code and associated files for the Linux kernel using the Red Hat Package Management utility. I'll assume that you're using the same network source that you created in Chapter 2. This exercise assumes that network source is on a remote computer with an IP address of 192.168.30.4. Substitute the IP address (or if you have a DNS server for your LAN, the hostname) for your network source computer. You'll need to start from the Linux GUI.

  1. If you're not already in the Linux GUI, run the startx command.

  2. Open a command line interface. Right-click on the desktop, and click New Terminal in the pop-up menu that appears.

  3. At the command line interface, make a connection to the network source. I'm assuming that you have an active NFS connection, no firewall, and a local /mnt/inst directory. For the given source, run the following command (substitute your IP address or hostname, and preferred mount directory in this command):

    # mount -t nfs 192.168.30.4:/mnt/inst /mnt/inst
  4. Start the Package Management utility. Point to the mounted network source (without the --tree option, the Package Management utility works from the installation CDs):

    # redhat-config-packages --tree=/mnt/inst
  5. Select the Kernel Development package group for installation.

  6. Click Update. The Package Management utility computes the dependencies, adding RPMs to the list of packages to be installed.

  7. Once you see the Completed System Preparation window, click Continue.

  8. The Package Management utility starts installing the packages you need to examine the source code and recompile the Linux kernel.

  9. When installation is complete, click OK.

Click Quit to exit from the Package Management utility.

end example

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 properly install it. For our example, we will assume you downloaded linux-2.4.22.tar.gz into the /usr/src/ directory.

# cd /usr/src # mkdir linux-2.4.22 # rm linux-2.4 # tar xzvf linux-2.4.22.tar.gz # ln -s linux-2.4.22 linux-2.4 

Here we manually created a new directory for the kernel, removed the old link, and then uncompressed the tar.gz file. Then you can link linux-2.4 to the new directory created when you uncompress the tar.gz file.

On The Job 

Compressed tar files are shown in tar.gz format; they are also known as 'tarballs.'



 < Day Day Up > 



RCHE Red Hat Certified Engineer Linux Study Guide[c] Exam (Rh302)
RCHE Red Hat Certified Engineer Linux Study Guide[c] Exam (Rh302)
ISBN: 71765654
EAN: N/A
Year: 2003
Pages: 194

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