📱

Get Our Mobile App

Take your business learning on the go!

Download on the App StoreGet it on Google Play

How Does Linux Boot Process Work?

ByteByteGo4:44

Transcription

What really happens behind the scenes when you press that power button to boot up Linux? Today I'll give you an inside look.

The process starts when you press that power button to turn on your computer. First, a program called the BIOS or UEFI boots up. These are basically pieces of software that get all the main parts of your computer ready for action - we’re talking about the keyboard, screen, hard drives, and so on. UEFI is the newer kid on the block, offering faster boot times and better security features like Secure Boot, compared to the traditional BIOS.

One key difference between BIOS and UEFI is in their approach to disk storage. BIOS is tied to the Master Boot Record (MBR) system, which limits disk size to 2TB. UEFI, on the other hand, uses the GUID Partition Table (GPT), removing these size constraints and offering a more flexible and modern solution.

BIOS UEFI

BIOS is tied to the Master Boot Record (MBR) system, which limits disk size to 2TB.

Slower boot time

Less secure boot

UEFI, on the other hand, uses the GUID Partition Table (GPT), removing these size constraints and offering a more flexible and modern solution.

Faster boot time

Secure boot

Next, the BIOS or UEFI runs a check called the power-on self-test or POST. This test makes sure all the different hardware bits and pieces are working right before fully turning everything on. If POST finds a problem, it'll often show an error message on the screen.

Finally, if everything checks out with POST, the BIOS or UEFI needs to find and load up the boot loader software. The boot order is usually set to check the hard drive first, then USB drives or CDs if it doesn't find anything on the hard drive. You can customize this order in the BIOS settings if you want.

On a BIOS system, the boot loader code lives in the first little chunk of the hard drive called the Master Boot Record. For UEFI, there's a separate partition that stores files like the .efi boot loader file.

The key jobs for the boot loader are:

Locate the operating system kernel on the disk

Load the kernel into the computer's memory

Start running the kernel code

Some common boot loaders you might see are LILO and GRUB2. LILO, the Linux Loader, is pretty outdated and rarely used in modern distributions. GRUB2 is the most full-featured and widely used today. It can handle booting multiple operating systems, looks nice with graphical or text-based menus, and has a bunch of advanced options for power users.

So once GRUB2 loads itself up, it inserts the Linux kernel into memory and hands control over to the kernel to finish the startup process.

After the boot loader starts the kernel, the kernel takes over the computer's resources and starts initiating all the background processes and services. First it decompresses itself into memory, checks the hardware, and loads device drivers and other kernel modules.

Next, an initial process called init kicks off, which in modern Linux systems is typically Systemd. Systemd has replaced older init systems like SysVinit and Upstart and is the parent of all other processes on Linux.

Systemd has a ton of responsibilities to get the system booted and ready to use. It's checking for any remaining hardware that needs drivers loaded. It mounts up all your different file systems and disks so they're accessible. It starts launching all the background services you need like networking, sound, power management. It handles user logins once you get to the graphical prompt. And it loads up your desktop environment with the panels and menus.

Systemd uses target configuration files to decide which mode it should be booting into - something basic like multi-user text-only target, or the graphical target most of us use daily. Those targets kind of correspond to the old run levels from past Linux days if you've heard of those. Mostly now you just need to know Systemd handles initializing everything that needs to launch behind the scenes when starting up Linux.

And there you have it. We've unpacked the sequence of events that transform your computer hardware into a functioning Linux system when you press the power button.