Boot process

When a computer starts up the first thing that occurs is it send a signal to motherboard which in turn starts the power supply. After supplying the correct amount of power to each device, it send a signal called “Power OK” to BIOS which resides on motherboard.

The following are the 6 high level stages of a Linux boot process.

1. BIOS

BIOS stands for Basic Input/Output System

It performs some system integrity checks

Searches, loads and executes the boot loader programs

It looks for bootloader in cd-rom or hard drive. You can press a key during the BIOS startup to change the boot sequence.

Once the bootloader program is detechted and loaded into memory, BIOS gives the control it.

So, insimple terms BIOS loads and executes the MBR boot loader.

2. MBR

MBR stands for Master Boot Record.

It is loacated in the 1st sector of the bootable disk. Typically /dev/hda or /dev/sad
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

It contains information about GRUB

So, in simple terms MBR loads and executes the GRUB bootloader.

3. GRUB

GRUB stands for Grand Unified Bootloader

If you have multiple kernel images installed on your system, you can choose which one to be 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 file system.

GRUB configuration file is /boot/grub/grub.conf.

GRUB just loads and executes kernel and initrd images.

4. Kernel

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 executed by Linux kernel, it has the process id (PID) of 1. Check the pid with ps -ef |grep init

initrd stands for Initial RAM Disk

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 drives compiled inside, which helps it to access the hard drive partitions, and other hardwares.

5. Init

Looks at the /etc/inittab file to decide the Linux run level

Follwing are the available run levels.

0- halt ( Shutdown)

1- Single user mode (Maintanance mode)

2- Multiuser, without NFS

3- Full multiuser mode

4- unused

5- X11

6- reboot

Init identified 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 run level

Typically you would set the default run level to either 3 or 5.

6. Run levels programs

When the Linux system is booting up, you might see various services getting started. Those are the runlevel programs, executed from run level directory as defined by your run level.

Depending on your default init level setting, the system will execute the programs from one of the following directories.

Run level 0 – etc/rc.d/rc0.d/

Run level 1 – etc/rc.d/rc1.d/

Run level 2 – etc/rc.d/rc2.d/

Run level 3 – etc/rc.d/rc3.d/

Run level 4 – etc/rc.d/rc4.d/

Run level 5 – etc/rc.d/rc5.d/

Run level 6 – etc/rc.d/rc6.d/

To check the default run level in linux.

# who -r
 run-level 5 2016-09-23 07:28
#

or

# runlevel
N 5
#

Changing default runlevel to some other like 3

# vi /etc/inittab
# Default runlevel. The runlevels used 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:3:initdefault:
~

Now reboot the system and check in which runlevel it is

# init 6
# who -r
 run-level 3 2016-09-23 07:37
#

# runlevel
N 3
#

To start the grapical interface when you are in runlevel 3, use the following command

# startx

Change it back to runlevel 5 and reboot the system.

To see the version of the kernel use

# uname -r
2.6.32-358.el6.x86_64
#

The same information cab be see in /boot/grub/grub.conf

# cat /etc/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,0)
# kernel /vmlinuz-version ro root=/dev/sda3
# 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-358.el6.x86_64)
 root (hd0,0)
 kernel /vmlinuz-2.6.32-358.el6.x86_64 ro root=UUID=b6264c63-081b-4d31-bd crashkernel=auto KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
 initrd /initramfs-2.6.32-358.el6.x86_64.img
#
#

To check the architecture of the OS

# arch
x86_64
#
#uname -m
x86_64
#

 

Advertisements