Skip to content

Boot Process

Complete Boot Flow

graph LR
    A[Power On] --> B[BIOS/UEFI]
    B --> C[Bootloader GRUB]
    C --> D[Kernel]
    D --> E[initramfs]
    E --> F[systemd/init]
    F --> G[Userspace Services]

1. BIOS/UEFI

BIOS (Legacy): - Power-On Self-Test (POST) - Hardware initialization - Reads MBR (first 512 bytes of disk) - Loads bootloader

UEFI (Modern): - Faster boot - Reads GPT partition table - Can load from ESP (EFI System Partition) - More secure (Secure Boot)

# Check if UEFI or BIOS
[ -d /sys/firmware/efi ] && echo "UEFI" || echo "BIOS"

2. Bootloader (GRUB)

GRUB (GRand Unified Bootloader) loads the kernel.

GRUB Stages: 1. Stage 1: MBR/ESP, loads Stage 2 2. Stage 2: Filesystem access, presents menu 3. Loads kernel and initramfs

# GRUB configuration
/boot/grub/grub.cfg
/etc/default/grub

# Update GRUB
update-grub
grub2-mkconfig -o /boot/grub2/grub.cfg

Kernel parameters (example):

linux /vmlinuz-5.10.0 root=/dev/sda1 ro quiet splash

3. Kernel Initialization

Kernel loading: 1. Decompress kernel (if compressed) 2. Initialize memory management 3. Initialize CPU, interrupts 4. Mount root filesystem (read-only initially) 5. Start init process (PID 1)

# View kernel messages
dmesg
journalctl -k

# Kernel command line
cat /proc/cmdline

4. initramfs/initrd

initramfs (initial RAM filesystem): Temporary root filesystem in RAM.

Purpose: - Load drivers needed to mount real root filesystem - RAID/LVM setup - Decrypt encrypted volumes - Network boot support

# List initramfs contents
lsinitramfs /boot/initramfs-$(uname -r).img
zcat /boot/initrd.img-$(uname -r) | cpio -t

# Rebuild initramfs
update-initramfs -u
dracut --force

5. init/systemd

systemd (Modern)

First process (PID 1), manages services and system state.

Units: - Services (.service) - Targets (.target) - groups of units - Mounts (.mount) - Sockets (.socket)

Targets (like runlevels): - poweroff.target - rescue.target (single user) - multi-user.target (multi-user, no GUI) - graphical.target (GUI)

# View default target
systemctl get-default

# Change target
systemctl set-default multi-user.target

# Boot to specific target
systemctl isolate rescue.target

# View boot time
systemd-analyze
systemd-analyze blame
systemd-analyze critical-chain

SysV init (Legacy)

Runlevels: - 0: Halt - 1: Single user - 2-5: Multi-user (varies by distro) - 6: Reboot

# Init scripts
/etc/init.d/
/etc/rc*.d/

# Change runlevel
init 3
telinit 1

6. Userspace Services

systemd starts configured services.

# List running services
systemctl list-units --type=service

# Start/stop service
systemctl start nginx
systemctl stop nginx
systemctl restart nginx
systemctl reload nginx

# Enable/disable (auto-start)
systemctl enable nginx
systemctl disable nginx

# View service status
systemctl status nginx
journalctl -u nginx

Boot Troubleshooting

GRUB Rescue

# If GRUB fails
grub rescue> ls
grub rescue> set root=(hd0,1)
grub rescue> linux /vmlinuz root=/dev/sda1
grub rescue> initrd /initrd.img
grub rescue> boot

Single User Mode

# Edit GRUB entry (press 'e')
# Add to kernel line:
single
# or
systemd.unit=rescue.target

# Press Ctrl+X to boot

Recovery

# Boot from live CD
# Mount root filesystem
mount /dev/sda1 /mnt
mount --bind /dev /mnt/dev
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys

# Chroot
chroot /mnt

# Fix issues, reinstall GRUB if needed
grub-install /dev/sda
update-grub

Practice Questions

  1. Explain the complete boot process from power-on.
  2. What is the purpose of initramfs?
  3. What is the difference between BIOS and UEFI?
  4. How do you boot into single user mode?
  5. What does systemd do?
  6. Explain the difference between targets and runlevels.
  7. How would you troubleshoot a system that won't boot?

Further Reading

  • man bootup
  • man systemd
  • /usr/share/doc/systemd/