Contents

Linux Boot Process: Complete Guide from Power Button to Login

To be a solid systems engineer, you need to deeply understand the Linux boot process. Only by knowing “what normal looks like” can you quickly troubleshoot when things go wrong. This post walks through every stage from power button to login screen.

1. Boot Process Overview

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
┌─────────────────────────────────────────────────────────────────────────┐
                           POWER ON                                       
└───────────────────────────────┬─────────────────────────────────────────┘
                                
┌─────────────────────────────────────────────────────────────────────────┐
 1. BIOS/UEFI                                                            
    - Hardware self-test (POST)                                          
    - Load Bootloader                                                    
└───────────────────────────────┬─────────────────────────────────────────┘
                                
┌─────────────────────────────────────────────────────────────────────────┐
 2. Bootloader (GRUB2)                                                   
    - Display boot menu                                                  
    - Load Kernel + initramfs into memory                                
    - Pass boot parameters                                               
└───────────────────────────────┬─────────────────────────────────────────┘
                                
┌─────────────────────────────────────────────────────────────────────────┐
 3. Kernel Init                                                          
    - Decompress itself                                                  
    - Initialize hardware/interrupts/memory                              
    - Mount initramfs as temporary root                                  
    - Execute /init                                                      
└───────────────────────────────┬─────────────────────────────────────────┘
                                
┌─────────────────────────────────────────────────────────────────────────┐
 4. initramfs                                                            
    - Load essential drivers (disk, filesystem)                          
    - Find real root partition                                           
    - pivot_root to actual root filesystem                               
└───────────────────────────────┬─────────────────────────────────────────┘
                                
┌─────────────────────────────────────────────────────────────────────────┐
 5. Systemd (PID 1)                                                      
    - Start system services in parallel                                  
    - Mount other filesystems                                            
    - Reach target (default.target)                                      
└───────────────────────────────┬─────────────────────────────────────────┘
                                
┌─────────────────────────────────────────────────────────────────────────┐
 6. Login                                                                
    - getty (TTY) or Display Manager (GUI)                               
└─────────────────────────────────────────────────────────────────────────┘

2. Stage 1: BIOS/UEFI

2.1 BIOS vs UEFI

FeatureBIOS (Legacy)UEFI
Era19812005+
Boot methodMBR (Master Boot Record)GPT + EFI System Partition
Max disk size2TB9.4ZB (effectively unlimited)
Boot speedSlowerFaster
Secure BootNoYes

2.2 What It Does

  1. POST (Power-On Self-Test)

    • Check CPU, memory, graphics
    • One short beep = OK, continuous beeps = hardware failure
  2. Read boot device order

    • Configured in BIOS settings
    • Try hard drive, USB, network boot in sequence
  3. Load Bootloader

    • BIOS: Read first 512 bytes of MBR
    • UEFI: Read .efi file from ESP partition

2.3 Troubleshooting

Symptom: No response on boot or error messages

1
2
3
4
5
# Check boot mode
[ -d /sys/firmware/efi ] && echo "UEFI" || echo "BIOS"

# UEFI boot entry management
efibootmgr -v

3. Stage 2: GRUB2

3.1 GRUB2’s Job

  • Provide boot menu (multi-OS selection)
  • Load Kernel image into memory
  • Load initramfs into memory
  • Pass boot parameters to Kernel

3.2 Key Files

1
2
3
4
5
/boot/grub/grub.cfg           # Main config (auto-generated, don't edit directly)
/etc/default/grub             # User config
/etc/grub.d/                   # Config scripts
/boot/vmlinuz-*               # Kernel image
/boot/initrd.img-* or initramfs-*  # initramfs

3.3 grub.cfg Example

1
2
3
4
5
menuentry 'Ubuntu' --class ubuntu {
    set root='hd0,gpt2'
    linux /vmlinuz-5.15.0-generic root=UUID=xxxxx ro quiet splash
    initrd /initrd.img-5.15.0-generic
}

Breakdown:

  • set root: Partition containing Kernel
  • linux: Kernel path + boot parameters
  • root=UUID=xxx: Tells Kernel where real root partition is
  • initrd: initramfs path

3.4 Modify and Update

1
2
3
4
5
6
# Edit default parameters
sudo vim /etc/default/grub

# Regenerate grub.cfg
sudo update-grub   # Debian/Ubuntu
sudo grub2-mkconfig -o /boot/grub2/grub.cfg  # RHEL/CentOS

3.5 Troubleshooting

Symptom: Stuck at GRUB menu or grub rescue>

1
2
3
4
5
6
7
# At GRUB command line
grub> ls                    # List partitions
grub> ls (hd0,gpt2)/        # View partition contents
grub> set root=(hd0,gpt2)   # Set root
grub> linux /vmlinuz root=/dev/sda2
grub> initrd /initrd.img
grub> boot

4. Stage 3: Kernel Initialization

4.1 What Does the Kernel Do?

  1. Decompress itself (if compressed vmlinuz)
  2. Set CPU mode (real mode → protected mode → 64-bit long mode)
  3. Initialize memory management (page tables)
  4. Initialize interrupts (IDT)
  5. Initialize scheduler
  6. Mount initramfs as root
  7. Execute /init or /sbin/init

4.2 Boot Parameters

1
2
3
4
5
6
7
8
9
# View current boot parameters
cat /proc/cmdline

# Common parameters
root=UUID=xxx      # Root partition
ro / rw            # Read-only/read-write mount
quiet              # Reduce output
init=/bin/bash     # Specify init program (rescue mode)
single / 1         # Single-user mode

4.3 Troubleshooting

Symptom: Kernel panic

1
2
3
4
# Common causes
1. root= points to non-existent device
2. initramfs corrupted
3. Required driver not compiled in kernel and not in initramfs

Solutions:

  • Enter GRUB command line, modify root parameter
  • Use Live CD to regenerate initramfs
1
2
3
4
5
6
7
# Using Live CD
mount /dev/sda2 /mnt
mount --bind /dev /mnt/dev
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys
chroot /mnt
update-initramfs -u -k all

5. Stage 4: initramfs

5.1 Why Do We Need initramfs?

Chicken and egg problem:

  • To mount root filesystem, need drivers
  • Drivers are in root filesystem
  • Root filesystem isn’t mounted yet…

Solution: initramfs is a temporary in-memory filesystem containing the minimal driver set needed to mount the real root.

5.2 initramfs Contents

1
2
3
4
5
6
7
8
9
# View initramfs contents
lsinitramfs /boot/initrd.img-$(uname -r) | head -50

# Typical structure
/init                       # Startup script
/bin/                       # busybox tools
/lib/modules/              # Driver modules
/etc/                       # Config
/scripts/                   # Init scripts

5.3 Workflow

1
2
3
4
5
6
7
1. Kernel decompresses initramfs into memory
2. Mounts as temporary root (/)
3. Executes /init script
4. Loads essential drivers (SATA/NVMe/LVM/encryption etc)
5. Finds real root partition
6. pivot_root or switch_root to real root
7. Executes /sbin/init (Systemd) on real root

5.4 Troubleshooting

Symptom: Dropped to initramfs shell

1
2
3
4
5
6
7
8
# initramfs gives you a busybox shell
(initramfs) # Check devices
(initramfs) blkid
(initramfs) ls /dev/sd*

# Manually try mounting root partition
(initramfs) mount /dev/sda2 /root
(initramfs) ls /root

Regenerate:

1
2
3
4
5
# Debian/Ubuntu
update-initramfs -u

# RHEL/CentOS
dracut -f

6. Stage 5: Systemd

6.1 What is Systemd?

Systemd is the init system for modern Linux distros, PID is always 1. It handles:

  • Starting and managing system services
  • Mounting filesystems
  • Managing user logins
  • Log management (journald)

6.2 Targets

Systemd uses targets instead of traditional runlevels:

RunlevelTargetPurpose
0poweroff.targetShutdown
1rescue.targetSingle-user/rescue mode
3multi-user.targetMulti-user CLI
5graphical.targetGUI
6reboot.targetReboot
1
2
3
4
5
6
7
8
# View default target
systemctl get-default

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

# Temporarily switch target
systemctl isolate rescue.target

6.3 Service Dependencies

1
2
3
4
5
6
# View service dependencies
systemctl list-dependencies sshd.service

# View startup order
systemctl list-dependencies --before sshd.service
systemctl list-dependencies --after sshd.service

6.4 Troubleshooting

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# View failed services
systemctl --failed

# View service logs
journalctl -u sshd.service -b

# View boot logs
journalctl -b

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

7. Practical: Customizing Boot Process

7.1 Add Script to Run at Boot

Method 1: rc.local (compatibility)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# Create rc-local.service
cat > /etc/systemd/system/rc-local.service << 'EOF'
[Unit]
Description=rc.local Compatibility
After=network.target

[Service]
Type=oneshot
ExecStart=/etc/rc.local
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
EOF

# Create script
echo '#!/bin/bash
echo "Hello from rc.local" > /tmp/boot-test
' > /etc/rc.local
chmod +x /etc/rc.local

# Enable
systemctl enable rc-local.service

Method 2: Create Systemd Service (recommended)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
cat > /etc/systemd/system/my-startup.service << 'EOF'
[Unit]
Description=My Startup Script
After=network.target

[Service]
Type=oneshot
ExecStart=/usr/local/bin/my-startup.sh

[Install]
WantedBy=multi-user.target
EOF

systemctl enable my-startup.service

7.2 Debugging Boot Issues

Strategy 1: Increase output

Remove quiet splash from GRUB, add debug parameter.

Strategy 2: Use serial console

1
2
# GRUB parameter
console=ttyS0,115200n8 console=tty0

Strategy 3: Enter rescue mode

At GRUB menu press e, append init=/bin/bash to linux line.

8. Summary

StageKey ComponentDebug Entry Point
BIOS/UEFIFirmware settingsF2/DEL to enter setup
GRUB/boot/grub/grub.cfgGRUB command line
Kernelvmlinuz + parametersBoot parameter debugging
initramfs/init scriptinitramfs shell
Systemdservice/targetjournalctl

Key insight: Each stage does one thing — prepare the environment for the next stage. Once you understand this chain, you’ll know where to look when things break.