You are on page 1of 7

=====================

The Linux Boot Process


LBP
======================
======
Part I
======

01. When the Computer is Switched on the SMPS(Switch Mode Power Supply)
gets on & starts generating voltage required by CPU, Motherboard &
Other Devices

02. The power is then supplied to the CPU, Motherboard & other devices

03. The CPU is made of lots of IC's. Out of numerous pin of the cpu,
the pin no. 66 called reset pin senses the power & starts the CPU

04. The Awakens CPU send signal to ROM chip on the motherboard which contains
BIOS which is made of 32 interrupts or programs(0 to 31)

05. Out of 32 interrupts, the interrupt no. 0 brings BIOS into RAM from
ROM & executes it.

06. This process of loading BIOS into RAM from ROM is Called "Boot Strapping"
or "Boot Strap Interrupt".

The Main Purpose of BIOS to Load the OS Any OS

07. BIOS is a Firmware which talks to the hardware

08. During Boot Sequence BIOS performes POST (Power On Self Test) to Check
all the hardware devices attached to the system are functioning properly
or not.

09. After Hardware Inventory if everything is ok then BIOS will at CMOS


(Complimentary Metal Oxide Semiconductor) setting to know what is boot
order.Boot Order nothing but user defined order which tells where to look
for OS.
The Order Will be Something Like This: a.CDROM b.HDD c.USB d.FLOPPY DISK

10. As per the boot order BIOS will first look at CDROM to check whether OS
can be loaded from here. If it does not find a bootable disk in the CDROM,
then it will check HDD for bootable OS, then USB & then Floppy disk.

11. Suppose you dont have bootable CD then BIOS will Turn to HDD,then it goes
to 1st Sector of your HDD i.e right in the begining of HDD. This area is
called MBR (Master Boot Record).

12. The Size of MBR is 512 bytes and it is divided into 3 parts :
a. Boot Sector b. Partition Table c. Magic No.

13. The Boot Sector is the first 446 bytes of the MBR.It contains the
boot loader binary (ntldr of windows & Grub of Linux) in highly
compressed form and address of the kernel in case of windows in CHS#
(Cylinder Head Sector) format.

14. The Partition Table is of 64 bytes immediately after the boot sector
which contains the whole partition information like how many partitions are
there, whether they are primary, extended or logical, which partition is
bootable.

15. The Magic No. is of 2 bytes. It contains only one number which represents
either Yes/Ok/True or No/Fail/False.

16. As soon as BIOS finds a MBR, loads its entire contents into RAM. This
process is called "First Stage of Boot Loading (FSBL)"

Boot Loader for Linux Kernel


a.First Stage Boot Loader(Grub Stage1) or IPL(Initial Program Loader)
b.Second Stage Boot Loader(Grub Stage2)

After Installing Linux, 7 items are put by anaconda in the Boot Sector
of MBR : 2 are binaries (Grub Stag1 & Stage2) and 5 are CHS nos pointing
to the files on the HDD.

1. /boot/grub/stage1 and 2. /boot/grub/Stage2 are binaries

CHS# a. /boot/grub/splash.xpm.gz
b. /boot/grub/stage2
c. /boot/vmlinuz-2.6.18-194.el5
d. /boot/initrd-2.6.18-194.el5.img
e. /boot/grub/grub.conf

17. BIOS then loads & excutes the first stage boot loader binary(Grub Stage1)
i.e[/boot/grub/stage1] from the BS of MBR into RAM.

18. The primary job of the 1st Stage BootLoader is to load 2nd Stage Bootloader
(Grub Stage2) i.e /boot/grub/stage2. GRUB stands for Grand Unified Boot
Loader is the combined name given to the different stages of Grub.

19. Grub Stage2 is in /boot/grub/stage2, which is a drive & a partition


you might have already configured grub configuration file. It contains
the kernel file location & name, its a partition how will grub access
this partition without file system driver.

20. We can access this file with the help of BIOS calls
Makes BIOS Calls -> Int 13H fn 8 --> "get drive parameters" &
Int 13H fn 2 --> "Read Sectors from drive"

21. The 1st Stage Boot Loader then request the BIOS for an Int 13 fn 2,that
gives back the CHS# of the 2nd Stage Boot Loader - /boot/grub/stage2
Here BIOS working like a driver -(which is actually /dev/sda? of
/boot/grub/stage2)

22. The 1st Stage Bootloader loads this 2nd Stage Bootloader into RAM
from the CHS# given by BIOS, executes it & hands over control to it.
BIOS now goes into high memory & remains there in sleep mode or state.

23. The 2nd Stage Bootloader is responsible for loading kernel & initrd
image files into RAM which are in the BS of MBR which were put by
anaconda at install time.
c. CHS# of the file /boot/vmlinuz-2.6.18-194.el5 and
D. CHS# of the file /boot/initrd-2.6.18-194.el5 and

24. The 2nd Stage Bootloader examines the binary format BS which contains
"grub.conf" and follow the instruction given there.

25. The SSBL requests BIOS for Int 13H fn 2, that gives back CHS# of the
/boot/grub/splash.xpm.gz file then SSBL executes it -This is the splash
screen.
BIOS is working like a driver here once again!

26. If you have multiple kernel images installed on your system, you can
choose which one to be executed. Splash screen waits for a seconds, if
you dont enter anything, then it will loads the default kernel image
as specified in the grub config file.

27. Now the SSBL wishes to loads the Linux Kernel into RAM, as instructed
by the binary format grub.conf file, which is in the BS of MBR, after
timing out or whatever the user chooses.

28. The SSBL once again requests BIOS for Int 13H fn 2, that gives back CHS#
of the kernel - /boot/vmlinuz-2.6.18.194.el5 file. Then SSBL loads and
executes Kernel image file into RAM.

29. Now Kernel is in RAM which is highly compressed image file.the SSBL
uncompress it & fills the memory with kernel memory structures(Nos of
executable files)which can be seen in the /proc virtual file system.

==================================
PART-II /sbin/init takes over
==================================

30. Now that kernel is in ram & is much more powerful and immensely
larger than the SSBL, it takes over control from grub stage2 &
makes yet another BIOS call Int 13H fn 2 for the initrd image file

31. Kernel uncompresses it in ram & create a mini file system as can be
seen if we look inside the initrd image file.

Here is a listing of the files inside this initrd image:


.
|-- bin
| |-- insmod
| |-- modprobe -> /sbin/nash
| `-- nash
|-- dev
| |-- console
| |-- null
| |-- ram
| |-- systty
| |-- tty1
| |-- tty2
| |-- tty3
| `-- tty4
|-- etc
|-- lib
| |-- ext3.o <---------- Actual device driver for a partition
| `-- jbd.o
|-- linuxrc <---------- Imp script run at initialization
|-- loopfs
|-- proc
|-- sbin -> bin
`-- sysroot

8 directories, 15 files
32. The kernel converts initrd into a "normal" RAM disk and frees the
memory used by initrd. initrd is mounted rw as root

33. The initrd image file contains actual device driver which help to access
HDD partitions and other hardware and also contains a script called
linuxrc that run at initialization.

34. When linuxrc script is executed,it is run with uid 0 and mounts
the "real" root file system and places the root file system at
the root directory using the pivot_root system call - on /initrd dir

The usual boot sequence (e.g. invocation of /sbin/init) is performed


on the root file system
The initrd file system is removed

35. Now Kernel executes /sbin/init into RAM & transfer the control to init
system daemon

36. /sbin/init examines /etc/inittab file & starts inittab in a subshell


called inittab shell and then it will look at the /etc/inittab
configuration file to see the default runlevel, after identifying
the default runlevel from /etc/inittab file, it uses that to load
all appropriate programs.

37. a. Now inittab shell executes /etc/rc.d/rc.sysinit in a subshell of


inittab shell called rc.sysinit shell.

1. rc.sysinit shell calls /etc/sysconfig/network sets the hostname


and checks whether NW card is present or not. if yes then sets
networking value yes. if netword card is not there then rc.sysinit
script sets the hostname to localhost & sets the networking value
no
2. After this rc.sysinit calls /etc/init.d/functions script in the same
env [i.e rc.sysinit] and sets global umask and path and defines no.of
shells functions within the rc.sysinit shell environment.

The most common functions are listed below:

/etc/init.d/functions
=====================
1 action() {
2 checkpid() {
3 confirm() {
4 daemon() {
5 echo_failure() {
6 echo_passed() {
7 echo_success() {
8 echo_warning() {
9 failure() {
10 killproc() {
11 passed() {
12 pidfileofproc() {
13 pidofproc() {
14 status() {
15 strstr() {
16 success() {
17 warning() {
# cat functions | grep \(\)|sort|nl -> command to no. of fns

3. It will displays the "Welcome to Red Hat..." from /etc/redhat-release


file and ask for interactive setup.

4. Runs dmesg binary which performs hardware inventory check &


display its contents on the screen and creates /var/log/dmesg

5. Mounts all local filesystems from /etc/fstab and updates /etc/mtab


Mount simply displays the contents of /etc/mtab

Now /etc/rc.d/rc.sysinit script ends !!

38. b. Now inittab shell executes another script /etc/rc.d/rc in a subshell of


/etc/inittab called rc shell.

1. In rc script previous and current renlevel get set & it will check
rc$runlevel.d in etc directory whether exist or not. then it will
run rc@runlevel.d script in a subshell of rc.Here all application
daemons starts and stops.

5 funstions in the script are :


1. start
2. stop
3. restart | reload
4. condrestart
5. status
2. Under /etc/rc$runlevel.d directory you would see programs starts
with S(startup) & K(killed). programs starts with S are used during
system startup and programs starts with K are used during shutdown

3. There are no. right next to S & K in the programs names.These are
sequence no.in which programs should be started or killed.

39. At last /etc/rc.d/rc.local script gets executed in a subshell of inittab


which starts optionl scripts.

40. c. update cmd is run bdflush only RH8 & before. Now part of the
/sbin/init daemon.

41. d. shutdown CAD(ctrl+alt+del)magic keys are set.

42. e. Then Poweroff & Poweron connectios are considered.

43. f. 6 mingettys are spawned with device drivers of terminals. all enter
sleep state except the first mingetty.

44. g. If runlevel 5 is set then script "predm" is executed. This examines


script /etc/sysconfig/desktop for dispmgr. with this inittab gets over

========
Part III
========
What is a getty : it is a program which opens a port, prompts for a
login name by running the /bin/login command, it is normally invoked by
init.
The mingetty daemon is used to listen for virtual console.

45. h. The one awaken mingetty loads device driver for terminal /dev/tty1
and executes /etc/issue file & magic cookies gets allowed.
[magic cookies allowed : see man mingetty]
46. mingetty then executes the /bin/login process & is then put in
sleep state by init.
47. /bin/login displays login then you login. After giving username
/bin/login executes /usr/bin/passwd which ask password from user
which then does authenticatin & authorization using PAM.
48. init then puts login daemon into sleep state and wakes up the mingetty
which now takes over.
49. mingetty checks for .hushlogin file in $HOME/$USER.if exits then
it will login quietly without displaying any message.
50. If $HOME/.hushlogin file does not exits then it does following:
i. executes lastlog* -u $USER using /var/log/lastlog
ii. executes /etc/motd (display message of the day)
iii.checks user mail, if any, using /var/spool/mail/$USER
51. Then init wakes up /bin/login process which takes over as independent
daemon & mingetty then goes into zombie state and later it is killed
by init.
52. /bin/login then loads /bin/bash which now takes over & put login into
sleep state.
53. Now bash executes /etc/profile script which sets system wide global
environment variables like PATH USER LOGNAME MAIL HISTSIZE HOSTNAME etc.
54. /etc/profile script executes two scripts /etc/inputrc and /etc/profile.d
/*.sh
55. /etc/inputrc script sets keyboard mappings (see ssty -a) and show
terminal characteristics (see man bash search for /bell-style)
56. /etc/profile.d/*.sh contains 13 scripts which gets executes.
The 13 scripts are as follow :
1. colorls.sh 2. glib2.sh 3.gnome-ssh-askpass.sh 4. krb5.sh
5. lam.sh 6. lang.sh 7.less.sh 8. mc.sh
9. pvm.sh 10. qt.sh 11. vim.sh 12.which-2.sh 13. xpvm.sh
57. i. Bash executes /etc/bashrc script which sets global aliases & shell
functions and also sets user's & root's final global umask.
58. Now bashrc executes another script called .bash_profile which is
user's personal profile & executes .bashrc(run after every command we
execute)
59. then .bash_history and .bash_logout.
60. After this finally we get the login propmt bash to type the various
command.

You might also like