Blog Single
Linux Boot Process
Step 1: BIOS (Basic Input Output System)

Once the Personal Computer (PC) is switched on, BIOS instruction will start. BIOS is used to perform hardware initialization during the booting process. The main job assigned to BIOS is POST (Power On Self Test). It is hardware self test checking.
The main two errors that occur during POST are:
 Fatal error. This occurs due to hardware problems
 Non fatal error. This occurs due to software problems

Main responsibilities of BIOS during POST are listed below:

  • 1. Verify CPU registers.
  • 2. Verify the integrity of the BIOS code itself.
  • 3. Verify some basic components like DMA, timer, interrupt controller.
  • 4. Find, size, and verify system main memory.
  • 5. Initialize BIOS
  • 6. Identify, organize, and select which devices are available for booting.

The beep sound after the POST indicates its result. A short beep while restart/start means normal POST – system is OK. Two short beeps mean POST error. The error code is shown on screen.

BIOS acts as an intermediary between computer CPU and Input/Output devices. This eliminates the need for the operating system and software. The system/server is always aware of the details of hardware and other I/O devices. If any hard disks or I/O devices is changed, the BIOS also needs to be updated.

BIOS is stored in EEPROM (Electrically Erasable Programmable ROM) / Flash memory. BIOS cannot be stored on a hard disk or other devices because it manages those devices.

BIOS is written in assembly language. After testing the system hardware and components it loads a master boot loader.

Step 2: Stage 1 Master Boot Loader (MBR)
What is Master Boot Loader (MBR)?

Master Boot Record, is the first place where boot loaders begins to start. MBR is a 512 byte sector located in the first sector of hard disk. MBR contains both program code and partition table details.

  On a computer with x86 architecture, the Master Boot Record (MBR) is the first 512 bytes of the boot drive that is read into memory by the BIOS.

  The first 446 bytes of that 512 bytes contain low-level boot code. For some bootloaders, the code in the MBR points to further bootloader code somewhere else on the disk or on another disk.

  The next 64 bytes contain the partition table for the disk.

  The last two bytes are the boot signature, which is used for error detection.

Step 3: Stage 2 Boot Loader

  The bootloader software runs when a computer starts. It is responsible for loading and transferring control to the kernel.
  The kernel then initializes the rest of the operating system. Many bootloaders are available.
  The most common bootloaders for Linux are LILO (LInux LOader) and GRUB (GRand Unified Bootloader).
  When booting from a hard disk, the BIOS starts by loading and executing boot loader code.

The MBR size is not enough sometimes to execute the complete boot loader code. Because, its size is larger than the available space in MBR. So booting has to be done in different stages. These stages are different in different boot loader on the system. After successfully MBR is executed then control will go to execute boot loader. It is called the kernel loader. The main task at this stage is to load the Linux kernel. So it is essential to know some basic details of Linux boot loaders.

The common boot loaders in Linux are listed below:
 LILO (Linux Loader)
 GRUB (Grand Unified Boot Loader)

GRUB is used since LILO has some disadvantages. One great thing about GRUB is that it has knowledge about the Linux file system. GRUB can load kernel from an storage file system. GRUB is a product of the GNU project. GRUB conforms to the multiboot specification, which allows it to load many free operating systems directly as well as to chain-load proprietary operating systems. GRUB understands file systems and kernel executable formats, allowing it to load an arbitrary operating system without recording the physical position of the kernel on the disk. The kernel can load just by specifying its file name, and the drive and partition where the kernel resides. As mentioned, the boot loader code is executing in different stages because of the size limit of MBR. These stages are different in different GRUB version.

These stages are mainly listed as follows:
 Stage 1 and Stage 2 : These are two essential stages
 Stage 1.5 : An optional stage

Stage 1 is an essential image used to boot up a Linux machine. This is usually embedded in an MBR or the boot sector of the partition. The maximum size of stage one image is 512 bytes because of the MBR size limit.
        Stage 1 does not understand file system. It loads stage 2 or stage 1.5 from local disk for further booting process. So it knows Linux file system details.

Stage 2, this is the core image of GRUB. Usually, this stage can be found usually in a file system (Not necessary). Stage 1.5 is actually a bridge between Stage 1 and Stage 2. Stage 1.5 will be installed into an area right after the MBR area. Boot loaders are loading from Stage 2.
Nowadays almost all Linux distributions are using GRUB as boot loader.

The latest GRUB is GRUB 2.

Both LILO and GRUB can configure as a primary boot loader (on MBR) or the secondary boot loader (on a bootable partition). Both work with supporting OS such as Linux, FreeBSD, NetBSD. They can also work with unsupported OS like Microsoft Windows.

Commonly using boot loader is GRUB and its configuration is also listed under the /etc folder.

GRUB has two versions. GRUB and the latest GRUB 2.

There are a lot of changes in these two versions of GRUB.

GRUB – /etc/grub.conf

This configuration is actually a link to /boot/grub/grub.conf.

All kernel details are included in this configuration file. Sample entries are pasted below:

GRUB 2 – /etc/grub2.cfg

This is actually a link to /boot/grub2/grub.cfg. The main difference between GRUB and GRUB 2 is that the configuration file cannot be edited for changing the kernel and other settings. However different grub2-* commands can be used for changing GRUB settings.
A sample configuration is pasted below:

The line starting from “menuentry” defines Kernels.

It is something complicated than GRUB . But it can be simply managed from command line.

At stage 2 of Linux booting process. In stage 2, GRUB is loaded from a known location in boot file system (/boot/grub).

This stage loads other required drives and kernel modules before reading the GRUB configuration file and displaying the boot menu. The familiar GRUB menu is now displayed on the monitor. The kernel can be selected from there.

Using cursor key we can choose desired kernel to load.

Step 4: Kernal Stage

Here the kernel stage begins. Kernel is in compressed format. The kernel can be selected from the GRUB menu. If not selected, the GRUB automatically load the default one in its configuration. The default kernel details can be changed from the GRUB configuration.

The selected kernel is now loaded into the memory. An image file containing the basic root file system with all kernel modules are then loaded into the memory. This image file is located under /boot and it is known as initramfs.

Initramfs, abbreviated from “initial RAM file system”, is the successor of initrd “initial ramdisk”. This image file contains the initial file system. The GRUB starts the kernel and tells the memory address of this image file. The kernel then mount this image file as a starter memory based root file system.

The kernel then starts to detect the hardware of the system. The root file system on disk takes over from the one in memory. The boot process then starts INIT (SYSTEMD) and the software daemons. Init or systemed (systemdaemon manager) is parent of all the process. Process ID (PID is 1 )

I will explain about grub2 details next article 
  • January 03,2020

    This Script is very useful and helpful to me. I learnt Good Knowledge on Linux Booting.

Write a comment
Your email address will not be published. Required fields are marked *
Notify me of new posts by email