The Boot Process: From Power Button to Login Screen
1. Waking Up the Machine
We press the power button, grab a coffee, and the login screen appears. It seems simple.
But in those few seconds, the computer performs a miraculous transition from a hunk of dead metal to a sentient machine capable of running applications.
This process is called Booting, short for "Bootstrapping".
It comes from the phrase "Pull yourself up by your bootstraps." Since software needs an OS to run, but the OS itself is software, who runs the OS?
The computer has to lift itself up, stage by stage.
Let's dissect the 6 stages of the Linux boot process. Understanding this is crucial for troubleshooting system failures (like the dreaded "Kernel Panic" or "Boot Loop").
2. Stage 1: BIOS / UEFI (Hardware Check)
When electricity flows into the motherboard, the CPU looks at a specific memory address mapped to the ROM (Read-Only Memory).
There resides the BIOS (Basic Input/Output System) or its modern successor, UEFI.
POST (Power-On Self-Test)
First, it checks its own body.
- Is RAM accessible?
- Is the Keyboard connected?
- Is the GPU responding?
If hardware is missing or broken, it beeps (beep codes). If everything is fine, it looks for a "Boot Device" (HDD, SSD, USB) based on the Boot Priority order set in BIOS settings.
Secure Boot
UEFI has a feature called "Secure Boot". It checks the digital signature of the bootloader to ensure it hasn't been tampered with by malware (Rootkits). If the signature doesn't match Microsoft's or the OEM's key, booting stops.
3. Stage 2: MBR / GUID (The First Sector)
Once the Boot Device is found, the BIOS reads the absolute first sector of that storage.
This sector (512 bytes) is called the MBR (Master Boot Record).
It's tiny but critical. It contains:
- Executable Code: The first part of the Bootloader.
- Partition Table: Defines how the disk is divided.
In modern UEFI systems, MBR is replaced by GPT (GUID Partition Table) and a special EFI System Partition (ESP). UEFI is smarter; it can read .efi files directly from the partition instead of relying on a magic raw sector. However, the concept is the same: Handover control to the Bootloader.
4. Stage 3: The Bootloader (GRUB)
The MBR code loads the full Bootloader. The standard for Linux is GRUB2 (GRand Unified Bootloader).
This is the screen where you see a menu:
- Ubuntu Linux
- Advanced Options for Ubuntu
- Windows Boot Manager
Dual Booting works here. GRUB scans the disks for other Operating Systems (like Windows) and adds them to this menu. If you choose Windows, GRUB hands over control to the Windows Boot Manager.
If you don't press anything, GRUB loads the default kernel image into memory.
Single User Mode (Recovery)
Sometimes you lose your password.
In the GRUB menu, you can edit the boot parameters by pressing e.
If you add init=/bin/bash to the end of the line starting with linux, you bypass the normal boot process and drop directly into a Root Shell without a password.
This is called Single User Mode. It's a powerful tool for fixing systems, but also a security risk if anyone has physical access to your machine.
5. Stage 4: The Kernel (The Heart)
The Kernel is the core of the operating system.
It is usually a compressed file (like vmlinuz) located in /boot.
Once loaded into RAM, it decompresses itself and takes full control of the hardware.
- Hardware Enumeration: It scans the bus (Check
dmesg output) and initializes drivers.
- Initramfs (Initial RAM Filesystem): This is crucial. Sometimes, the kernel needs to read the hard drive to load drivers, but the driver to read the hard drive is IN the hard drive!
- To solve this "chicken and egg" problem, a small temporary filesystem (
initrd.img) is loaded into RAM.
- It contains essential modules (RAID, LVM, Encryption drivers).
- Once the real root filesystem (
/) is mounted, initramfs is discarded.
Kernel Modules
The kernel is smart. It doesn't load every single driver for every possible device. It uses Modules.
Modules are pieces of code (.ko files) that can be loaded and unloaded on demand.
lsmod: List loaded modules.
modprobe: Load a module.
This keeps the core kernel small and efficient.
6. Stage 5: The Init Process (PID 1)
Now that the kernel is running and the disk is mounted, it needs to start "User Space" programs.
The kernel executes the first program: /sbin/init (or linked to /lib/systemd/systemd).
This process gets PID (Process ID) 1.
- It is the Immortal Process. It runs until shutdown.
- It is the parent of all other processes.
- It adopts orphaned processes.
Historically we used System V Init (SysVinit), but now Systemd is the de-facto standard. Systemd checks its configuration (default.target) to decide what to do next.
7. Stage 6: Services and Runlevels (Systemd Targets)
Systemd starts launching background services (Daemons) in parallel.
It follows a target dependency tree defined in Unit Files (.service).
sysinit.target: Basic system initialization (Swap, Filesystems).
multi-user.target (Runlevel 3): Network, SSH, Cron, Databases. (Text mode only).
graphical.target (Runlevel 5): Starts the Display Manager (GDM, LightDM) for the GUI login screen.
Unit Files
You can control these services using systemctl.
sudo systemctl start nginx
sudo systemctl enable nginx (Start on boot)
The unit files live in /etc/systemd/system/ or /lib/systemd/system/.
Once the Display Manager asks for your username/password and you login, a Shell session (like Bash or Zsh) is started.
Congratulations! The boot is complete.
8. Troubleshooting: Journalctl
When boot fails after the kernel loads, Systemd often captures the reason.
The journalctl command is your best friend here.
journalctl -b: Show logs from the current boot.
journalctl -b -1: Show logs from the previous boot (useful if it crashed).
journalctl -p 3 -xb: Show only errors (priority 3) and explanations.
systemd-analyze blame: Shows what took so long during boot.
Common boot failures:
- Beep noises, no screen? -> Stage 1 (BIOS/Hardware Failure). Reseat RAM.
- "Missing Operating System" -> Stage 2 (MBR/Disk Failure). Check boot order.
- GRUB Rescue prompt? -> Stage 3 (GRUB config broken).
- Kernel Panic text scroll? -> Stage 4. (Fatal error in kernel/drivers).
- Stuck at startup? -> Stage 6 (Systemd service hang).
The boot process is a relay race of software layers, each handing the baton to the next, building up abstraction until you can move your mouse.