Booting Procedure of Linux in details
When You press power button on your system, and
after few moments you see the Linux login prompt.
Have you ever wonderd what happens behind the scenes
from the time you press the power button until the Linux login prompt appears?
The
following are the 6 high level stages of a typical Linux boot process.
BIOS
|
Basic input/output System
executes MBR
|
MBR
|
Master boot record executes
GRUB
|
GRUB
|
Grand Unified Bootloader
Executes Kernel
|
KERNEL
|
Kernel executes /sbin/init
|
INIT
|
Init executes runlevel programs
|
RUNLEVEL
|
Runlevel programs are executed
from /etc/rc.d/rc*.d/
|
BIOS:
- BIOS stands for Basic Input/Output System
- This is the first thing which loads once you press power button on your machine.
- When you press the power button of the machine, CPU looks out into ROM for further instruction.
- The ROM contains JUMP function in the form of instrucion which tells the CPU to bring up the BIOS
- BIOS Performs some system integrity checks
- Searches, loads, and executes the boot loader program.
- It looks for boot loader in floppy,cd-rom, or hard drive. You can press a key (typically F12 or F2, but it depends on your system) during the BIOS startup to chaange the boot sequence.
- Once the boot loader program is detected and loaded into the memory, BIOS gives the control to it.
- So, in simple terms Bios loads executes the MBR boot loader.
MBR:
- MBR stands for Master Boot Record.
- It is located in the 1st sector of the bootable disk. Typically /dev/had, or/dev/sda
- MBR is less than 512 bytes in size. This has three components
- primary boot loader info in 1st 446 bytes
- partition table info in next 64 bytes
- MBR validation check in last 2 bytes
GRUB:
GRUB stands for Grand Unified Bootloader.
This loads the kernel into 3 stages
Stage
1:
The primary boot loader takes up less than 512 bytes
of disk space in the MBR - too small a space to contain the instructions
necessary to load a complex operating system.
Instead the primary boot loader performs the
function of loading either the stage 1.5 or stage 2 boot loader.
Stage
1.5:
Stage 1 can load the stage 2 directly, but it is
normally set up to load the stage 1.5.
This can happen when the /boot partition is situated
beyond the 1024 cylinder head of the hard drive.
GRUB Stage 1.5 is located in the first 30 KB of Hard
Disk immediately after MBR and before the first partition.
This space is utilized to store file system drivers
and modules.
This enabled stage 1.5 to load stage 2 to load from
any known location on the file system i.e. /boot/grub
Stage
2:
This is responsible for loading kernel from
/boot/grub/grub.conf and any other modules needed
Loads a GUI interface i.e. splash image located at
/grub/splash.xpm.gz with list of available kernels where you can manually
select the kernel or else after the default timeout value the selected kernel
will boot
- If you have multiple kernel images installed on your system, you can choose which one to executed.
- GRUB displays a splash screen, waits for few seconds, if you don’t enter anything, it loads the default kernel image as specified in the grub configuration file.
- Grub has the knowledge of the filesystem (the older linux loader LILO didn’t understand filesystem)
- GRUB configuration file is /boot/grub/grub.conf (/etc/grub.conf is a link to this). The following is sample of grub.conf file.
#
grub.conf generated by anaconda
#
#
Note that you do not have to rerun grub after making changes to this file
#
NOTICE: You have a /boot
partition. This means that
# all kernel and initrd paths are
relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro
root=/dev/sda2
# initrd
/initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title
Red Hat Enterprise Linux (2.6.32-71.el6.x86_64)
root (hd0,0)
kernel /vmlinuz-2.6.32-71.el6.x86_64
ro root=UUID=4afa457a-d662-4e89-b4e2-09303c44c3eb rd_NO_LUKS rd_NO_LVM
rd_NO_MD rd_NO_DM LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc
KEYTABLE=us crashkernel=auto rhgb quiet
initrd
/initramfs-2.6.32-71.el6.x86_64.img
|
- As you notice from the above info, it contains kernel and initrd image.
- So, in simple terms GRUB just loads and executes kernel and initrd images.
KERNEL:
- This can be considered the heart of operating system responsible for handling all system processes.
- Mounts the root file system as specified in the “root=” in grub.conf
- Kernel Executes the /Sbin/init program
- Since init was the 1st program to be executed by Linux Kernel, It has the process id(PID) of 1. Do a `ps-ef |grep init’ and check the pid.
- Initrd stands for initial RAM disk.
- Kernel as soon as it is loaded configures hardware and memory allocated to the system.
- Initrd is used by kernel as temporary root file system until kernel is booted and the real root file system is mounted. It also contains necessary drivers complied inside, which helps it to access the hard drive partitions, and other hardware.
InIt:
- Executes the system to boot into the run level as specified in /etc/inittab
- Following are available run lavels inside /etc/inittab file
# Default runlevel. The runlevels used by RHS are:
# 0 - halt
(Do NOT set initdefault to this)
# 1 - Single
user mode
# 2 -
Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full
multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot
(Do NOT set initdefault to this)
#
id:5:initdefault:
- Init identifies the default initlevel from /etc/inittab and uses that to load all appropriate program.
- Execute 'grep initdefault /etc/inittab' on your system to identify the default runlavel.
- Typically you would set the default run level to either 3 or 5.
RUNLEVEL
Programs:
- Depending on your default init level setting, the system will execute the programs from one of the following directories.
Runlevel Directory
- Runlevel 0 /etc/rc.d/rc0.d
- Runlevel 1 /etc/rc.d/rc1.d
- Runlevel 2 /etc/rc.d/rc2.d
- Runlevel 3 /etc/rc.d/rc3.d
- Runlevel 4 /etc/rc.d/rc4.d
- Runlevel 5 /etc/rc.d/rc5.d
- Runlevel 6 /etc/rc.d/rc6.d
- Programs used for runlevels 0 to 6 are located in subdirectories /etc/rc.d/rc0.d through /etc/rc.d/rc6.d, respectively.
- When the linux system is booting up, you might see various services getting started. For example, it might say “starting sendmail….OK”. Those are the run level programs, executed from the run level directory as defined by your run level.
Post a Comment