15. The Boot Process
When a server crashes or fails to come back online after a restart, a SysAdmin must understand exactly how a Linux system boots in order to intervene at the correct stage.
15.1 The Boot Sequence
Section titled “15.1 The Boot Sequence”The Linux boot process follows a strict, sequential chain of events. If any step fails, the next step cannot begin.
BIOS / UEFI (Hardware Initialization) ↓ Bootloader (GRUB) ↓ Kernel (Core OS loaded into memory) ↓ initramfs (Temporary initial filesystem) ↓ systemd (PID 1 - The Init System) ↓ Services (Daemons, Network, Mounts) ↓ Login (TTY / SSH available)15.2 Detailed Boot Stages
Section titled “15.2 Detailed Boot Stages”1. BIOS vs UEFI
Section titled “1. BIOS vs UEFI”When power is applied to the motherboard, the firmware wakes up.
- BIOS (Basic Input/Output System): The legacy standard. It performs a POST (Power-On Self Test) and looks for the MBR (Master Boot Record) on the first sector of the hard drive.
- UEFI (Unified Extensible Firmware Interface): The modern standard. It reads the GPT (GUID Partition Table) and can understand filesystems well enough to load an
.efibootloader file directly.
2. The Bootloader (GRUB)
Section titled “2. The Bootloader (GRUB)”The firmware’s only job is to find the bootloader. In Linux, this is almost always GRUB2 (GRand Unified Bootloader).
- GRUB presents a menu allowing you to choose which OS or which specific Linux Kernel version you want to boot.
- Once a selection is made (or a timeout is reached), GRUB loads the selected Kernel and the
initramfsinto memory.
3. The Kernel & initramfs
Section titled “3. The Kernel & initramfs”- The Kernel: The core of the operating system takes control from GRUB. It probes the hardware and initializes the CPU and memory.
- initramfs (Initial RAM Filesystem): The kernel needs to mount the real root filesystem (
/), but the drivers required to read your specific hard drive (e.g., RAID, LVM, or encrypted disks) live on that hard drive! Theinitramfsis a tiny, temporary filesystem loaded into RAM that contains just enough drivers and kernel modules to find and mount the real/drive.
4. systemd (The Init System)
Section titled “4. systemd (The Init System)”Once the real root filesystem is mounted, the Kernel executes the very first process: PID 1. On modern systems, this is systemd.
systemdtakes over the boot process and begins spawning all other processes concurrently.
5. Targets and Services
Section titled “5. Targets and Services”Instead of legacy “Runlevels,” systemd boots to a specific Target.
systemdlooks at its default target (usuallymulti-user.targetfor servers, orgraphical.targetfor desktops).- It then calculates the dependencies for that target and starts all the required
.service,.socket, and.mountunits.
6. Login
Section titled “6. Login”Once the target is reached, systemd spawns getty processes for the physical TTY consoles and starts the sshd service, finally allowing users to log in.
15.3 Boot Troubleshooting & Recovery
Section titled “15.3 Boot Troubleshooting & Recovery”If a system won’t boot, you must intervene at the GRUB menu.
Booting into Recovery Mode
Section titled “Booting into Recovery Mode”If a bad service or configuration is preventing the server from booting completely, you can boot into a restricted environment.
- Reboot the server.
- When the GRUB menu appears, press
eto edit the boot parameters. - Find the line that starts with
linux. - Append
systemd.unit=rescue.targetto the end of the line. - Press
Ctrl + Xto boot. This drops you into a root shell with the filesystem mounted, allowing you to fix broken configurations or disable crashing services before returning to a normal boot.
Emergency Mode
Section titled “Emergency Mode”If the system cannot even mount the root filesystem (e.g., due to /etc/fstab errors), you need Emergency Mode.
- Follow the same steps above, but append
systemd.unit=emergency.target. - In this mode, the root filesystem is mounted as Read-Only. You must manually remount it as Read-Write (
mount -o remount,rw /) to fix your/etc/fstaberrors.
Checking Boot Logs
Section titled “Checking Boot Logs”If the system successfully booted but you suspect something failed along the way, you can read the kernel ring buffer and the systemd journal:
# View kernel hardware/driver initialization logsdmesg | less
# View the systemd boot logs for the current bootjournalctl -b