SlideShare a Scribd company logo
1 of 56
Building a Linux Kernel
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.
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.
$ sysctl kernel.domainname
kernel.domainname = tcorp.com
$ su -c 'sysctl -w kernel.domainname="example.com" '
kernel.domainname = example.com
$ sysctl kernel.domainname
kernel.domainname = example.com
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)
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
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.
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
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
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.
$ 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!
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.
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:
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.
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
#% 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
.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.
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.
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
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
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.
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:
$ make config
$ make menuconfig
$ make gconfig
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.
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.
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.
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.
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).
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: Options􀁄Show All Options to display all options and features.
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: File􀁄Save and close the
window.
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
...
CLEAN Documentation/watchdog/src
CLEAN .tmp_versions
CLEAN vmlinux System.map .tmp_kallsyms3.o .tmp_kallsyms3.S ...
This command ensures that make correctly applies any numbering scheme you use
when you compile the kernel.
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
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
+ umask 022
+ cd /home/sam/rpmbuild/BUILD
...
Wrote: /home/sam/rpmbuild/RPMS/i686/kernel-debug-devel-2.6.38.2-9.sam1 .... fc15.i686.rpm
Wrote: /home/sam/rpmbuild/RPMS/i686/kernel-debug-debuginfo-2.6.38.2-9.s ... fc15.i686.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.gZcEvK
+ umask 022
+ cd /home/sam/rpmbuild/BUILD
+ cd kernel-2.6.38.fc15
+ rm -rf /home/sam/rpmbuild/BUILDROOT/kernel-2.6.38.2-9.sam1104181000.fc15.i386
+ exit 0
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.
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:
$ 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
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
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.
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.
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.
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;)
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.
# 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
#boot=/dev/sda
default=0
timeout=0
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Fedora (2.6.38.2-9.sam1104181000.fc15.i686)
root (hd0,0)
kernel /vmlinuz-2.6.38.2-9.sam1104181000.fc15.i686 ro
root=/dev/mapper/vg_guava-lv_root rd_LVM_LV=vg_guava/lv_root
rd_LVM_LV=vg_guava/lv_swap
rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16
KEYTABLE=us
rhgb quiet
initrd /initramfs-2.6.38.2-9.sam1104181000.fc15.i686.img
title Fedora (2.6.38.2-9.fc15.i686)
root (hd0,0)
kernel /vmlinuz-2.6.38.2-9.fc15.i686 ro root=/dev/mapper/vg_guava-lv_root
rd_LVM_LV=vg_guava/lv_root rd_LVM_LV=vg_guava/lv_swap rd_NO_LUKS rd_NO_MD
rd_NO_DM
LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet
initrd /initramfs-2.6.38.2-9.fc15.i686.img
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:
# 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
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:
$ 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:
$ 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.
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.

More Related Content

What's hot

FIXING BLOCK CORRUPTION (RMAN) on 11G
FIXING BLOCK CORRUPTION (RMAN) on 11GFIXING BLOCK CORRUPTION (RMAN) on 11G
FIXING BLOCK CORRUPTION (RMAN) on 11G
N/A
 
My sql with querys
My sql with querysMy sql with querys
My sql with querys
NIRMAL FELIX
 
Power point on linux commands,appache,php,mysql,html,css,web 2.0
Power point on linux commands,appache,php,mysql,html,css,web 2.0Power point on linux commands,appache,php,mysql,html,css,web 2.0
Power point on linux commands,appache,php,mysql,html,css,web 2.0
venkatakrishnan k
 

What's hot (20)

FIXING BLOCK CORRUPTION (RMAN) on 11G
FIXING BLOCK CORRUPTION (RMAN) on 11GFIXING BLOCK CORRUPTION (RMAN) on 11G
FIXING BLOCK CORRUPTION (RMAN) on 11G
 
Asiabsdcon14 lavigne
Asiabsdcon14 lavigneAsiabsdcon14 lavigne
Asiabsdcon14 lavigne
 
Yum (Linux)
Yum (Linux) Yum (Linux)
Yum (Linux)
 
Article may11 bsdmag
Article may11 bsdmagArticle may11 bsdmag
Article may11 bsdmag
 
Tlf2014
Tlf2014Tlf2014
Tlf2014
 
12 yum
12  yum12  yum
12 yum
 
Windows Xp Command Prompt
Windows Xp Command PromptWindows Xp Command Prompt
Windows Xp Command Prompt
 
Hadoop completereference
Hadoop completereferenceHadoop completereference
Hadoop completereference
 
My sql with querys
My sql with querysMy sql with querys
My sql with querys
 
9i lin relnotes
9i lin relnotes9i lin relnotes
9i lin relnotes
 
Ilf2011
Ilf2011Ilf2011
Ilf2011
 
Basic linux commands
Basic linux commandsBasic linux commands
Basic linux commands
 
Backup and Restore SALSA to a Secondary Server with a different IP address
Backup and Restore SALSA to a Secondary Server with a different IP addressBackup and Restore SALSA to a Secondary Server with a different IP address
Backup and Restore SALSA to a Secondary Server with a different IP address
 
Content server installation guide
Content server installation guideContent server installation guide
Content server installation guide
 
Scale9x sun
Scale9x sunScale9x sun
Scale9x sun
 
Linux presentation
Linux presentationLinux presentation
Linux presentation
 
Power point on linux commands,appache,php,mysql,html,css,web 2.0
Power point on linux commands,appache,php,mysql,html,css,web 2.0Power point on linux commands,appache,php,mysql,html,css,web 2.0
Power point on linux commands,appache,php,mysql,html,css,web 2.0
 
Cheatsheet of msdos
Cheatsheet of msdosCheatsheet of msdos
Cheatsheet of msdos
 
Asiabsdcon14
Asiabsdcon14Asiabsdcon14
Asiabsdcon14
 
Linux
LinuxLinux
Linux
 

Viewers also liked

Red hat linux essentials
Red hat linux essentialsRed hat linux essentials
Red hat linux essentials
elshiekh1980
 
Linux fundamentals
Linux fundamentalsLinux fundamentals
Linux fundamentals
Raghu nath
 
Linux Kernel Programming
Linux Kernel ProgrammingLinux Kernel Programming
Linux Kernel Programming
Nalin Sharma
 
Linux process management
Linux process managementLinux process management
Linux process management
Raghu nath
 
Approach to liver disease
Approach to liver diseaseApproach to liver disease
Approach to liver disease
anoop r prasad
 
Redhat training &certification
Redhat training &certificationRedhat training &certification
Redhat training &certification
Ahmed Abbas Ahmed
 
Top 100 Linux Interview Questions and Answers 2014
Top 100 Linux Interview Questions and Answers 2014Top 100 Linux Interview Questions and Answers 2014
Top 100 Linux Interview Questions and Answers 2014
iimjobs and hirist
 

Viewers also liked (20)

Red hat linux essentials
Red hat linux essentialsRed hat linux essentials
Red hat linux essentials
 
Linux Kernel Development
Linux Kernel DevelopmentLinux Kernel Development
Linux Kernel Development
 
Linux Process Management Workshop
Linux Process Management WorkshopLinux Process Management Workshop
Linux Process Management Workshop
 
Linux fundamentals
Linux fundamentalsLinux fundamentals
Linux fundamentals
 
Kernel Module Programming
Kernel Module ProgrammingKernel Module Programming
Kernel Module Programming
 
Linux fundamentals Training
Linux fundamentals TrainingLinux fundamentals Training
Linux fundamentals Training
 
Red hat linux essentials
Red hat linux essentialsRed hat linux essentials
Red hat linux essentials
 
Linux Initialization Process (2)
Linux Initialization Process (2)Linux Initialization Process (2)
Linux Initialization Process (2)
 
Linux Kernel Programming
Linux Kernel ProgrammingLinux Kernel Programming
Linux Kernel Programming
 
Linux process management
Linux process managementLinux process management
Linux process management
 
RHCE (RED HAT CERTIFIED ENGINEERING)
RHCE (RED HAT CERTIFIED ENGINEERING)RHCE (RED HAT CERTIFIED ENGINEERING)
RHCE (RED HAT CERTIFIED ENGINEERING)
 
Embedded Linux Kernel - Build your custom kernel
Embedded Linux Kernel - Build your custom kernelEmbedded Linux Kernel - Build your custom kernel
Embedded Linux Kernel - Build your custom kernel
 
Process management in linux
Process management in linuxProcess management in linux
Process management in linux
 
Approach to liver disease
Approach to liver diseaseApproach to liver disease
Approach to liver disease
 
RedHat Linux
RedHat LinuxRedHat Linux
RedHat Linux
 
Linux Kernel Overview
Linux Kernel OverviewLinux Kernel Overview
Linux Kernel Overview
 
Redhat training &certification
Redhat training &certificationRedhat training &certification
Redhat training &certification
 
RHCE FINAL Questions and Answers
RHCE FINAL Questions and AnswersRHCE FINAL Questions and Answers
RHCE FINAL Questions and Answers
 
Introduction to Red Hat
Introduction to Red HatIntroduction to Red Hat
Introduction to Red Hat
 
Top 100 Linux Interview Questions and Answers 2014
Top 100 Linux Interview Questions and Answers 2014Top 100 Linux Interview Questions and Answers 2014
Top 100 Linux Interview Questions and Answers 2014
 

Similar to Building a linux kernel

Software management in linux
Software management in linuxSoftware management in linux
Software management in linux
nejadmand
 
101 2.5 use rpm and yum package management
101 2.5 use rpm and yum package management101 2.5 use rpm and yum package management
101 2.5 use rpm and yum package management
Acácio Oliveira
 

Similar to Building a linux kernel (20)

Lecture 5 Kernel Development
Lecture 5 Kernel DevelopmentLecture 5 Kernel Development
Lecture 5 Kernel Development
 
Oracle11g On Fedora14
Oracle11g On Fedora14Oracle11g On Fedora14
Oracle11g On Fedora14
 
Oracle11g on fedora14
Oracle11g on fedora14Oracle11g on fedora14
Oracle11g on fedora14
 
Linux kernel
Linux kernelLinux kernel
Linux kernel
 
Linux
Linux Linux
Linux
 
Linux kernel modules
Linux kernel modulesLinux kernel modules
Linux kernel modules
 
Unix Administration 2
Unix Administration 2Unix Administration 2
Unix Administration 2
 
RPM (LINUX)
RPM (LINUX)RPM (LINUX)
RPM (LINUX)
 
101 1.2 boot the system
101 1.2 boot the system101 1.2 boot the system
101 1.2 boot the system
 
Sahul
SahulSahul
Sahul
 
Perl 20tips
Perl 20tipsPerl 20tips
Perl 20tips
 
linux installation.pdf
linux installation.pdflinux installation.pdf
linux installation.pdf
 
How to make debian package from scratch (linux)
How to make debian package from scratch (linux)How to make debian package from scratch (linux)
How to make debian package from scratch (linux)
 
Software management in linux
Software management in linuxSoftware management in linux
Software management in linux
 
101 2.5 use rpm and yum package management
101 2.5 use rpm and yum package management101 2.5 use rpm and yum package management
101 2.5 use rpm and yum package management
 
Managing Perl Installations: A SysAdmin's View
Managing Perl Installations: A SysAdmin's ViewManaging Perl Installations: A SysAdmin's View
Managing Perl Installations: A SysAdmin's View
 
Divya
DivyaDivya
Divya
 
Divya
DivyaDivya
Divya
 
Sahu
SahuSahu
Sahu
 
Fedora Atomic Workshop handout for Fudcon Pune 2015
Fedora Atomic Workshop handout for Fudcon Pune  2015Fedora Atomic Workshop handout for Fudcon Pune  2015
Fedora Atomic Workshop handout for Fudcon Pune 2015
 

More from Raghu nath

Ftp (file transfer protocol)
Ftp (file transfer protocol)Ftp (file transfer protocol)
Ftp (file transfer protocol)
Raghu nath
 
Javascript part1
Javascript part1Javascript part1
Javascript part1
Raghu nath
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
Raghu nath
 
Selection sort
Selection sortSelection sort
Selection sort
Raghu nath
 
Binary search
Binary search Binary search
Binary search
Raghu nath
 
JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)
Raghu nath
 
Stemming algorithms
Stemming algorithmsStemming algorithms
Stemming algorithms
Raghu nath
 
Step by step guide to install dhcp role
Step by step guide to install dhcp roleStep by step guide to install dhcp role
Step by step guide to install dhcp role
Raghu nath
 
Network essentials chapter 4
Network essentials  chapter 4Network essentials  chapter 4
Network essentials chapter 4
Raghu nath
 
Network essentials chapter 3
Network essentials  chapter 3Network essentials  chapter 3
Network essentials chapter 3
Raghu nath
 
Network essentials chapter 2
Network essentials  chapter 2Network essentials  chapter 2
Network essentials chapter 2
Raghu nath
 
Network essentials - chapter 1
Network essentials - chapter 1Network essentials - chapter 1
Network essentials - chapter 1
Raghu nath
 
Python chapter 2
Python chapter 2Python chapter 2
Python chapter 2
Raghu nath
 
python chapter 1
python chapter 1python chapter 1
python chapter 1
Raghu nath
 
Linux Shell Scripting
Linux Shell ScriptingLinux Shell Scripting
Linux Shell Scripting
Raghu nath
 

More from Raghu nath (20)

Mongo db
Mongo dbMongo db
Mongo db
 
Ftp (file transfer protocol)
Ftp (file transfer protocol)Ftp (file transfer protocol)
Ftp (file transfer protocol)
 
MS WORD 2013
MS WORD 2013MS WORD 2013
MS WORD 2013
 
Msword
MswordMsword
Msword
 
Ms word
Ms wordMs word
Ms word
 
Javascript part1
Javascript part1Javascript part1
Javascript part1
 
Regular expressions
Regular expressionsRegular expressions
Regular expressions
 
Selection sort
Selection sortSelection sort
Selection sort
 
Binary search
Binary search Binary search
Binary search
 
JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)JSON(JavaScript Object Notation)
JSON(JavaScript Object Notation)
 
Stemming algorithms
Stemming algorithmsStemming algorithms
Stemming algorithms
 
Step by step guide to install dhcp role
Step by step guide to install dhcp roleStep by step guide to install dhcp role
Step by step guide to install dhcp role
 
Network essentials chapter 4
Network essentials  chapter 4Network essentials  chapter 4
Network essentials chapter 4
 
Network essentials chapter 3
Network essentials  chapter 3Network essentials  chapter 3
Network essentials chapter 3
 
Network essentials chapter 2
Network essentials  chapter 2Network essentials  chapter 2
Network essentials chapter 2
 
Network essentials - chapter 1
Network essentials - chapter 1Network essentials - chapter 1
Network essentials - chapter 1
 
Python chapter 2
Python chapter 2Python chapter 2
Python chapter 2
 
python chapter 1
python chapter 1python chapter 1
python chapter 1
 
Linux Shell Scripting
Linux Shell ScriptingLinux Shell Scripting
Linux Shell Scripting
 
Perl
PerlPerl
Perl
 

Recently uploaded

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
heathfieldcps1
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
fonyou31
 

Recently uploaded (20)

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 

Building a linux kernel

  • 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.
  • 4. $ sysctl kernel.domainname kernel.domainname = tcorp.com $ su -c 'sysctl -w kernel.domainname="example.com" ' kernel.domainname = example.com $ sysctl kernel.domainname kernel.domainname = example.com
  • 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:
  • 23.
  • 24. $ make config $ make menuconfig $ make gconfig
  • 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: Options􀁄Show 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: File􀁄Save 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
  • 34. ... CLEAN Documentation/watchdog/src CLEAN .tmp_versions CLEAN vmlinux System.map .tmp_kallsyms3.o .tmp_kallsyms3.S ... This command ensures that make correctly applies any numbering scheme you use when you compile the kernel.
  • 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
  • 37. + umask 022 + cd /home/sam/rpmbuild/BUILD ... Wrote: /home/sam/rpmbuild/RPMS/i686/kernel-debug-devel-2.6.38.2-9.sam1 .... fc15.i686.rpm Wrote: /home/sam/rpmbuild/RPMS/i686/kernel-debug-debuginfo-2.6.38.2-9.s ... fc15.i686.rpm Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.gZcEvK + umask 022 + cd /home/sam/rpmbuild/BUILD + cd kernel-2.6.38.fc15 + rm -rf /home/sam/rpmbuild/BUILDROOT/kernel-2.6.38.2-9.sam1104181000.fc15.i386 + exit 0
  • 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
  • 49. root=/dev/mapper/vg_guava-lv_root rd_LVM_LV=vg_guava/lv_root rd_LVM_LV=vg_guava/lv_swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet initrd /initramfs-2.6.38.2-9.sam1104181000.fc15.i686.img title Fedora (2.6.38.2-9.fc15.i686)
  • 50. root (hd0,0) kernel /vmlinuz-2.6.38.2-9.fc15.i686 ro root=/dev/mapper/vg_guava-lv_root rd_LVM_LV=vg_guava/lv_root rd_LVM_LV=vg_guava/lv_swap rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet initrd /initramfs-2.6.38.2-9.fc15.i686.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.