Linux Boot Process

Aryan Shrestha
6 min readDec 12, 2023

--

The Linux boot process consists of 4 distinct phases:

Bootstrap Phase

This is the first phase of Linux boot. It’s responsible for bringing up the hardware and testing the hardware, and it also finds the location of the bootloader which is necessary for us to move into phase two. We’re going to talk about three bootstrap options in this blog. BIOS, UEFI, and PXE.

  • BIOS and POST

BIOS, which is the basic input-output system is a legacy bootstrap that was used early on, it’s still used on older systems, and after BIOS happens, the system is going to initialize the power on self-test or POST. POST codes are very complicated. There are a lot of different POST codes that you can find if POST has errors, you’re going to hear beeps. Maybe sometimes you’ll see an error message depending on the motherboard. Take a look at Bioscentral if you need any help determining what those mean. Next, the BIOS looks through the list of devices for the bootloader to move on to that second phase, which is normally referred to as the boot or boot order in the BIOS menu and will happen if the BIOS searches the list to look at the devices to try and find bootloader code. What it’s looking for is the master boot record, the MBR, and that contains the bootloader codes that we use to move into phase two.

  • BIOS Depreciation

BIOS has been deprecated. It’s not able to keep up with modern hardware and advancements that we see today. Can’t boot drives larger than 2.1 terabytes. It has a limitation on the amount of memory addressing access, and it can only manage a limited number of devices.

  • UEFI/EFI Bootloader

Unified Extensible Firmware Interface is the replacement for BIOS. It can boot those larger drives. It can operate in a larger amount of memory space. This is configured in Linux with an EFI boot manager. UEFI looks for storage on a device with an EFI system partition ESP. Now, ESP is FAT32 formatted. Generally, you’re going to find that at boot EFI, and we’ll see that later in this blog as we get into those files. But once that ESP is found, you can load an OS or you can load a bootloader like GRUB, and if you want to get into heavy-duty detail on UEFI:

  • PXE

Preboot execution environment, also known as PXE is used to boot the server remotely. There are two requirements for PXE booting. The system has to have a network interface card that supports PXE, and the system has to have PXE enabled as the boot device, what happens then is when you power up the system, the NIC tries to obtain an IP address and then it transfers files over using TFTP, and then the system downloads the appropriate boot image from the TFTP servers, pxelinux.cfg directory.

Boot Options

  • ISO

ISO image is an image that holds the contents of a disk. Having that data in a file format rather than a physical CD or DVD is a much more effective method of distributing data. We may have files that are 9.9 gigs in size, good luck trying to fit that on a CD or DVD. But in the ISO format, we can download that and use that to perform operations on our system, we can download that and use that to perform operations on our system, we can also access the file remotely to install an operating system on a computer. There are a few methods that can be used to do so.

  • ISO — Remote Access Method
  1. Remote access to an ISO can be made via HTTP or FTP.
  2. Using FTP allows the data to be transferred bit-by-bit, and you can use Secure FTP(SFTP) across SSH port 22.
  3. Hypertext Transfer Protocol allows for connections over port 80.
  • NFS Boot

NFS boot is another remote booting method that uses network file systems, and an NFS server. A computer will boot with a kernel image, or it can get one from a TFTP server like we saw with PXE boot, and next the system will connect to that NFS server on the network and access that root file system that it needs to boot up.

Bootloader Phase: GRUB

GRUB stands for GRand Unified Bootloader. It’s not the little creepy crawly you see in the above image. It is the legacy bootloader that is used to bring up a Linux OS. The purpose of GRUB and all bootloaders is to load the Linux system kernel GRUB operates in stages. Those stages are:

Stage 1 and then is where the Bootstrap we saw finds GRUB on the master boot record, and it points to either stage 1.5 or stage 2. Now, GRUB may go to stage 1.5, right after that master boot record sector, before the first partition if it needs specific file system drivers. If you’re loading something wackier, you’re using an older version of Linux that doesn’t have the drivers that you need to boot up that particular file system, you’re going to go to stage 1.5, do not pass go, do not go to stage 2 before you get that loaded. From there, you will go to stage 2, which is stored on the first partition, and that presents the text menu we saw a couple of times now like a new bootloader menu that gives us options for selecting a kernel image.

Now, the GRUB menu is configured. What we see in them, and use configured. What we see in them and use configured from one of two files could be in grub.conf, or menu.lst. The default configuration file is actually /boot/grub/menu.lst, but some distributions use /boot/grub/grub.conf. GRUB still thinks it’s using the menu.lst, but it’s linked to grub.conf.

We can see in the above image here if you’ve seen the blue menu.lst, there’s an arrow pointing to grub.conf that’s known as an assembly. Now, the GRUB system allows you to boot up interactively, allows you to go in and change the way that you’re going to boot into the system.

The way that you can do that is by when you get to that GRUB boot menu, hit Escape. Then from there, you can hit Escape. Then from there, you can hit the arrow keys to move down between your lines, hit Enter to select the current line, and do all those wonderful things over there. I want to enumerate all of them here to save you some time, but hit pause, and look over those. If you have time on your system, please go ahead and play around with it.

Bootloader Phase: GRUB2

  • GRand Unified Bootloader -version 2 is a replacement for GRUB.
  • Any version newer than 1.98 is considered as GRUB2
  • To find out what version of GRUB you’re running use one of the following commands:

grub-install -V

grub2-install -V

GRUB2 Menu

  • GRUB2 settings are configured in two places.
  • /etc/default/grub controls configuration variables.
  • The directory /etc/grub.d contains scripts that build the GRUB boot menu.

Changing GRUB2

  • To make changes to GRUB2, you can edit /etc/default/grub.
  • You can also create a custom script in /etc/grub.d
  • After a user makes changes to GRUB2, you must execute the command grub2-mkconfig for the change tobe picked up.

--

--