The Booting Process:Linux

The Linux booting process can be broken down into 6 different stages. For legacy’s sake We’ll also take a look at the BIOS boot sequence. The stages could be divided into:

  1. BIOS [1]   |  UEFI [2]
  2. MBR [1]   |  GTP [2]
  3. GRUB
  4. Init
  5. RunLevel

 

Both BIOS and UEFI are firmware. Firmware are software that control and monitor systems. Typical examples are embedded systems. Firmware is usually stored in the non-volatile RAM or EPROM. To get a better idea the first two steps will be looked at together. First let’s look at BIOS systems. BIOS (Basic Input/Ouput System) is not that widely used nowadays. BIOS is used to initialize the hardware during the booting process. Now the next layer of software, the bootloader code (explained next), is to be loaded. Since the firmware do not really carry heavy code, BIOS does something very simple. The bootloader ( or atleast parts of the bootloader that can pull the rest up themselves) is located on the first 2 sectors of the primary hard disk, which is also known as MBR (Master Boot Record). UEFI (Unified Extended Firmware Interface) was basically created by IBM for their servers since BIOS had some limitations (1 MB addressable space etc.). The UEFI boot managers mainly look at global configuration variables that are stored on the NVRAM. These variables decide how the UEFI boot manager should act. The boot manager then proceeds to load the drivers etc into memory. To access the addresses of such programs UEFI systems use a format known as GPT (GUID Partition Table), a table that basically exists with pointers which act as global Identifiers of the partitions. The control is then passed on to the bootloaders.                                                                                                                   GRUB (Grand Unified Bootloader)is a bootloader. Bootloaders are programs that look for and load the first component of the OS into memory, known as bootstrap programs. Bootstrap Program are the programs that are directly responsible for loading the Operating System into memory. GRUB also gives us the option of choosing which OS to load in case we have multiple to choose from (the header image depicts this). There are about 150 different options to configure GRUB. GRUB has knowledge of the file system and basically runs the initrd image and the kernel. Initrd is basically a minimal file system containing the programs and data necessary to continue the booting process. That is when GRUB loads the kernel, the kernel may require to access critically important drivers and depending on their location, they may or may not be accessible to the kernel. The simplest solution would be to simply load all the drivers, but this is unnecessary and may slow down the booting process. Hence the creation of a preliminary root file system that would contain just enough of the loadable modules to give the kernel access to the rest of the hardware. So in short, it is the job of the bootloader (GRUB) to load the kernel (bootstrap program, rest of the kernel it pulls itself), load the initrd image (initial file system) and pass on control to the kernel.

The kernel then runs the init program located in /sbin/init. The init program looks at the default init run level from the /etc/inittab file and uses that level to load all the appropriate programs. The levels are defined as below:

  • 0 – halt
  • 1 – Single user mode
  • 2 – Multiuser, without NFS
  • 3 – Full multiuser mode
  • 4 – unused
  • 5 – X11
  • 6 – reboot

When linux systems boot, one may have noticed a screen similar to the image below. This is nothing but the kernel executing in the runlevel, defined previously, starting all the services required to complete bootup. This is typically how linux systems bootup.

027_start_services_b.png

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s