Professional Documents
Culture Documents
Today we'll finally take a closer look at the boot process and the linux
kernel. The boot process is something every Linux administrator
needs to be familiar with, because you'll interact with it often and
you'll need to modify it from time to time.
You'll also need to be aware, at least, of kernel modules, and how to
use them. This knowledge will come in handy when dealing with new
hardware, or trying to understand errors.
These days, the process for building the Linux kernel is something that
can safely remain a mystery to many system administrators. Kernel
updates are usually made available by the vendor (Red Hat, Ubuntu,
etc.), and can easily be installed through the regular package
management system. Gone are the days when Linux administrators
regularly built their own customized kernels.
Still, there will some day come a time when you need to do it. Maybe
you'll need a bleeding-edge kernel to make some newfangled device
work, or maybe you'll need to turn off some kernel feature that causes
problems.
Bootstrapping:
Bootstrapping (shortened long ago to booting) is the process by which a
computer is moved from a completely quiescent, dead, state to a fully
initialized and running state. Usually it begins with a button press that
leads to a cascade of successively more complex events that eventually
results in a successfully running operating system.
POST
BIOS
GRUB
Runtime
Stage1
Stage1.5
Stage2
Kernel
Linux
inittab
init
Number of
Blocks
Part 2: GRUB
Grub's Files:
Grub's files usually reside in the directory /boot/grub. Here you'll find:
images for the stage1, stage1.5 and stage2 bootloaders,
the main grub configuration file, called grub.conf or menu.lst,
possibly a background image for the grub menu,
the file device.map that matches up Linux disk names with their
Grub names.
[root@demo
-rw-r--r--rw-r--r--rw-r--r--rw-r--r--rw-------rw-r--r--rw-r--r-lrwxrwxrwx
-rw-r--r--rw-r--r--rw-r--r--rw-r--r--rw-r--r--rw-r--r--rw-r--r--rw-r--r--
~]# ls
1 root
1 root
1 root
1 root
1 root
1 root
1 root
1 root
1 root
1 root
1 root
1 root
1 root
1 root
1 root
1 root
-l /boot/grub
root
63 Sep
root
7616 Sep
root
7456 Sep
root
6720 Sep
root
1644 Dec
root
6720 Sep
root
8192 Sep
root
11 Sep
root
6880 Sep
root
9248 Sep
root
5427 Nov
root
512 Sep
root 104924 Sep
root
7040 Sep
root
6272 Sep
root
8864 Sep
10 2007 device.map
10 2007 e2fs_stage1_5
10 2007 fat_stage1_5
10 2007 ffs_stage1_5
17 01:38 grub.conf
10 2007 iso9660_stage1_5
10 2007 jfs_stage1_5
10 2007 menu.lst -> ./grub.conf
10 2007 minix_stage1_5
10 2007 reiserfs_stage1_5
22 2007 splash.xpm.gz
10 2007 stage1
10 2007 stage2
10 2007 ufs2_stage1_5
10 2007 vstafs_stage1_5
10 2007 xfs_stage1_5
8
(hd0,1)
Grub
Linux
Name
Name
(fd0)
/dev/fd0
Device
First floppy drive
menu.lst or grub.conf:
The main grub configuration file has the official name menu.lst, and
usually lives in the directory /boot/grub. Many Linux distributions use
symbolic links to allow you to use grub.conf as an alternative name
for this file. Here's a typical grub.conf file:
When grub displays its boot
menu, it will wait this long
before automatically booting
the default item.
Image to display
behind the boot
menu.
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
default=0
10
Booting Windows:
This is the root for Grub,
but don't try to mount it
(noverify).
title Microsoft Windows XP
rootnoverify (hd0,0)
chainloader +1
11
file understands the resulting file's format, and can tell us a few things
about it: [root@demo ~]# file pbr.dat
pbr.dat: x86 boot sector,
Microsoft Windows XP Bootloader NTLDR,
code offset 0x58, OEM-ID "MSDOS5.0",
sectors/cluster 32, reserved sectors 38,
Media descriptor 0xf8,
heads 255, hidden sectors 63,
sectors 40965687 (volumes > 32 MB) ,
FAT (32 bit), sectors/FAT 9997,
reserved3 0x800000,
12
serial number 0xa4ea03af, unlabeled
It must by 640x480.
13
Password-Protecting Grub:
By default, the Grub menu allows a user to interactively edit the menu
entries to alter the way Grub boots the computer. This may be a security
risk if the computer is located in a public place. Because of this, Grub
allows you to password protect the menu, by adding a line like this to the
top of your grub.conf file:
password --md5 $1$m4OG./$.J9WAanGSa60d/aDj3RoH/
This specifies an MD5 hash of a plaintext password. To generate this
hash, you can use the grub-md5-crypt command:
[root@demo ~]# grub-md5-crypt
Password:
Retype password:
$1$m4OG./$.J9WAanGSa60d/aDj3RoH/
You can also password-protect a particular menu item by adding a
similar line under the title line for that item in your grub.conf file.
14
15
core.img
GRUB2
grub.cfg
*.mod
Grub2 supports png, jpeg and other image formats for splash images.
16
http://ubuntuforums.org/showthread.php?t=1369019
The Ubuntu distribution has used grub2 for a while now, and
most major distributions will probably move to it.
Grub2 is still a moving target, as you'll see in the pages linked
to above. The details of configuring it vary from one Ubuntu
version to the next, and between Ubuntu and other
distributions using grub2. Getting the results you want may
require some experimentation.
17
19
~]# ls
1 root
1 root
2 root
1 root
1 root
1 root
1 root
1 root
1 root
1 root
1 root
-l /boot
root
65411
root
65411
root
1024
root 3133534
root 3133544
root
91738
root
91760
root 912912
root 913350
root 1806900
root 1805940
Nov
Dec
Dec
Nov
Dec
Nov
Dec
Nov
Dec
Nov
Dec
12
16
17
13
17
12
16
12
16
12
16
09:54
12:28
01:38
03:18
01:36
09:54
12:28
09:54
12:28
09:54
12:28
config-2.6.18-92.1.18.el5
config-2.6.18-92.1.22.el5
grub
initrd-2.6.18-92.1.18.el5.img
initrd-2.6.18-92.1.22.el5.img
symvers-2.6.18-92.1.18.el5.gz
symvers-2.6.18-92.1.22.el5.gz
System.map-2.6.18-92.1.18.el5
System.map-2.6.18-92.1.22.el5
vmlinuz-2.6.18-92.1.18.el5
vmlinuz-2.6.18-92.1.22.el5
21
Kernel Modules:
Many parts of the Linux kernel can be built as modules. These kernel
modules can be dynamically loaded or unloaded, without rebooting the
computer. Most of them are drivers for particular devices, filesystems,
etc. The modules for a particular kernel usually live under /lib/modules,
in a directory specific to that kernel version. For example:
[root@demo ~]# ls /lib/modules/2.6.18-92.1.22.el5/drivers/net
3c59x.ko
dummy.ko
natsemi.ko
ppp_synctty.ko sunhme.ko
8139cp.ko
e1000
ne2k-pci.ko
qla3xxx.ko
tg3.ko
8139too.ko e1000e
netconsole.ko r8169.ko
tlan.ko
8390.ko
e100.ko
netxen
s2io.ko
tokenring
acenic.ko
epic100.ko
ns83820.ko
sis190.ko
tulip
amd8111e.ko fealnx.ko
pcmcia
sis900.ko
tun.ko
b44.ko
forcedeth.ko pcnet32.ko
skge.ko
typhoon.ko
bnx2.ko
ifb.ko
phy
sky2.ko
via-rhine.ko
bnx2x.ko
igb
ppp_async.ko
slhc.ko
via-vel.ko
bonding
ixgb
ppp_deflate.ko slip.ko
wireless
cassini.ko ixgbe
ppp_generic.ko starfire.ko
chelsio
mii.ko
ppp_mppe.ko
sundance.ko
cxgb3
mlx4
pppoe.ko
sungem.ko
dl2k.ko
myri10ge
pppox.ko
sungem_phy.ko
The files with names ending in .ko are kernel modules. Other files are
22
directories containing more modules.
Module Dependencies:
Each kernel module provides a set of symbols, representing functions
or variables. These functions and variables can be used by other
modules. Thus, some modules will require that other modules be
installed in order to function properly. For example, the module sndtrident-synth requires seventeen other modules:
snd-trident
snd-seq-instr
gameport
snd-page-alloc
snd-ac97-codec
snd-seq-midi-emul
ac97_bus
snd-seq
snd-pcm
snd-timer
snd-util-mem
snd-seq-device
snd-mpu401-uart
snd
snd-rawmidi
soundcore
snd-ainstr-simple
One tool to help figure out which modules need to be loaded is
depmod. When you run this command, the currently-running kernel's
modules will be examined, and dependency information will be written
into a file like /lib/modules/2.6.18-92.1.22.el5/modules.dep, for later
23
use.
Size
15809
51165
76705
10945
7617
11205
21101
123593
109380
53797
144893
9537
10713
7105
17029
21193
18533
10049
Used by
0
1 vfat
0
0
1
1
2 ipt_MASQUERADE,iptable_nat
2
0
5 hidp,rfcomm,l2cap
1
3
2 ip_nat,ip_conntrack
1
2 iptable_nat,iptable_filter
0
0
1 video
24
25
26
Module Parameters:
Some modules allow you to control their behavior by setting parameters
when the module is loaded.
[root@demo ~]# modinfo e1000
...
description: Intel(R) PRO/1000 Network Driver
author:
Intel Corporation, <linux.nics@intel.com>
...
depends:
vermagic:
2.6.18-92.1.22.el5 SMP mod_unload
686 REGPARM 4KSTACKS gcc-4.1
parm: Speed:Speed setting (array of int)
parm: Duplex:Duplex setting (array of int)
parm: AutoNeg:Advertised auto-negotiation setting (array of int)
parm: FlowControl:Flow Control setting (array of int)
parm: InterruptThrottleRate:Interrupt Throttling Rate (array of int)
parm: SmartPowerDownEnable:Enable PHY smart power down (array of int)
parm: debug:Debug level (0=none,...,16=all) (int)
...
We could load the e1000 ethernet controller driver and tell it to run at
1Gbps and full duplex:
[root@demo ~]# modprobe e1000 Speed=1000 Duplex=2
Documentation is left up to the author of the module, and may
sometimes be cryptic.
27
options
These are parameters that modprobe will pass to the given module,
28
by default, when it is loaded.
29
The result will be a tree of files in the junk directory. If necessary, you
can modify, add or remove files and create a new version of the initrd:
[root@demo ~]# find ~/junk | cpio -H newc -o > /boot/new-initrd.cpio
[root@demo ~]# gzip /boot/new-initrd.cpio
[root@demo ~]# mv /boot/new-initrd.cpio.gz /boot/new-initrd.img
30
etc/
`-- lvm/
`-- lvm.conf
init
lib/
|-- ata_piix.ko
|-- dm-mirror.ko
|-- dm-mod.ko
|-- dm-snapshot.ko
|-- dm-zero.ko
|-- ehci-hcd.ko
|-- ext3.ko
|-- firmware/
|-- jbd.ko
|-- libata.ko
|-- ohci-hcd.ko
|-- scsi_mod.ko
|-- sd_mod.ko
`-- uhci-hcd.ko
proc/
31
Kernel Version
A given initrd will only work with one version of the kernel, because
kernel modules are generally tied to a particular kernel version.
mkinitrd needs to know the intended kernel version so it can pack up
appropriate modules.
Normally, mkinitrd determines which modules to include by looking at
the computer on which it's running. If you want to force mkinitrd to
include some modules, you can use the --with switch:
[root@demo ~]# mkinitrd --with=e1000 --with=fglrx \
initrd-new.img 2.6.18-92.1.22
On Debian-based systems, you can use a similar tool called
mkinitramfs. Consult the man page for details.
32
33
34
~]#
~]#
~]#
~]#
cd /usr/src
tar xjvf linux-2.6.29.1.tar.bz2
cd linux-2.6.29.1
make mrproper
The make mrproper command will make sure the source tree is in a
pristine state, ready to build a new kernel.
Useful documentation in this tree includes:
README
This file in the top directory contains general information about
Linux, and some fairly detailed instructions for building the Linux
kernel from source code.
Documentation/kernel-parameters.txt
This file contains much useful information about the boot-time
parameters that can be passed to the Linux kernel.
35
36
This will give you a text-based menu interface for creating a .config file.
The End
38
Thanks!