Linux Booting Process


Introduction: 

Linux is Open source Operating System. We can check starting, stopping of operating system, where it loads specified programs using their particular configurations and permits you to change those configurations to control the boot process, and shuts down in a graceful and organized way. 

Beyond the question of controlling the boot or shutdown process, the open nature of Linux makes it much easier to determine the exact source of most problems associated with starting up or shutting down your system. A basic understanding of this process is quite beneficial to everybody who uses a Linux system.


Linux Booting Process


BIOS (Basic Input Output System): 

When Computer is booted; the processor looks at the end of the system memory for the BIOS (Basic Input/output System) and runs it. The BIOS program is written into permanent read-only memory and is always available for use. The BIOS provides the lowest level interface to peripheral devices and controls the first step of the boot process.

The BIOS tests the system and checks peripherals and system integrity. Then it checks the bootable device present, depends on the setting, and first checks floppy drive if present, and then checks hard drive. The BIOS looks for a Master Boot Record (MBR) starting at the first sector on the first hard drive, loads its contents into memory, then passes control to it.



MBR (Master Boot Record): 

MBR is located in the first sector of bootable device. MBR is less than 512 bytes in size. It has three components, 1st  contains primary boot loader info in 446 bytes, 2nd has partition table information in next 64 bytes and 3rd has info of mbr validation check in last 2 bytes. MBR contains instructions on how to load the GRUB (or LILO) boot-loader, using a pre-selected operating system. The MBR then loads the boot loader, which takes over the process (if the boot-loader is installed in the MBR).



GRUB: (Grand Unified Boot Loader): 

This boot method is called direct loading because instructions are used to directly load the operating system,with no intermediary code between the boot-loaders and the operating system's main files (such as the kernel). Microsoft's DOS and Windows operating systems completely overwrite anything on the MBR when they are installed without incorporating any of the current MBR's configurations. This destroys any other information stored in the MBR by other operating systems, such as Linux. Microsoft operating systems are loaded using a chain loading boot method. With this method, the MBR points to the first sector of the partition holding the operating system, where it finds the special files necessary to actually boot that operating system.

GRUB supports both boot methods, allowing you to use it with almost any operating system, most popular file systems, and almost any hard disk your BIOS can recognize.

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 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 grub.conf of Redhat. 




default=0
timeout=10
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux AS (2.6.8-1.523)
        root (hd0,0)
        kernel /vmlinuz-2.6.8-1.523 ro root=/dev/VolGroup00/LogVol00 rhgb quiet
        initrd /initrd-2.6.8-1.523.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: 

Kernel mounts the root file system as specified in the “root=” in grub.conf. Kernel executes the /sbin/init program.  init is the 1st program to be executed by Linux Kernel, it has the process id (PID) of 1. initrd stands for Initial RAM Disk. Kernel use initrd as a temporary basis to mount root file system until kernel is booted and the real root file system is mounted.



INIT: 

After the kernel is booted and initialized, the kernel starts the first user-space application.

In a Linux system, the first application started is commonly /sbin/init.


First, it runs the/etc/rc.d/rc.sysinit script, which sets the environment path, starts swap, checks the file systems, and executes all other steps required for system initialization. For example, most systems use a clock, so on them rc.sysinit reads the /etc/sysconfig/clock configuration file to initialize the hardware clock.




Runlevel: 

The init command then runs the /etc/inittab script to decide which run level OS has to come up.

Default run levels are as follows :


# 0 – halt (Do NOT set init default 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 init default to this)




The init program starts all of the background processes by looking in the appropriate rc directory for the runlevel specified as default in /etc/inittab. The rc directories are numbered to corresponds to the runlevel they represent. For instance, /etc/rc.d/rc5.d/ is the directory for runlevel 5.


In /etc/rc.d/rc5.d/ directory what are all files starting with “K” those responsible for Kill the process when system is rebooting or shouting down. And Starting “S” those responsible for Start the process.

After this the system finished Booting and you can login to system.






absolute vs relative Path                              Linux-distributors-flavours


No comments: