How does a Linux computer boot?

How does a Linux computer boot?
Photo by Timur Garifov / Unsplash

You press the power button, maybe hear some beeps, and all of a sudden your login screen appears. Feels like magic right? Let's take a look at what is happening behind the scenes!

Motherboards, Firmware, Hardware, and Software

It's important to talk about a couple of things very quickly here before we dive in.

  • Hardware - Hardware refers to the physical components of a computer system or any electronic device. These are the tangible parts that can be touched and seen. Some examples would be the cpu, ram, hard drives, keyboards, printers etc.
  • Software - Software refers to a set of instructions, data, or programs used to operate computers and execute specific tasks. Software is intangible and is stored electronically. Examples of this could be Adobe Photoshop, Steam, discord, etc.
  • Firmware - Firmware is a specific type of software that provides low-level control for a device's specific hardware. It is typically embedded directly into the hardware components of a device. It's software that hardware needs to run.
  • When software runs it gets loaded into RAM (random access memory) so that the CPU (central processing unit) can read the software's instructions very quickly. RAM is extremely fast and is situated close to the processor to maximize speed.

Checking the System

First things first, your computer has to make sure that its hardware is funcitioning properly. This is done using Bios (basic input/output system) or UEFI (unified extensible firmware) which are essentially just the new and old ways of doing things. UEFI being the new way of doing things, we will focus on that.

UEFI checks to make sure that cpu, memory, harddrives, and USB devices are all functioning properly by undergoing POST (power on self test.) It then reads the boot order from the firmware settings to determine which device to boot from.

MBR/GPT and the Bootloader

Once the system is confident that it can boot properly, the motherboard attempts to boot from the first entry stored in its firmware. It's important that we briefly talk about partitions before moving forward.

A hard drive can be divided up into different "segments" called partitions. If you want you can have multiple partitions of multiple sizes, there are limitations on both of those, but for typical usage its pretty straight forward. For a 1 terabyte hard drive you may have something that looks like this:

/dev/sda1 512MB
/dev/sda2 512MB
/dev/sda3 100GB
/dev/sda4 899GB

Each of these are partitions, and each of them have a file system that lives on top of them. Filesystems are a bit beyond the scope of this article but just know that they likely each have different filesystem types. It's also important to know that BIOS will look for an MBR (master boot record) which tells the system where things are on the disk. UEFI disks will also have an MBR but that's just to prevent a BIOS based PC from thinking the disk is empty. UEFI will use GPT (Guid (globally unique identifier) Partition Table) instead.

GRUB

Assuming the system was previously installed on a hard drive we will now end up on the GRUB (GRand Unified Bootloader) splash page. GRUB's job is to load the linux kernel (in its compressed form its called vmlinuz) to ram. Once loaded into RAM the kernel is used to mount the hard drive where the operating system was installed. GRUB also loads a temporary root file system called initramfs, this contains drivers for disk controllers, filesystems, and other essential hardware components.

Linux really is just the kernel, which allows the computer to control the hardware connected to the motherboard. It's also modular, meaning that different modules can be loaded if the computer needs them to function, this way you only use what you need.

Init Systems

Once Grub has done its job, the kernel can now decompress itself, set up memory management, initialize hardware devices, and hand over the rest of the boot process to an init system.

An init system is kind of likerolling a snowball down a hill. Once the first process is started, it starts the next process in line. This is repeated until all of the other software that is necessary for the system to function is running.

During this process the real root file system is located and the system starts using it instead of the initramfs.

Once the init system has completed starting other necessary software, we eventually make our way to the login screen, where we can finally start using the system!


Thank you for taking a look at my breakdown of the boot process. We are going to be using this knowledge to dive into a bunch of different topics soon. Please take a moment to subscribe for members only content and check us out on Youtube.