Linux system boot process is important knowledge for understanding how the system works. Mastering the boot process helps with troubleshooting and system optimization.
BIOS/UEFI boot stage:
- BIOS (Basic Input/Output System):
- Traditional firmware interface
- Executes POST (Power-On Self-Test)
- Detects hardware devices
- Searches for bootable devices
- Loads MBR (Master Boot Record)
- UEFI (Unified Extensible Firmware Interface):
- Modern firmware interface
- Supports GPT partition table
- Faster boot speed
- Supports secure boot
- Loads EFI applications
Bootloader stage:
- GRUB (Grand Unified Bootloader):
- Most commonly used Linux bootloader
- Supports GRUB Legacy (0.97) and GRUB 2
- Configuration file: /boot/grub/grub.cfg (GRUB 2), /boot/grub/menu.lst (GRUB Legacy)
- Supports multi-boot for Linux, Windows, etc.
- Provides command-line interface for recovery
- LILO (Linux Loader):
- Traditional Linux bootloader
- Configuration file: /etc/lilo.conf
- Replaced by GRUB
- systemd-boot:
- Simple UEFI bootloader
- Configuration file: /boot/loader/entries/*.conf
- Suitable for simple boot scenarios
Kernel loading stage:
- Load kernel image: /boot/vmlinuz-*
- Load initramfs (initial RAM filesystem): /boot/initrd.img-*
- Kernel decompression and initialization
- Detect and initialize hardware devices
- Mount root filesystem
- Start init process (PID 1)
init process stage:
- SysVinit (traditional init system):
- Configuration file: /etc/inittab
- Runlevels: 0-6
- 0: shutdown
- 1: single user mode
- 2: multi-user mode (no network)
- 3: multi-user mode (with network)
- 4: unused
- 5: graphical mode
- 6: reboot
- Startup scripts: /etc/rc.d/rc*.d/ or /etc/rc*.d/
- Use chkconfig to manage services
- systemd (modern init system):
- Configuration file: /etc/systemd/system/
- Targets: similar to runlevels
- poweroff.target: shutdown
- rescue.target: rescue mode
- multi-user.target: multi-user mode
- graphical.target: graphical mode
- reboot.target: reboot
- Use systemctl to manage services
- Supports parallel booting, faster boot speed
- Better log integration (journalctl)
System service startup stage:
- SysVinit:
- Start services in runlevel order
- Execute scripts in /etc/rc.d/rcN.d/ directory
- Scripts starting with S indicate Start
- Scripts starting with K indicate Kill
- systemd:
- Start services in parallel
- Determine startup order based on dependencies
- Execute services defined in .service files
Login stage:
- Display login prompt
- User enters username and password
- Verify user credentials
- Start user shell
- Execute user configuration files: ~/.bash_profile, ~/.bashrc
Key files in boot process:
- /boot/grub/grub.cfg: GRUB 2 configuration file
- /boot/grub/menu.lst: GRUB Legacy configuration file
- /etc/inittab: SysVinit configuration file
- /etc/systemd/system/default.target: systemd default boot target
- /etc/fstab: filesystem mount configuration
- /etc/hostname: hostname configuration
- /etc/hosts: hostname to IP mapping
Boot troubleshooting:
- GRUB issues:
- Repair GRUB: grub-install /dev/sda
- Rebuild GRUB configuration: update-grub or grub2-mkconfig -o /boot/grub2/grub.cfg
- Enter GRUB command line: press 'c' key
- Kernel issues:
- View kernel logs: dmesg, journalctl -k
- Try recovery mode: select recovery mode in GRUB menu
- Boot with old kernel
- Filesystem issues:
- Repair filesystem: fsck /dev/sda1
- Check /etc/fstab configuration
- Service startup issues:
- View service status: systemctl status service
- View service logs: journalctl -u service
- Disable faulty service: systemctl disable service
Boot optimization:
- Reduce GRUB wait time: modify GRUB_TIMEOUT in /etc/default/grub
- Disable unnecessary startup services: systemctl disable service
- Use systemd-analyze to analyze boot time:
- systemd-analyze: view total boot time
- systemd-analyze blame: view service startup times
- systemd-analyze critical-chain: view critical boot chain
- Use parallel booting: systemd supports by default
- Optimize kernel parameters: modify GRUB_CMDLINE_LINUX in /etc/default/grub