2. Fedora/RHEL comes with a prebuilt kernel that simplifies the installation process.
You can add the same parameters you use on the boot command line to
/boot/grub/grub.conf or to its symbolic link, /etc/grub.conf. For example, acpi=off
prevents acpid (the advanced configuration and power interface daemon) from
starting.
3. sysctl The sysctl utility can modify kernel parameters while the system is running. This
utility takes advantage of the facilities of /proc/sys, which defines the parameters
that sysctl can modify.
The command sysctl –a displays a complete list of sysctl parameters. An example
of displaying and changing the domainname kernel parameter follows. The double
quotation marks are not required in this example, but you must quote any characters
that would otherwise be interpreted by the shell. You must work with root
privileges when you change a parameter.
5. Downloading, Installing, and Prepping
the Kernel Source Code
Prerequisites
Install the following packages:
• rpmdevtools
• yum-utils (installed with the default system)
• ncurses-devel (used to configure the kernel using make menuconfig)
• libglade2-devel (used to configure the kernel using make gconfig)
6. Compiling a kernel takes a lot of disk space
When you compile a default kernel, it occupies approximately 3.5 gigabytes.
$ rpmdev-setuptree
$ ls rpmbuild
BUILD RPMS SOURCES SPECS SRPMS
7. After you compile the kernel, the five directories rpmdev-setuptree creates will hold
files as follows: BUILD holds the results of compiling the kernel, RPMS holds compiled
RPM files, SOURCES holds source and patch files, SPECS holds the kernel
specification file, and SRPMS holds source RPM files, if any.
You do not need to—nor should you—work as a user with root privileges for any portion of
configuring or building the kernel except for installing software packages and installing the
kernel (the last step). The kernel README file says, “Don’t take the name of root in vain.”
The sections on building, customizing, and installing the kernel use su –c when it is necessary
to work with root privileges.
8. Fedora only: The easiest way to download the updated kernel source code for the
most recently released version of the Fedora kernel is to use yumdownloader. Work in
and download kernel source code RPM file to your home directory:
$ cd
$ yumdownloader --source kernel
Loaded plugins: langpacks, presto, refresh-packagekit
Enabling updates-testing-source repository
Enabling fedora-source repository
kernel-2.6.38.2-9.fc15.src.rpm | 72 MB 02:48
9. The download.fedora.redhat.com site holds the kernel source code for other Fedora releases.
RHEL RHEL only: To download the source code for a RHEL kernel, point a browser or FTP client at
ftp://ftp.redhat.com/pub/redhat/linux/enterprise and select the version of RHEL you want,
following the links until you get to the SRPMS directory. For the RHEL 6 server kernel, go to
ftp://ftp.redhat.com/pub/redhat/linux/enterprise/6Server/en/os/SRPMS From the SRPMS page,
search for or scroll down until you find the files named kernel*src.rpm. Click and download the
RPM file for the kernel source code. Typically you will want to download the most recent
version. It will have a name similar to kernel-2.6.32-71.18.1.el6.src.rpm. The src indicates the
package contains source files. Alternatively
10. Installing the Source Code
yum-builddep With the kernel source code RPM package file in your home directory, run
yumbuilddep to download and install the packages needed to build the source code package
(dependencies). Because you are installing packages, you must work with root privileges.
Replace sam and 2.6.35.11-83.fc14 in the following example with your username and the name
of the kernel you are using to specify the location of the RPM file on the system.
11. $ su -c 'yum-builddep ~sam/kernel-2.6.38.2-9.fc15.src.rpm'
password:
Loaded plugins: langpacks, presto, refresh-packagekit
Adding en_US to language list
Getting requirements for kernel-2.6.38.2-9.fc15.src
...
Install 29 Package(s)
Total download size: 26 M
Installed size: 77 M
Is this ok [y/N]: y
...
Complete!
12. Finally, working from your home directory as a nonprivileged user, use rpm to install the kernel source
code in the rpmbuild directory hierarchy in your home directory:
$ rpm -Uvh kernel-2.6.38.2-9.fc15.src.rpm
1:kernel warning: user mockbuild does not exist - using root
warning: group mockbuild does not exist - using root
warning: user mockbuild does not exist - using root
...
1:kernel ########################################### [100%]
You can ignore errors, such as those shown above, about groups and users that do
not exist.
13. Prepping the Source Code
The final step before you can work with the source code is to prep it. Prepping unpacks
compressed files and applies patches. The following rpmbuild command uses the –bp option to
prep the source code:
$ cd /home/sam/rpmbuild/SPECS
$ rpmbuild -bp --target $(arch) kernel.spec
Building target platforms: i686
Building for target i686
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.SJXxg1
+ umask 022
+ cd /home/sam/rpmbuild/BUILD
...
If rpmbuild cannot find a package it needs to prep the code, it displays a message
such as the following:
14. error: Failed build dependencies:
elfutils-libelf-devel is needed by kernel-2.6.32-71.18.1.el6.i686
zlib-devel is needed by kernel-2.6.32-71.18.1.el6.i686
binutils-devel is needed by kernel-2.6.32-71.18.1.el6.i686
In this case, install the needed packages (you might have to install different packages
than those in the example):
$ su -c 'yum install elfutils-libelf-devel zlib-devel binutils-devel'
After you install the packages, give the preceding rpmbuild command again. With the
kernel source code installed and prepped on the local system, you can configure,
compile, and install it.
15. Configuring and Compiling the Linux
Kernel
Labeling the Kernel
To prevent overwriting existing kernel files and to identify various compilations of
the kernel, you can change the buildid variable in the kernel.spec file. This variable
is initially set to .local.
Whatever value you assign to this variable is placed at the end of the kernel name and release
number to identify the kernel. You can make note of patches applied to the kernel in this string
to help people track down problems later on. Use cd to change directories to /rpmbuild/SPECS,
edit kernel.spec, and change local in the line
16. #% define buildid .local
to a value that identifies the kernel you are building. You must also remove the
leading hash mark (#), the SPACE following the hash mark, and the SPACE between %
and define:
%define buildid .sam1104181000
17. .config: Configures the Kernel
The .config file in the ~/rpmbuild/BUILD/kernel*/linux* directory controls which
features the new kernel will support and how it will support them. The next section
provides instructions for replacing an existing custom kernel. “Customizing a Kernel”
on page 590 explains how to create a default version of the .config file if it does not
exist and how to edit the file if it does exist.
18. Replacing a Custom Kernel
If you have already configured a custom kernel, you might want to replace it with a
similarly configured, newer kernel. Each kernel potentially has new configuration
options, however—which explains why it is poor practice to use an old .config file for
compiling a new kernel. This section explains how to upgrade an existing .config file
so it includes options that are new to the new kernel and maintains the existing configuration
for the old options.
19. Work in the ~/rpmbuild/BUILD/kernel*/linux* directory. The system keeps a
copy of the configuration file for the kernel the local system is running in /boot. The
following command copies this file to .config in the working directory:
$ pwd
/home/sam/rpmbuild/BUILD/kernel-2.6.38.fc15/linux-2.6.38.i686
$ cp /boot/config-$(uname -r) .config
20. Next give the command make oldconfig to patch the .config file with options from
the new kernel that are not present in the old kernel. This command displays each
kernel option that is the same in the new and old kernels and automatically sets the
state of the option in the new kernel the same way it was set in the old kernel. It stops
when it finds an option that appears in the new kernel but not in the old kernel. It
21. then displays a prompt, which is similar to [N/y/?] (NEW), showing possible
responses and indicating this option is new. The prompt shows the default response as
an uppercase letter; you can type this letter (uppercase or lowercase) and press RETURN,
or just ress RETURN to select this response. In the example, the Tickless System option
is new, and the default response is Y for yes, include the option in the new kernel. To
select a nondefault response (n means no, do not include the option, and m means
include the option as a module), you must type the letter and press RETURN. Enter ? followed
by RETURN to display more information about the option.
22. Customizing a Kernel
The ~/rpmbuild/BUILD/kernel*/linux* directory and the configs subdirectory
provide sample configuration files for various processors, multiple processors, and
configurations. You might want to look at these files before you get started or use
one of them as your starting point. To use one of these files, copy it to .config.
You can use one of three standard commands to build the .config file that configures
a Linux kernel:
25. If a .config file does not exist in the working directory, each of these commands
except the first sets up a .config file that matches the kernel the local system is
running and then allows you to modify that configuration. The commands can set
up this .config file only if the configuration file for the locally running kernel is at
/boot/config-$(uname –r). See the preceding section if you want to build a new
kernel with a configuration similar to that of an existing kernel.
26. The make config command is the simplest of the three commands, uses a textual
interface, and does not require additional software. It is, however, the most unforgiving
and hardest to use of the configuration interfaces. The make menuconfig
command uses a pseudographical interface and also displays a textual interface.
The make gconfig command uses GTK+ (www.gtk.org) and displays a graphical
interface.
27. Each command asks the same questions and produces the same result, given the same
responses. The first and second commands work in character-based environments; the
third command works in graphical environments. For many administrators working
with a GUI, the third method is the easiest to use.
28. The make gconfig command displays the Linux Kernel Configuration window,
which you can view in three configurations: single, split, or full view. Choose a
view by clicking one of the three icons to the right of the save icon on the toolbar.
29.
30. At the far right of all views are four columns labeled N, M, Y, and Value. An N
appears in the N column if the feature on that line is not being used. An M in the M
column means the feature is included as a module. A Y in the Y column means the
feature is compiled in the kernel. An underscore in any of these columns means that
the value that would appear in that column is valid for the feature (e.g., an underscore
in the column labeled M means that that feature can be included as a module,
although it is not included as a module). The Value column holds the value of the
feature (N, M, or Y).
31. In any view, you can double-click the check boxes and radio buttons next to the features
to select or deselect that feature. An empty check box/radio button indicates
the feature is disabled, a tick indicates it is to be compiled in the kernel, and a minus
sign means it is to be compiled as a module. With a choice highlighted, you can also
press M for module, N for not included, and Y for compiled into the kernel. Select
Menubar: OptionsShow All Options to display all options and features.
32. Go through the options and mark the features as you would like them to be configured
in the new kernel. At any time during the configuration process, you can
store the currently defined configuration to a file, load a configuration from a file,
or exit with or without saving your changes. The selections to do so are available
in Menubar: File. When you are done, select Menubar: FileSave and close the
window.
33. Cleaning the Source Tree
After generating a .config file, but before compiling or recompiling the kernel, purge
the source tree of all potentially stale *.o files using the following command:
$ make clean
CLEAN arch/x86/boot/compressed
CLEAN arch/x86/boot
CLEAN /home/sam/rpmbuild/BUILD/kernel-2.6.38.fc15/linux-2.6.38.i686
CLEAN arch/x86/kernel/acpi/realmode
CLEAN arch/x86/kernel/cpu
35. Copying the Configuration File
Before compiling the kernel, you must copy the .config file you want to use to the
directory you will compile the kernel in. This file must have a name that corresponds
to the kernel in use on the local system (e.g., config-i686-generic):
$ cp .config ~/rpmbuild/SOURCES/config-$(arch)-generic
36. Compiling a Kernel Image File and
Loadable Modules
The next command compiles the kernel and modules. Compiling the kernel will
take upwards of several hours, depending on the power of the system you are using
$ pwd
/home/sam/rpmbuild/SPECS
$ rpmbuild -bb --target $(arch) kernel.spec
Building target platforms: i686
Building for target i686
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.JoAIFx
38. Using Loadable Kernel Modules
A loadable kernel module (sometimes called a module or loadable module)
is an object file—part of the kernel—that is linked into the kernel at runtime.
Modules can be inserted into and removed from a running kernel at almost any time
(except when a module is being used). This ability gives the kernel the flexibility to be
as small as possible at any given time. Modules are a good way to code some kernel
features, including drivers that are not used continually (such as a tape driver). Module
filenames end in .ko and are stored in subdirectories in /lib/modules.
39. Installing the Kernel, Modules, and
Associated Files
The next step, which you must execute with root privileges, is to copy the compiled
kernel, modules, and associated files to the appropriate directories—usually /boot
and a subdirectory of /lib/modules. When you have a partition mounted at /boot,
the files are kept in the root of this partition (/boot). Because you have created an
RPM package, installing these files is quite easy. The following command installs
the new kernel files from the rpmbuild directory hierarchy in Sam’s home directory
into the proper directories:
40. $ su -c 'rpm -ivh --force ~sam/rpmbuild/RPMS/i686/kernel-2.6.38.2-
9.sam1104181000.fc15.i686.rpm'
Password:
Preparing... ########################################### [100%]
1:kernel ########################################### [100%]
Installing the kernel in this manner updates the grub.conf
41. Reboot Reboot the system by clicking your name at the upper-right corner of the screen
and selecting Shut Down and then selecting Restart. If you are working at the
console, press CONTROL-ALT-DEL. You can also give a reboot command from the console,
a character-based terminal, or a terminal emulator. When the system is
rebooted, you can use uname to verify the new kernel is loaded:
$ uname -r
2.6.38.2-9.sam1104181000.fc15.i686
42. GRUB: The Linux Boot Loader
MBR A boot loader is a very small program that the bootstrap process uses as it brings a
computer from off or reset to a fully functional state. The boot loader frequently resides on the
starting sectors of a hard disk called the MBR (master boot record).
The BIOS on the system’s motherboard, gains control of a system when you turn on or reset the
computer. After testing the hardware, the BIOS transfers control to the MBR, which usually
passes control to the partition boot record.
43. LBA addressing mode and the /boot partition
All newer hard disks support LBA (logical block addressing) mode. LBA permits the /boot
directory to appear anywhere on the hard disk. For LBA to work, it must be supported by the
hard disk, the BIOS, and the operating system (GRUB in the case of Linux). Although GRUB
supports LBA addressing mode, some BIOSes do not.
For this reason, it is a good idea to place the /boot directory in its own partition located near the
beginning of the hard disk. With this setup, the root (/) filesystem can be anywhere on any hard
drive that Linux can access regardless of LBA support.
In some instances, without a separate /boot partition, the system might boot at first but then
fail as you update the kernel and the kernel files move further from the beginning of the disk.
44. LVM Systems with LVM require a separate boot partition that is not an LV
GRUB GRUB stands for Grand Unified Boot loader. Although GRUB 2 has been released,
Fedora/RHEL use GRUB, which is sometimes referred to as GRUB legacy
The GRUB loader can recognize various types of filesystems and kernel executable formats,
allowing it to load an arbitrary operating system. When you boot the system, GRUB can display
a menu of choices that is generated by the /boot/grub/grub.conf file (next page). At
this point you can modify a menu selection, choose which operating system or kernel
to boot, or do nothing and allow GRUB to boot the default system.
45. Configuring GRUB
The /boot/grub/grub.conf file, with its link at /etc/grub.conf, is the default GRUB configuration
file. The grub.conf file in the following example is from a system that had its kernel replaced
(there are two versions of vmlinuz and initrd). The system has a separate boot partition so that
all kernel and initrd (for systems using loadable modules;)
46. The file starts with comments that Anaconda, the graphical installer, puts there, followed by
three assignments and hiddenmenu. The default is the section number of the default boot
specification. This numbering starts with 0. The example includes two boot specifications: The
first, numbered 0, is for the 2.6.38.2-9.sam1104181000.fc15.i686 kernel; the second, numbered
1, is for the 2.6.38.2-9.fc15.i686 kernel. The timeout is the number of seconds that grub
waits after it has prompted for a boot specification before it boots the system with the default
boot specification. The splashimage is the grub menu interface background GRUB displays when
the system boots. When you specify hiddenmenu, grub boots the default entry and does not
display the menu interface unless you press ESCAPE while the system is booting.
47. # cat /boot/grub/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/mapper/vg_guava-lv_root
# initrd /initrd-[generic-]version.img
51. grub-install: Installs the MBR and GRUB Files
You can specify the device name as a GRUB device name (e.g.,
hd0) or a device filename (e.g., /dev/sda). The following example shows grub-install
installing files in the default location (/boot/grub) and the MBR on device /dev/sda:
52. # grub-install /dev/sda
Installation finished. No error reported.
This is the contents of the device map /boot/grub/device.map.
Check if this is correct or not. If any of the lines is incorrect,
fix it and re-run the script 'grub-install'.
# this device map was
53. dmesg: Displays Kernel Messages
The dmesg utility displays the kernel-ring buffer, where the kernel stores messages.
When the system boots, the kernel fills this buffer with messages related to hardware
and module initialization. Messages in the kernel-ring buffer are often useful
for diagnosing system problems.
When you run dmesg, it displays a lot of information. It is frequently easier to pipe
the output of dmesg through less or grep to find what you are looking for. For
example, if you find that your hard disks are performing poorly, you can use dmesg
to check whether they are running in DMA mode:
54. $ dmesg | grep DMA
...
[ 1.398073] ata1: PATA max UDMA/33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14
[ 1.398078] ata2: PATA max UDMA/33 cmd 0x170 ctl 0x376 bmdma 0x10c8 irq 15
...
The preceding lines tell you which mode each ATA device is operating in. If you are
having problems with the Ethernet connection, search the dmesg buffer for eth:
55. $ dmesg | grep eth
[ 5.060499] pcnet32: eth0: registered as PCnet/PCI II 79C970A
[ 84.527758] pcnet32 0000:02:01.0: eth0: link up
[ 95.458834] eth0: no IPv6 routers present
If everything is working properly, dmesg displays the hardware configuration
information for each network interface.
dmesg log Boot messages are also logged to /var/log/dmesg. This file is overwritten each time
the system is booted, but the previous version of the file is saved as dmesg.old. This
log is a good place to start when diagnosing faults. If you have configured a system
service incorrectly, this log quickly fills with errors.
56. You can build a Linux kernel from the source code. Sometimes you do not need to build a kernel;
instead, you can change many aspects of the kernel by using boot options in /etc/grub.conf. You
can dynamically change options by modifying /etc/sysctl.conf. Before you can build a Linux
kernel, you must download the kernel source files to the local system. After you have
downloaded the source files, you need to install and prep the source code, configure and
compile the kernel and the loadable modules, and install the kernel and loadable modules. The
GRUB boot loader is a small program that controls the process of bringing the system up. You
must configure the boot loader so that it recognizes the new kernel. The dmesg utility displays
the kernel-ring buffer, where the kernel stores messages. You can use this utility to help
diagnose boot-time problems.