How Linux Boots ? Linux Boot-up procedure made easy.

If you are new to Linux and interested in Linux Boot process, you have reached the correct web-page.This article is for you.

Linux is a Open Source Operating System  developed by many programmers around the clock. Its a dynamically evolving Operating system used in various devices like Mobiles, Personal computers, Laptops, tablets etc.

If you are using a Linux PC (or a device)  in your daily life, it’s important to know how it boots and what steps are involved in its boot up process.

The moment you switch on a Linux device, you may notice various screen displayed during the initial stage of Linux Boot-up. Finally you will end up with a log-in prompt.

Are you curious to know what exactly happens between the power-up and the display of Login prompt ?  If you are, then lets see how Linux boots.

Linux Boot-up process involves mainly 4 steps:
1.    BIOS
2.    MBR (First Stage Bootloader)
3.    Kernel Loader (Second Stage Boot loader)
4.    Kernel

1. BIOS (Basic Input/Output System) :
  • Resides at the end of flash memory. This is a well- known location to a processor when the system is reset.
  • BIOS program is written into permanent read-only memory and is always available to use.
  • It provides the lowest level interface to peripheral devices and controls the first step of the boot process.
  • It performs a Power On Self-Test (POST) for all the hardware components in the system to make sure that all hardware’s are functional.
  • It checks if the computer is being started from a cool boot (off position) or from a warm boot (restarted).
  • It retrieves the information from CMOS (Complementary Metal Oxide Semiconductor) a batter operated memory chip on the motherboard that sotres time, data, and critical information of the computer.
  • Once  above steps are successful, based on the order of the bootable media selected in the BIOS, it boots up the Linux.
  • If Linux is installed in Hard-drive, it looks at the first sector of the Hard-disk for (MBR)  Master Boot Record. It loads MBR to memory and passes control to it.
2. MBR (First stage Boot Loader):
  • MBR is the first stage boot loader which is loaded into the RAM and executed. This boot loader is less than 512 bytes in length (a single sector) .
  • First 416 bytes is the Boot loader, the next 64 bytes is the partition table and 2 bytes of magic number. 
  • Job of boot loader is to load the second stage boot loader.
  •  It does this by looking through the partition table for an active partition. When active partition is found, it scans the remaining partition in the partition table and make sure that they are all inactive. When this is verified, the active partition is loaded into the RAM and executed.
  • From there on, second stage boot loader passes control to the kernel image and the kernel is decompressed and initialized.
3. Kernel Loader (Second stage Boot loader):
  • Once control reaches kernel loaders , its task is to load the Linux Kernel and optional initial RAM disk (initrd kernel).
  • This also checks the system hardware, enumerates the attached hardware devices, mounts the root device, and then loads the necessary kernel modules.
  • On success, it starts the first user-space program (init) and performs high level system initialization.
  • The first and second stage boot loader combined together are called LILO (Linux Loader) or GRUB (Grand Unified Boot loader) in X86 PC environment.
  • GRUB is superior to LILO. So, let’s know about GRUB.

GRUB:
  • GRUB includes knowledge of Linux File systems.
  • It can load a Linux Kernel from an ext2 or ext3 system.
  • Its loads Linux Kernel in three stage boot loader instead of above discussed two stage boot loaders.
  • Stage 1: Boots a stage 1.5 boot loader that understands the particular file system containing the Linux Kernel Image.
  • Once Stage 1.5 boot loader is up and running, stage 2 boot loader can be loaded.
  • With Stage 2 boot loader loaded, GRUB displays list of available kernels (as in /etc/grub.conf). It allows you to select a kernel and even amend it with additional kernel parameters.
  • Till here, with second stage boot loader in memory, the file system is verified, and default kernel image and initrd image are loaded into memory. With the image ready, the stage 2 boot loader invokes the kernel image.

4. Kernel:
  • Once kernel is loaded into the memory, it finds init in sbin and executes it.
  • Init is the parent or grandparent of  all the processes that start up automatically in Linux system.
  • Init reads the initialization file “/etc/inittab”. This instructs init to read an initial configuration script for the environment, which sets the path, starts swapping, checks the file systems , sets the clock , initializes serial ports etc.
  • Init continues to read /etc/inittab file, which describes how the system should be set up in each run level and sets the default run level.
  • Available run levels are generally described in /etc/inittab, which is partially shown below:
 #  
 # inittab  This file describes how the INIT process should set up  
 #      the system in a certain run-level.  
 # Default run level. The run levels 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)  
 #   
Runlevel selection can be done in /etc/inittab file.

Now based on run level selection, the Linux Kernel boots up and finishes the boot process and displays the login prompt for the user to input.

Note : System boot up process depends on the hardware that Linux is being booted on.
Please note that in this article we discussed about the boot process of Linux on X86 platforms.
This process may change for other platforms.

Comments

Popular posts from this blog

Linux Device Drivers - Part 4 : Linux Kernel Moduels (LKM) and types of LKM's

Linux Device Drivers Part - 5 : Building and Compiling Kernel Moduels

Linux Device Drivers - Part 13 : More on Device Numbers