THE LINUX BOOT PROCESS MBR|BIOS|KERNEL

Majority of us overlook the importance of understanding what always happens from the time we press the power button on our systems to the time when the Linux login prompt appears.

Remember 96.3% of the world’s top 1 million servers run on linux.(https://hostingtribunal.com/blog/linux-statistics/#gref). As a software engineer you can be sure to interact with a linux server at one point in your career. With this in mind lets dive in and understand every bit of this process.

The linux boot process.

linuxboot 1

BIOS.

BIOS is an acronym for basic input/output system. It was first introduced by Gary Kildall and American computer scientist.

It is the firmware that a computer’s microprocessor uses to initialize the hardware. It always comes preinstalled but can be installed by the user.

Traditionally BIOS firmware was stored in EPROM(Erasable Programmable Read Only memory) chip on the pc motherboard. But in modern systems, it is stored in flash memory for ease of rewriting without removing the chip from the motherboard. Flash memory is developed from EEPROM(Electrically Erasable Read Only Memory). It is a non-volatile chip, ie it retains its contents even when the system is powered off. Since it is Electrically Erasable, it can be updated or rewritten. This has made the process of writing or updating BIOS way too easy. Traditionally you had to remove the EPROM chip, install a new one or have the manufacturer re-program it.

The CMOS(Complementary metal oxide semiconductor) chip stores BIOS settings. The CMOS chip is powered via a cmos battery. This explains why for you to reset the BIOS you have to reset the BIOS you have to remove the battery and re-attach it.

When the laptop is powered on, the microprocessor starts executing BIOS instructions on the EEPROM chip. The following diagram shows an overview of how these instructions initialize the hardware and load the operating system into the RAM.(Random access memory).

BIOS

Going into details:

The BIOS instructions also perform basic system integrity checks. BIOS then searches, loads and executes the boot loader program which resides in the Master Boot Record(MBR). Depending on your system the MBR can be located in a hard drive, cd-rom, floppy disk or a solid state drive. After the boot loader program is detected and loaded into memory, BIOS hands over the control of the system to it.

MBR

Is an acronym for Master Boot Record. It is located in the first sector of the bootable disk. Normally dev/sda. It contains information about GRUB. Basically its role is to load and execute the GRUB boot loader.

GRUB

Is an acronym for Grand Unified Bootloader. It can alos be refferred to as GNU GRUB. It normally appears as a splash screen when you boot your computer. In a case where you have multiple kernel images installed, GRUB allows you to choose which one to load and execute. When the splash screen shows up and you don’t choose any kernel image, then GRUB loads the default kernel image. In most linux bases systems the GRUB configuration file is located in /boot/grub/grub.conf. Its role is just to load and execute the kernel image.

KERNEL

This is the main component of an operating system. It has full control over everything in the system. The kernel’s first task is to mount the root file system that is defined inside the grub configuration file we talked about earlier. After mounting the root file system, it executes the “Always first” program to be executed ie /sbin/init program. It has a PID of 1. On most of the linux based systems you can confirm this by running the following command from the terminal.

ps aux|head -n 2
sbinini

The kernel will then create a temporary root file system using initrd(Initial Ram Disk) or initramfs(Init Ram File system) until the actual file system is mounted on the hard disk from memory. This is done by the dracut daemon. Without going deeper, the difference between initrd and initramfs is that initrd is a block device which is unpacked so that it can be mounted at boot by the kernel while ninitramfs is unpacked via cpio(copy in, copy out) into memory

INIT

The init program executes all the run-level programs. A run-level is identified by a special number usually between 0 and 6.

A run level determines the mode in which an operating system will run. It determines what services are operating in that particular runlevel. Init looks for an init file, usually found at /etc/inittab to decide the linux run-level.

The following are the defined run-levels.

0……………………Halt. It is a symbolic link to poweroff.target, it shuts down the system.

1……………………Singler User mode, does not configure interfaces, start daemons, or allow non-root logins.

2……………………Does not configure network interfaces or start daemons.

3……………………Full multiuser mode.

4……………………Unused/undefined. It is user definable.

5……………………X11 forwarding.

6……………………Reboot. Restarts the system.

To check your run-level, run the following command.

who -r
runlevel

To change your run-level, use the following command.

init [run-level]

For example, init 3, to change the run-level to 3

RUN-LEVEL PROGRAMS.

Once init determines your set run-level, the system executes all the programs that fall under that level.

Normally when booting up, you might be able to see various services getting started, these are the run level programs. Eg you might see “[OK] Started Disk manager………….”

Location of run-level programs for different run-levels.

Run level 0/etc/rc0.d/
Run level 1/etc/rc1.d/
Run level 2/etc/rc2.d/
Run level 3/etc/rc3.d/
Run level 4/etc/rc4.d/
Run level 5/etc/rc5.d/
Run level 6/etc/rc6.d/

After all the run-level programs are started successfully, your OS will finally display the login prompt marking the end of the boot process.

A NOTE ON THE DIFFERENCE BETWEEN BIOS AND UEFI

UEFI stands for Unified Extensible Firmware Interface. It provides the same functionality as BIOS but with the following key differences:

UEFI is able to support drives up to 9 zettabytes, whereas BIOS supports only up to 2 terabytes.

UEFI offers secure boot as a security mechanism against unauthorized/unsigned applications which is not available in BIOS.

Compared to BIOS, UEFI has a faster boot time.

Despite these advantages that UEFI has over BIOS, you can still run BIOS especially if your had disk is less than 2TB or if you just don’t want to mess up with system firmware.

Feel fee to drop your comment.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x