+ All Categories
Home > Education > Building a linux kernel

Building a linux kernel

Date post: 15-Jul-2015
Category:
Upload: raghu-nath
View: 92 times
Download: 3 times
Share this document with a friend
Popular Tags:
56
Building a Linux Kernel
Transcript
Page 1: Building a linux kernel

Building a Linux Kernel

FedoraRHEL comes with a prebuilt kernel that simplifies the installation process

You can add the same parameters you use on the boot command line to

bootgrubgrubconf or to its symbolic link etcgrubconf 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 procsys which defines the parameters

that sysctl can modify

The command sysctl ndasha 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 kerneldomainname

kerneldomainname = tcorpcom

$ su -c sysctl -w kerneldomainname=examplecom

kerneldomainname = examplecom

$ sysctl kerneldomainname

kerneldomainname = examplecom

Downloading Installing and Prepping the Kernel Source CodePrerequisites

Install the following packages

bull rpmdevtools

bull yum-utils (installed with the default system)

bull ncurses-devel (used to configure the kernel using make menuconfig)

bull 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 35 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 tomdashnor should youmdashwork 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 ldquoDonrsquot take the name of root in vainrdquo

The sections on building customizing and installing the kernel use su ndashc 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-26382-9fc15srcrpm | 72 MB 0248

The downloadfedoraredhatcom 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

ftpftpredhatcompubredhatlinuxenterprise 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

ftpftpredhatcompubredhatlinuxenterprise6ServerenosSRPMS From the SRPMS page

search for or scroll down until you find the files named kernelsrcrpm 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-2632-71181el6srcrpm The src indicates the

package contains source files Alternatively

Installing the Source Codeyum-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 263511-83fc14 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 ~samkernel-26382-9fc15srcrpm

password

Loaded plugins langpacks presto refresh-packagekit

Adding en_US to language list

Getting requirements for kernel-26382-9fc15src

Install 29 Package(s)

Total download size 26 M

Installed size 77 M

Is this ok [yN] 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-26382-9fc15srcrpm

1kernel warning user mockbuild does not exist - using root

warning group mockbuild does not exist - using root

warning user mockbuild does not exist - using root

1kernel [100]

You can ignore errors such as those shown above about groups and users that do

not exist

Prepping the Source CodeThe 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 ndashbp option to

prep the source code

$ cd homesamrpmbuildSPECS

$ rpmbuild -bp --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpSJXxg1

+ umask 022

+ cd homesamrpmbuildBUILD

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-2632-71181el6i686

zlib-devel is needed by kernel-2632-71181el6i686

binutils-devel is needed by kernel-2632-71181el6i686

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 KernelLabeling the Kernel

To prevent overwriting existing kernel files and to identify various compilations of

the kernel you can change the buildid variable in the kernelspec 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 rpmbuildSPECS

edit kernelspec 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 KernelThe config file in the ~rpmbuildBUILDkernellinux 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 ldquoCustomizing a Kernelrdquo

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 howevermdashwhich 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 ~rpmbuildBUILDkernellinux 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

homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

$ cp bootconfig-$(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 [Ny] (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 KernelThe ~rpmbuildBUILDkernellinux 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

bootconfig-$(uname ndashr) 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+ (wwwgtkorg) 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 (eg 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 boxradio 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 Options1048644Show 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 File1048644Save and close the

window

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 2: Building a linux kernel

FedoraRHEL comes with a prebuilt kernel that simplifies the installation process

You can add the same parameters you use on the boot command line to

bootgrubgrubconf or to its symbolic link etcgrubconf 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 procsys which defines the parameters

that sysctl can modify

The command sysctl ndasha 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 kerneldomainname

kerneldomainname = tcorpcom

$ su -c sysctl -w kerneldomainname=examplecom

kerneldomainname = examplecom

$ sysctl kerneldomainname

kerneldomainname = examplecom

Downloading Installing and Prepping the Kernel Source CodePrerequisites

Install the following packages

bull rpmdevtools

bull yum-utils (installed with the default system)

bull ncurses-devel (used to configure the kernel using make menuconfig)

bull 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 35 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 tomdashnor should youmdashwork 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 ldquoDonrsquot take the name of root in vainrdquo

The sections on building customizing and installing the kernel use su ndashc 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-26382-9fc15srcrpm | 72 MB 0248

The downloadfedoraredhatcom 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

ftpftpredhatcompubredhatlinuxenterprise 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

ftpftpredhatcompubredhatlinuxenterprise6ServerenosSRPMS From the SRPMS page

search for or scroll down until you find the files named kernelsrcrpm 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-2632-71181el6srcrpm The src indicates the

package contains source files Alternatively

Installing the Source Codeyum-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 263511-83fc14 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 ~samkernel-26382-9fc15srcrpm

password

Loaded plugins langpacks presto refresh-packagekit

Adding en_US to language list

Getting requirements for kernel-26382-9fc15src

Install 29 Package(s)

Total download size 26 M

Installed size 77 M

Is this ok [yN] 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-26382-9fc15srcrpm

1kernel warning user mockbuild does not exist - using root

warning group mockbuild does not exist - using root

warning user mockbuild does not exist - using root

1kernel [100]

You can ignore errors such as those shown above about groups and users that do

not exist

Prepping the Source CodeThe 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 ndashbp option to

prep the source code

$ cd homesamrpmbuildSPECS

$ rpmbuild -bp --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpSJXxg1

+ umask 022

+ cd homesamrpmbuildBUILD

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-2632-71181el6i686

zlib-devel is needed by kernel-2632-71181el6i686

binutils-devel is needed by kernel-2632-71181el6i686

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 KernelLabeling the Kernel

To prevent overwriting existing kernel files and to identify various compilations of

the kernel you can change the buildid variable in the kernelspec 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 rpmbuildSPECS

edit kernelspec 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 KernelThe config file in the ~rpmbuildBUILDkernellinux 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 ldquoCustomizing a Kernelrdquo

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 howevermdashwhich 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 ~rpmbuildBUILDkernellinux 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

homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

$ cp bootconfig-$(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 [Ny] (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 KernelThe ~rpmbuildBUILDkernellinux 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

bootconfig-$(uname ndashr) 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+ (wwwgtkorg) 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 (eg 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 boxradio 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 Options1048644Show 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 File1048644Save and close the

window

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 3: Building a linux kernel

sysctl The sysctl utility can modify kernel parameters while the system is running This

utility takes advantage of the facilities of procsys which defines the parameters

that sysctl can modify

The command sysctl ndasha 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 kerneldomainname

kerneldomainname = tcorpcom

$ su -c sysctl -w kerneldomainname=examplecom

kerneldomainname = examplecom

$ sysctl kerneldomainname

kerneldomainname = examplecom

Downloading Installing and Prepping the Kernel Source CodePrerequisites

Install the following packages

bull rpmdevtools

bull yum-utils (installed with the default system)

bull ncurses-devel (used to configure the kernel using make menuconfig)

bull 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 35 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 tomdashnor should youmdashwork 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 ldquoDonrsquot take the name of root in vainrdquo

The sections on building customizing and installing the kernel use su ndashc 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-26382-9fc15srcrpm | 72 MB 0248

The downloadfedoraredhatcom 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

ftpftpredhatcompubredhatlinuxenterprise 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

ftpftpredhatcompubredhatlinuxenterprise6ServerenosSRPMS From the SRPMS page

search for or scroll down until you find the files named kernelsrcrpm 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-2632-71181el6srcrpm The src indicates the

package contains source files Alternatively

Installing the Source Codeyum-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 263511-83fc14 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 ~samkernel-26382-9fc15srcrpm

password

Loaded plugins langpacks presto refresh-packagekit

Adding en_US to language list

Getting requirements for kernel-26382-9fc15src

Install 29 Package(s)

Total download size 26 M

Installed size 77 M

Is this ok [yN] 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-26382-9fc15srcrpm

1kernel warning user mockbuild does not exist - using root

warning group mockbuild does not exist - using root

warning user mockbuild does not exist - using root

1kernel [100]

You can ignore errors such as those shown above about groups and users that do

not exist

Prepping the Source CodeThe 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 ndashbp option to

prep the source code

$ cd homesamrpmbuildSPECS

$ rpmbuild -bp --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpSJXxg1

+ umask 022

+ cd homesamrpmbuildBUILD

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-2632-71181el6i686

zlib-devel is needed by kernel-2632-71181el6i686

binutils-devel is needed by kernel-2632-71181el6i686

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 KernelLabeling the Kernel

To prevent overwriting existing kernel files and to identify various compilations of

the kernel you can change the buildid variable in the kernelspec 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 rpmbuildSPECS

edit kernelspec 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 KernelThe config file in the ~rpmbuildBUILDkernellinux 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 ldquoCustomizing a Kernelrdquo

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 howevermdashwhich 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 ~rpmbuildBUILDkernellinux 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

homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

$ cp bootconfig-$(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 [Ny] (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 KernelThe ~rpmbuildBUILDkernellinux 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

bootconfig-$(uname ndashr) 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+ (wwwgtkorg) 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 (eg 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 boxradio 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 Options1048644Show 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 File1048644Save and close the

window

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 4: Building a linux kernel

$ sysctl kerneldomainname

kerneldomainname = tcorpcom

$ su -c sysctl -w kerneldomainname=examplecom

kerneldomainname = examplecom

$ sysctl kerneldomainname

kerneldomainname = examplecom

Downloading Installing and Prepping the Kernel Source CodePrerequisites

Install the following packages

bull rpmdevtools

bull yum-utils (installed with the default system)

bull ncurses-devel (used to configure the kernel using make menuconfig)

bull 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 35 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 tomdashnor should youmdashwork 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 ldquoDonrsquot take the name of root in vainrdquo

The sections on building customizing and installing the kernel use su ndashc 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-26382-9fc15srcrpm | 72 MB 0248

The downloadfedoraredhatcom 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

ftpftpredhatcompubredhatlinuxenterprise 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

ftpftpredhatcompubredhatlinuxenterprise6ServerenosSRPMS From the SRPMS page

search for or scroll down until you find the files named kernelsrcrpm 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-2632-71181el6srcrpm The src indicates the

package contains source files Alternatively

Installing the Source Codeyum-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 263511-83fc14 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 ~samkernel-26382-9fc15srcrpm

password

Loaded plugins langpacks presto refresh-packagekit

Adding en_US to language list

Getting requirements for kernel-26382-9fc15src

Install 29 Package(s)

Total download size 26 M

Installed size 77 M

Is this ok [yN] 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-26382-9fc15srcrpm

1kernel warning user mockbuild does not exist - using root

warning group mockbuild does not exist - using root

warning user mockbuild does not exist - using root

1kernel [100]

You can ignore errors such as those shown above about groups and users that do

not exist

Prepping the Source CodeThe 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 ndashbp option to

prep the source code

$ cd homesamrpmbuildSPECS

$ rpmbuild -bp --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpSJXxg1

+ umask 022

+ cd homesamrpmbuildBUILD

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-2632-71181el6i686

zlib-devel is needed by kernel-2632-71181el6i686

binutils-devel is needed by kernel-2632-71181el6i686

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 KernelLabeling the Kernel

To prevent overwriting existing kernel files and to identify various compilations of

the kernel you can change the buildid variable in the kernelspec 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 rpmbuildSPECS

edit kernelspec 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 KernelThe config file in the ~rpmbuildBUILDkernellinux 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 ldquoCustomizing a Kernelrdquo

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 howevermdashwhich 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 ~rpmbuildBUILDkernellinux 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

homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

$ cp bootconfig-$(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 [Ny] (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 KernelThe ~rpmbuildBUILDkernellinux 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

bootconfig-$(uname ndashr) 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+ (wwwgtkorg) 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 (eg 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 boxradio 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 Options1048644Show 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 File1048644Save and close the

window

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 5: Building a linux kernel

Downloading Installing and Prepping the Kernel Source CodePrerequisites

Install the following packages

bull rpmdevtools

bull yum-utils (installed with the default system)

bull ncurses-devel (used to configure the kernel using make menuconfig)

bull 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 35 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 tomdashnor should youmdashwork 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 ldquoDonrsquot take the name of root in vainrdquo

The sections on building customizing and installing the kernel use su ndashc 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-26382-9fc15srcrpm | 72 MB 0248

The downloadfedoraredhatcom 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

ftpftpredhatcompubredhatlinuxenterprise 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

ftpftpredhatcompubredhatlinuxenterprise6ServerenosSRPMS From the SRPMS page

search for or scroll down until you find the files named kernelsrcrpm 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-2632-71181el6srcrpm The src indicates the

package contains source files Alternatively

Installing the Source Codeyum-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 263511-83fc14 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 ~samkernel-26382-9fc15srcrpm

password

Loaded plugins langpacks presto refresh-packagekit

Adding en_US to language list

Getting requirements for kernel-26382-9fc15src

Install 29 Package(s)

Total download size 26 M

Installed size 77 M

Is this ok [yN] 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-26382-9fc15srcrpm

1kernel warning user mockbuild does not exist - using root

warning group mockbuild does not exist - using root

warning user mockbuild does not exist - using root

1kernel [100]

You can ignore errors such as those shown above about groups and users that do

not exist

Prepping the Source CodeThe 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 ndashbp option to

prep the source code

$ cd homesamrpmbuildSPECS

$ rpmbuild -bp --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpSJXxg1

+ umask 022

+ cd homesamrpmbuildBUILD

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-2632-71181el6i686

zlib-devel is needed by kernel-2632-71181el6i686

binutils-devel is needed by kernel-2632-71181el6i686

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 KernelLabeling the Kernel

To prevent overwriting existing kernel files and to identify various compilations of

the kernel you can change the buildid variable in the kernelspec 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 rpmbuildSPECS

edit kernelspec 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 KernelThe config file in the ~rpmbuildBUILDkernellinux 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 ldquoCustomizing a Kernelrdquo

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 howevermdashwhich 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 ~rpmbuildBUILDkernellinux 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

homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

$ cp bootconfig-$(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 [Ny] (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 KernelThe ~rpmbuildBUILDkernellinux 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

bootconfig-$(uname ndashr) 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+ (wwwgtkorg) 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 (eg 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 boxradio 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 Options1048644Show 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 File1048644Save and close the

window

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 6: Building a linux kernel

Compiling a kernel takes a lot of disk space

When you compile a default kernel it occupies approximately 35 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 tomdashnor should youmdashwork 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 ldquoDonrsquot take the name of root in vainrdquo

The sections on building customizing and installing the kernel use su ndashc 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-26382-9fc15srcrpm | 72 MB 0248

The downloadfedoraredhatcom 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

ftpftpredhatcompubredhatlinuxenterprise 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

ftpftpredhatcompubredhatlinuxenterprise6ServerenosSRPMS From the SRPMS page

search for or scroll down until you find the files named kernelsrcrpm 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-2632-71181el6srcrpm The src indicates the

package contains source files Alternatively

Installing the Source Codeyum-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 263511-83fc14 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 ~samkernel-26382-9fc15srcrpm

password

Loaded plugins langpacks presto refresh-packagekit

Adding en_US to language list

Getting requirements for kernel-26382-9fc15src

Install 29 Package(s)

Total download size 26 M

Installed size 77 M

Is this ok [yN] 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-26382-9fc15srcrpm

1kernel warning user mockbuild does not exist - using root

warning group mockbuild does not exist - using root

warning user mockbuild does not exist - using root

1kernel [100]

You can ignore errors such as those shown above about groups and users that do

not exist

Prepping the Source CodeThe 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 ndashbp option to

prep the source code

$ cd homesamrpmbuildSPECS

$ rpmbuild -bp --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpSJXxg1

+ umask 022

+ cd homesamrpmbuildBUILD

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-2632-71181el6i686

zlib-devel is needed by kernel-2632-71181el6i686

binutils-devel is needed by kernel-2632-71181el6i686

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 KernelLabeling the Kernel

To prevent overwriting existing kernel files and to identify various compilations of

the kernel you can change the buildid variable in the kernelspec 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 rpmbuildSPECS

edit kernelspec 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 KernelThe config file in the ~rpmbuildBUILDkernellinux 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 ldquoCustomizing a Kernelrdquo

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 howevermdashwhich 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 ~rpmbuildBUILDkernellinux 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

homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

$ cp bootconfig-$(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 [Ny] (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 KernelThe ~rpmbuildBUILDkernellinux 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

bootconfig-$(uname ndashr) 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+ (wwwgtkorg) 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 (eg 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 boxradio 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 Options1048644Show 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 File1048644Save and close the

window

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 7: Building a linux kernel

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 tomdashnor should youmdashwork 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 ldquoDonrsquot take the name of root in vainrdquo

The sections on building customizing and installing the kernel use su ndashc 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-26382-9fc15srcrpm | 72 MB 0248

The downloadfedoraredhatcom 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

ftpftpredhatcompubredhatlinuxenterprise 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

ftpftpredhatcompubredhatlinuxenterprise6ServerenosSRPMS From the SRPMS page

search for or scroll down until you find the files named kernelsrcrpm 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-2632-71181el6srcrpm The src indicates the

package contains source files Alternatively

Installing the Source Codeyum-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 263511-83fc14 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 ~samkernel-26382-9fc15srcrpm

password

Loaded plugins langpacks presto refresh-packagekit

Adding en_US to language list

Getting requirements for kernel-26382-9fc15src

Install 29 Package(s)

Total download size 26 M

Installed size 77 M

Is this ok [yN] 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-26382-9fc15srcrpm

1kernel warning user mockbuild does not exist - using root

warning group mockbuild does not exist - using root

warning user mockbuild does not exist - using root

1kernel [100]

You can ignore errors such as those shown above about groups and users that do

not exist

Prepping the Source CodeThe 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 ndashbp option to

prep the source code

$ cd homesamrpmbuildSPECS

$ rpmbuild -bp --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpSJXxg1

+ umask 022

+ cd homesamrpmbuildBUILD

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-2632-71181el6i686

zlib-devel is needed by kernel-2632-71181el6i686

binutils-devel is needed by kernel-2632-71181el6i686

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 KernelLabeling the Kernel

To prevent overwriting existing kernel files and to identify various compilations of

the kernel you can change the buildid variable in the kernelspec 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 rpmbuildSPECS

edit kernelspec 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 KernelThe config file in the ~rpmbuildBUILDkernellinux 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 ldquoCustomizing a Kernelrdquo

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 howevermdashwhich 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 ~rpmbuildBUILDkernellinux 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

homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

$ cp bootconfig-$(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 [Ny] (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 KernelThe ~rpmbuildBUILDkernellinux 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

bootconfig-$(uname ndashr) 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+ (wwwgtkorg) 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 (eg 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 boxradio 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 Options1048644Show 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 File1048644Save and close the

window

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 8: Building a linux kernel

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-26382-9fc15srcrpm | 72 MB 0248

The downloadfedoraredhatcom 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

ftpftpredhatcompubredhatlinuxenterprise 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

ftpftpredhatcompubredhatlinuxenterprise6ServerenosSRPMS From the SRPMS page

search for or scroll down until you find the files named kernelsrcrpm 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-2632-71181el6srcrpm The src indicates the

package contains source files Alternatively

Installing the Source Codeyum-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 263511-83fc14 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 ~samkernel-26382-9fc15srcrpm

password

Loaded plugins langpacks presto refresh-packagekit

Adding en_US to language list

Getting requirements for kernel-26382-9fc15src

Install 29 Package(s)

Total download size 26 M

Installed size 77 M

Is this ok [yN] 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-26382-9fc15srcrpm

1kernel warning user mockbuild does not exist - using root

warning group mockbuild does not exist - using root

warning user mockbuild does not exist - using root

1kernel [100]

You can ignore errors such as those shown above about groups and users that do

not exist

Prepping the Source CodeThe 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 ndashbp option to

prep the source code

$ cd homesamrpmbuildSPECS

$ rpmbuild -bp --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpSJXxg1

+ umask 022

+ cd homesamrpmbuildBUILD

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-2632-71181el6i686

zlib-devel is needed by kernel-2632-71181el6i686

binutils-devel is needed by kernel-2632-71181el6i686

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 KernelLabeling the Kernel

To prevent overwriting existing kernel files and to identify various compilations of

the kernel you can change the buildid variable in the kernelspec 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 rpmbuildSPECS

edit kernelspec 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 KernelThe config file in the ~rpmbuildBUILDkernellinux 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 ldquoCustomizing a Kernelrdquo

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 howevermdashwhich 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 ~rpmbuildBUILDkernellinux 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

homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

$ cp bootconfig-$(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 [Ny] (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 KernelThe ~rpmbuildBUILDkernellinux 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

bootconfig-$(uname ndashr) 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+ (wwwgtkorg) 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 (eg 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 boxradio 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 Options1048644Show 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 File1048644Save and close the

window

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 9: Building a linux kernel

The downloadfedoraredhatcom 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

ftpftpredhatcompubredhatlinuxenterprise 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

ftpftpredhatcompubredhatlinuxenterprise6ServerenosSRPMS From the SRPMS page

search for or scroll down until you find the files named kernelsrcrpm 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-2632-71181el6srcrpm The src indicates the

package contains source files Alternatively

Installing the Source Codeyum-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 263511-83fc14 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 ~samkernel-26382-9fc15srcrpm

password

Loaded plugins langpacks presto refresh-packagekit

Adding en_US to language list

Getting requirements for kernel-26382-9fc15src

Install 29 Package(s)

Total download size 26 M

Installed size 77 M

Is this ok [yN] 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-26382-9fc15srcrpm

1kernel warning user mockbuild does not exist - using root

warning group mockbuild does not exist - using root

warning user mockbuild does not exist - using root

1kernel [100]

You can ignore errors such as those shown above about groups and users that do

not exist

Prepping the Source CodeThe 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 ndashbp option to

prep the source code

$ cd homesamrpmbuildSPECS

$ rpmbuild -bp --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpSJXxg1

+ umask 022

+ cd homesamrpmbuildBUILD

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-2632-71181el6i686

zlib-devel is needed by kernel-2632-71181el6i686

binutils-devel is needed by kernel-2632-71181el6i686

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 KernelLabeling the Kernel

To prevent overwriting existing kernel files and to identify various compilations of

the kernel you can change the buildid variable in the kernelspec 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 rpmbuildSPECS

edit kernelspec 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 KernelThe config file in the ~rpmbuildBUILDkernellinux 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 ldquoCustomizing a Kernelrdquo

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 howevermdashwhich 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 ~rpmbuildBUILDkernellinux 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

homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

$ cp bootconfig-$(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 [Ny] (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 KernelThe ~rpmbuildBUILDkernellinux 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

bootconfig-$(uname ndashr) 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+ (wwwgtkorg) 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 (eg 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 boxradio 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 Options1048644Show 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 File1048644Save and close the

window

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 10: Building a linux kernel

Installing the Source Codeyum-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 263511-83fc14 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 ~samkernel-26382-9fc15srcrpm

password

Loaded plugins langpacks presto refresh-packagekit

Adding en_US to language list

Getting requirements for kernel-26382-9fc15src

Install 29 Package(s)

Total download size 26 M

Installed size 77 M

Is this ok [yN] 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-26382-9fc15srcrpm

1kernel warning user mockbuild does not exist - using root

warning group mockbuild does not exist - using root

warning user mockbuild does not exist - using root

1kernel [100]

You can ignore errors such as those shown above about groups and users that do

not exist

Prepping the Source CodeThe 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 ndashbp option to

prep the source code

$ cd homesamrpmbuildSPECS

$ rpmbuild -bp --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpSJXxg1

+ umask 022

+ cd homesamrpmbuildBUILD

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-2632-71181el6i686

zlib-devel is needed by kernel-2632-71181el6i686

binutils-devel is needed by kernel-2632-71181el6i686

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 KernelLabeling the Kernel

To prevent overwriting existing kernel files and to identify various compilations of

the kernel you can change the buildid variable in the kernelspec 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 rpmbuildSPECS

edit kernelspec 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 KernelThe config file in the ~rpmbuildBUILDkernellinux 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 ldquoCustomizing a Kernelrdquo

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 howevermdashwhich 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 ~rpmbuildBUILDkernellinux 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

homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

$ cp bootconfig-$(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 [Ny] (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 KernelThe ~rpmbuildBUILDkernellinux 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

bootconfig-$(uname ndashr) 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+ (wwwgtkorg) 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 (eg 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 boxradio 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 Options1048644Show 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 File1048644Save and close the

window

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 11: Building a linux kernel

$ su -c yum-builddep ~samkernel-26382-9fc15srcrpm

password

Loaded plugins langpacks presto refresh-packagekit

Adding en_US to language list

Getting requirements for kernel-26382-9fc15src

Install 29 Package(s)

Total download size 26 M

Installed size 77 M

Is this ok [yN] 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-26382-9fc15srcrpm

1kernel warning user mockbuild does not exist - using root

warning group mockbuild does not exist - using root

warning user mockbuild does not exist - using root

1kernel [100]

You can ignore errors such as those shown above about groups and users that do

not exist

Prepping the Source CodeThe 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 ndashbp option to

prep the source code

$ cd homesamrpmbuildSPECS

$ rpmbuild -bp --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpSJXxg1

+ umask 022

+ cd homesamrpmbuildBUILD

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-2632-71181el6i686

zlib-devel is needed by kernel-2632-71181el6i686

binutils-devel is needed by kernel-2632-71181el6i686

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 KernelLabeling the Kernel

To prevent overwriting existing kernel files and to identify various compilations of

the kernel you can change the buildid variable in the kernelspec 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 rpmbuildSPECS

edit kernelspec 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 KernelThe config file in the ~rpmbuildBUILDkernellinux 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 ldquoCustomizing a Kernelrdquo

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 howevermdashwhich 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 ~rpmbuildBUILDkernellinux 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

homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

$ cp bootconfig-$(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 [Ny] (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 KernelThe ~rpmbuildBUILDkernellinux 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

bootconfig-$(uname ndashr) 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+ (wwwgtkorg) 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 (eg 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 boxradio 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 Options1048644Show 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 File1048644Save and close the

window

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 12: Building a linux kernel

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-26382-9fc15srcrpm

1kernel warning user mockbuild does not exist - using root

warning group mockbuild does not exist - using root

warning user mockbuild does not exist - using root

1kernel [100]

You can ignore errors such as those shown above about groups and users that do

not exist

Prepping the Source CodeThe 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 ndashbp option to

prep the source code

$ cd homesamrpmbuildSPECS

$ rpmbuild -bp --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpSJXxg1

+ umask 022

+ cd homesamrpmbuildBUILD

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-2632-71181el6i686

zlib-devel is needed by kernel-2632-71181el6i686

binutils-devel is needed by kernel-2632-71181el6i686

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 KernelLabeling the Kernel

To prevent overwriting existing kernel files and to identify various compilations of

the kernel you can change the buildid variable in the kernelspec 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 rpmbuildSPECS

edit kernelspec 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 KernelThe config file in the ~rpmbuildBUILDkernellinux 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 ldquoCustomizing a Kernelrdquo

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 howevermdashwhich 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 ~rpmbuildBUILDkernellinux 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

homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

$ cp bootconfig-$(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 [Ny] (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 KernelThe ~rpmbuildBUILDkernellinux 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

bootconfig-$(uname ndashr) 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+ (wwwgtkorg) 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 (eg 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 boxradio 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 Options1048644Show 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 File1048644Save and close the

window

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 13: Building a linux kernel

Prepping the Source CodeThe 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 ndashbp option to

prep the source code

$ cd homesamrpmbuildSPECS

$ rpmbuild -bp --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpSJXxg1

+ umask 022

+ cd homesamrpmbuildBUILD

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-2632-71181el6i686

zlib-devel is needed by kernel-2632-71181el6i686

binutils-devel is needed by kernel-2632-71181el6i686

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 KernelLabeling the Kernel

To prevent overwriting existing kernel files and to identify various compilations of

the kernel you can change the buildid variable in the kernelspec 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 rpmbuildSPECS

edit kernelspec 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 KernelThe config file in the ~rpmbuildBUILDkernellinux 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 ldquoCustomizing a Kernelrdquo

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 howevermdashwhich 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 ~rpmbuildBUILDkernellinux 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

homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

$ cp bootconfig-$(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 [Ny] (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 KernelThe ~rpmbuildBUILDkernellinux 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

bootconfig-$(uname ndashr) 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+ (wwwgtkorg) 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 (eg 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 boxradio 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 Options1048644Show 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 File1048644Save and close the

window

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 14: Building a linux kernel

error Failed build dependencies

elfutils-libelf-devel is needed by kernel-2632-71181el6i686

zlib-devel is needed by kernel-2632-71181el6i686

binutils-devel is needed by kernel-2632-71181el6i686

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 KernelLabeling the Kernel

To prevent overwriting existing kernel files and to identify various compilations of

the kernel you can change the buildid variable in the kernelspec 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 rpmbuildSPECS

edit kernelspec 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 KernelThe config file in the ~rpmbuildBUILDkernellinux 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 ldquoCustomizing a Kernelrdquo

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 howevermdashwhich 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 ~rpmbuildBUILDkernellinux 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

homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

$ cp bootconfig-$(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 [Ny] (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 KernelThe ~rpmbuildBUILDkernellinux 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

bootconfig-$(uname ndashr) 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+ (wwwgtkorg) 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 (eg 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 boxradio 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 Options1048644Show 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 File1048644Save and close the

window

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 15: Building a linux kernel

Configuring and Compiling the Linux KernelLabeling the Kernel

To prevent overwriting existing kernel files and to identify various compilations of

the kernel you can change the buildid variable in the kernelspec 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 rpmbuildSPECS

edit kernelspec 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 KernelThe config file in the ~rpmbuildBUILDkernellinux 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 ldquoCustomizing a Kernelrdquo

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 howevermdashwhich 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 ~rpmbuildBUILDkernellinux 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

homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

$ cp bootconfig-$(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 [Ny] (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 KernelThe ~rpmbuildBUILDkernellinux 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

bootconfig-$(uname ndashr) 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+ (wwwgtkorg) 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 (eg 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 boxradio 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 Options1048644Show 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 File1048644Save and close the

window

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 16: Building a linux kernel

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 KernelThe config file in the ~rpmbuildBUILDkernellinux 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 ldquoCustomizing a Kernelrdquo

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 howevermdashwhich 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 ~rpmbuildBUILDkernellinux 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

homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

$ cp bootconfig-$(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 [Ny] (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 KernelThe ~rpmbuildBUILDkernellinux 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

bootconfig-$(uname ndashr) 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+ (wwwgtkorg) 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 (eg 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 boxradio 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 Options1048644Show 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 File1048644Save and close the

window

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 17: Building a linux kernel

config Configures the KernelThe config file in the ~rpmbuildBUILDkernellinux 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 ldquoCustomizing a Kernelrdquo

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 howevermdashwhich 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 ~rpmbuildBUILDkernellinux 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

homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

$ cp bootconfig-$(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 [Ny] (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 KernelThe ~rpmbuildBUILDkernellinux 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

bootconfig-$(uname ndashr) 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+ (wwwgtkorg) 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 (eg 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 boxradio 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 Options1048644Show 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 File1048644Save and close the

window

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 18: Building a linux kernel

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 howevermdashwhich 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 ~rpmbuildBUILDkernellinux 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

homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

$ cp bootconfig-$(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 [Ny] (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 KernelThe ~rpmbuildBUILDkernellinux 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

bootconfig-$(uname ndashr) 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+ (wwwgtkorg) 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 (eg 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 boxradio 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 Options1048644Show 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 File1048644Save and close the

window

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 19: Building a linux kernel

Work in the ~rpmbuildBUILDkernellinux 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

homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

$ cp bootconfig-$(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 [Ny] (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 KernelThe ~rpmbuildBUILDkernellinux 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

bootconfig-$(uname ndashr) 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+ (wwwgtkorg) 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 (eg 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 boxradio 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 Options1048644Show 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 File1048644Save and close the

window

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 20: Building a linux kernel

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 [Ny] (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 KernelThe ~rpmbuildBUILDkernellinux 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

bootconfig-$(uname ndashr) 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+ (wwwgtkorg) 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 (eg 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 boxradio 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 Options1048644Show 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 File1048644Save and close the

window

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 21: Building a linux kernel

then displays a prompt which is similar to [Ny] (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 KernelThe ~rpmbuildBUILDkernellinux 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

bootconfig-$(uname ndashr) 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+ (wwwgtkorg) 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 (eg 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 boxradio 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 Options1048644Show 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 File1048644Save and close the

window

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 22: Building a linux kernel

Customizing a KernelThe ~rpmbuildBUILDkernellinux 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

bootconfig-$(uname ndashr) 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+ (wwwgtkorg) 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 (eg 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 boxradio 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 Options1048644Show 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 File1048644Save and close the

window

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 23: Building 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

bootconfig-$(uname ndashr) 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+ (wwwgtkorg) 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 (eg 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 boxradio 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 Options1048644Show 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 File1048644Save and close the

window

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 24: Building a linux kernel

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

bootconfig-$(uname ndashr) 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+ (wwwgtkorg) 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 (eg 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 boxradio 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 Options1048644Show 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 File1048644Save and close the

window

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 25: Building a linux 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+ (wwwgtkorg) 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 (eg 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 boxradio 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 Options1048644Show 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 File1048644Save and close the

window

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 26: Building a linux kernel

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 (eg 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 boxradio 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 Options1048644Show 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 File1048644Save and close the

window

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 27: Building a linux kernel

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 (eg 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 boxradio 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 Options1048644Show 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 File1048644Save and close the

window

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 28: Building a linux kernel

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 (eg 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 boxradio 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 Options1048644Show 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 File1048644Save and close the

window

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 29: Building a linux kernel

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 boxradio 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 Options1048644Show 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 File1048644Save and close the

window

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 30: Building a linux kernel

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 File1048644Save and close the

window

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 31: Building a linux kernel

Cleaning the Source TreeAfter 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 archx86bootcompressed

CLEAN archx86boot

CLEAN homesamrpmbuildBUILDkernel-2638fc15linux-2638i686

CLEAN archx86kernelacpirealmode

CLEAN archx86kernelcpu

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 32: Building a linux kernel

CLEAN Documentationwatchdogsrc

CLEAN tmp_versions

CLEAN vmlinux Systemmap tmp_kallsyms3o tmp_kallsyms3S

This command ensures that make correctly applies any numbering scheme you use

when you compile the kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 33: Building a linux kernel

Copying the Configuration FileBefore 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 (eg config-i686-generic)

$ cp config ~rpmbuildSOURCESconfig-$(arch)-generic

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 34: Building a linux kernel

Compiling a Kernel Image File and Loadable ModulesThe 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

homesamrpmbuildSPECS

$ rpmbuild -bb --target $(arch) kernelspec

Building target platforms i686

Building for target i686

Executing(prep) binsh -e vartmprpm-tmpJoAIFx

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 35: Building a linux kernel

+ umask 022

+ cd homesamrpmbuildBUILD

Wrote homesamrpmbuildRPMSi686kernel-debug-devel-26382-9sam1 fc15i686rpm

Wrote homesamrpmbuildRPMSi686kernel-debug-debuginfo-26382-9s fc15i686rpm

Executing(clean) binsh -e vartmprpm-tmpgZcEvK

+ umask 022

+ cd homesamrpmbuildBUILD

+ cd kernel-2638fc15

+ rm -rf homesamrpmbuildBUILDROOTkernel-26382-9sam1104181000fc15i386

+ exit 0

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 36: Building a linux kernel

Using Loadable Kernel ModulesA loadable kernel module (sometimes called a module or loadable module)

is an object filemdashpart of the kernelmdashthat 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 libmodules

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 37: Building a linux kernel

Installing the Kernel Modules andAssociated FilesThe next step which you must execute with root privileges is to copy the compiled

kernel modules and associated files to the appropriate directoriesmdashusually boot

and a subdirectory of libmodules 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 Samrsquos home directory

into the proper directories

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 38: Building a linux kernel

$ su -c rpm -ivh --force ~samrpmbuildRPMSi686kernel-26382-9sam1104181000fc15i686rpm

Password

Preparing [100]

1kernel [100]

Installing the kernel in this manner updates the grubconf

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 39: Building a linux kernel

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

26382-9sam1104181000fc15i686

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 40: Building a linux kernel

GRUB The Linux Boot LoaderMBR 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 systemrsquos 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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 41: Building a linux kernel

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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 42: Building a linux kernel

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

FedoraRHEL 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 bootgrubgrubconf 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 GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 43: Building a linux kernel

Configuring GRUBThe bootgrubgrubconf file with its link at etcgrubconf is the default GRUB configuration

file The grubconf 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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 44: Building a linux kernel

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 26382-9sam1104181000fc15i686 kernel the second numbered

1 is for the 26382-9fc15i686 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 bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 45: Building a linux kernel

cat bootgrubgrubconf

grubconf 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 (hd00)

kernel vmlinuz-version ro root=devmappervg_guava-lv_root

initrd initrd-[generic-]versionimg

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 46: Building a linux kernel

boot=devsda

default=0

timeout=0

splashimage=(hd00)grubsplashxpmgz

hiddenmenu

title Fedora (26382-9sam1104181000fc15i686)

root (hd00)

kernel vmlinuz-26382-9sam1104181000fc15i686 ro

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 47: Building a linux kernel

root=devmappervg_guava-lv_root rd_LVM_LV=vg_guavalv_rootrd_LVM_LV=vg_guavalv_swap

rd_NO_LUKS rd_NO_MD rd_NO_DM LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us

rhgb quiet

initrd initramfs-26382-9sam1104181000fc15i686img

title Fedora (26382-9fc15i686)

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 48: Building a linux kernel

root (hd00)

kernel vmlinuz-26382-9fc15i686 ro root=devmappervg_guava-lv_root

rd_LVM_LV=vg_guavalv_root rd_LVM_LV=vg_guavalv_swap rd_NO_LUKS rd_NO_MDrd_NO_DM

LANG=en_USUTF-8 SYSFONT=latarcyrheb-sun16 KEYTABLE=us rhgb quiet

initrd initramfs-26382-9fc15i686img

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 49: Building a linux kernel

grub-install Installs the MBR and GRUB Files

You can specify the device name as a GRUB device name (eg

hd0) or a device filename (eg devsda) The following example shows grub-install

installing files in the default location (bootgrub) and the MBR on device devsda

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 50: Building a linux kernel

grub-install devsda

Installation finished No error reported

This is the contents of the device map bootgrubdevicemap

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 51: Building a linux kernel

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

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 52: Building a linux kernel

$ dmesg | grep DMA

[ 1398073] ata1 PATA max UDMA33 cmd 0x1f0 ctl 0x3f6 bmdma 0x10c0 irq 14

[ 1398078] ata2 PATA max UDMA33 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

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 53: Building a linux kernel

$ dmesg | grep eth

[ 5060499] pcnet32 eth0 registered as PCnetPCI II 79C970A

[ 84527758] pcnet32 000002010 eth0 link up

[ 95458834] 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 varlogdmesg This file is overwritten each time

the system is booted but the previous version of the file is saved as dmesgold 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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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

Page 54: Building a linux kernel

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 etcgrubconf You can dynamically change options by modifying etcsysctlconf 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


Recommended