Understanding the Linux Booting Process: A Step-by-Step Guide

 

Introduction

The Linux booting process is a crucial topic for system administrators, DevOps engineers, and cloud professionals. Understanding how a Linux system starts up can help troubleshoot boot issues, optimize performance, and customize startup processes.

In this blog post, we will break down the Linux boot process into clear, step-by-step stages, covering everything from BIOS initialization to user login.

1. The Linux Booting Process Overview

When you power on a Linux system, the boot process begins with BIOS (Basic Input/Output System) and proceeds through multiple stages before reaching the user login prompt.

Key Stages of the Boot Process:

1️⃣ BIOS Initialization
2️⃣ Bootloader Execution (MBR & GRUB/LILO)
3️⃣ Kernel Loading
4️⃣ Initial RAM Disk (initramfs)
5️⃣ Root Filesystem Mounting
6️⃣ System Initialization (systemd/init)
7️⃣ Runlevel/Target Processing
8️⃣ User Login

Each of these stages plays a critical role in ensuring a successful boot-up. Let’s dive into each one in detail.

2. Stage 1: BIOS Initialization

📌 What is BIOS?
BIOS (Basic Input/Output System) is the firmware stored in the motherboard’s ROM. It is responsible for initializing hardware components and locating the boot device (HDD, SSD, USB, etc.).

How BIOS Works in Linux Booting?

🔹 BIOS checks hardware (POST - Power-On Self-Test).
🔹 Reads boot priority settings from CMOS (Complementary Metal-Oxide-Semiconductor).
🔹 Locates the first bootable sector (MBR) from the boot device.
🔹 Loads the MBR (Master Boot Record) bootloader into memory.

3. Stage 2: Bootloader Execution (MBR & GRUB/LILO)

📌 What is MBR?
The Master Boot Record (MBR) is a 512-byte sector at the start of the bootable disk. It contains the bootloader (e.g., GRUB or LILO) and the partition table.

MBR Execution Process:

✅ BIOS loads MBR from the first sector (cylinder 0, head 1, sector 1) of the disk.
✅ MBR contains a small bootloader that loads a full bootloader (e.g., GRUB, LILO).

Bootloader Options in Linux:

🔹 GRUB (Grand Unified Bootloader) – Default in most modern Linux distributions.
🔹 LILO (Linux Loader) – Older bootloader, less commonly used today.

GRUB Bootloader Structure:

  • /boot/grub/grub.cfg – GRUB configuration file.
  • /boot/vmlinuz – Kernel image.
  • /boot/initramfs – Initial RAM Disk.
  • /boot/message – Splash screen.

Once the bootloader is executed, it loads the Linux kernel into memory.

4. Stage 3: Kernel Loading

📌 What is the Kernel?
The Linux kernel is the core of the operating system that manages hardware and system resources.

Steps in Kernel Loading:

✅ Bootloader loads vmlinuz (compressed kernel file) into memory.
✅ Loads initramfs (initial RAM disk) for temporary root filesystem.
✅ Kernel initializes hardware, drivers, and system services.

Key Kernel Modules:

🔹 JBD.ko – Journaled Block Device (HDD driver).
🔹 ext4.ko – EXT4 filesystem driver.
🔹 nash – Minimal shell for booting.

The kernel then mounts the root filesystem (/) in read-only mode.

5. Stage 4: Root Filesystem Mounting

What Happens in This Stage?

✅ The kernel mounts the root filesystem using the /dev/root device.
SETUPROOT: mount /dev/root / ro (mount root filesystem in read-only mode).
SWITCHROOT: mount /dev/sdaX ro (switch to the actual root filesystem).

📌 Why Read-Only Mounting?
The root filesystem is initially mounted in read-only mode to allow fsck (filesystem check) to run before making it writable.

6. Stage 5: System Initialization (systemd/init)

📌 What is init?
The init (or systemd in modern Linux) process is the first user-space process started by the kernel. It is responsible for starting all system services.

✅ The kernel executes /sbin/init after mounting the root filesystem.
init reads configuration from /etc/inittab (older Linux versions) or systemd targets (newer versions).

System Initialization Files:

🔹 /etc/inittab – Defines system runlevels (for SysVinit systems).
🔹 /etc/systemd/system/ – Contains systemd unit files (for systemd-based systems).
🔹 /etc/rc.sysinit – Loads hostname, network settings, and other boot tasks.

7. Stage 6: Runlevels and Service Management

What are Runlevels?

Runlevels determine which services start at boot:

RunlevelDescription
0Halt (Shutdown)
1Single-user mode
2Multi-user mode (No network)
3Multi-user mode (With network)
4Unused
5Graphical mode (GUI)
6Reboot

8. Stage 7: User Login Process

/sbin/mingetty manages login terminals (TTYs).
/bin/login prompts for a username.
/bin/passwd verifies the password.
/etc/passwd and /etc/shadow contain user authentication details.

Customization Options:

  • Modify /etc/motd (Message of the Day) to show a custom message after login.
  • Change the login prompt text by editing /etc/issue.
  • Modify the command prompt (PS1) in /etc/profile.

9. Post-Boot Customization (rc.local & Profile Settings)

/etc/rc.local – Runs custom commands after boot (e.g., start scripts, log messages).
/etc/profile.d/*.sh – Runs scripts for user environment settings.
/etc/bashrc – Configures shell settings (like umask, PS1 prompt).

To add a custom startup command, edit /etc/rc.local:

echo "Welcome to Linux Booting Guide!" > /etc/motd

This will display a custom welcome message after login.


Linux Booting Process – End-to-End Flow

[ Power ON ]  

      ↓  

[ BIOS Initialization ]  

   (POST: Hardware Check)  

      ↓  

[ Locate Boot Device (CMOS) ]  

      ↓  

[ Load Bootloader from MBR (GRUB/LILO) ]  

      ↓  

[ Select Kernel & Boot Parameters ]  

      ↓  

[ Load Kernel (vmlinuz) into Memory ]  

      ↓  

[ Load initramfs (Temporary Root FS) ]  

      ↓  

[ Kernel Initializes Hardware & Drivers ]  

      ↓  

[ Mount Root Filesystem (Read-Only) ]  

      ↓  

[ Execute /sbin/init (First User Process) ]  

      ↓  

[ Load System Initialization Files ]  

   (/etc/inittab or systemd Targets)  

      ↓  

[ Start Essential Services ]  

   (Networking, Udev, System Logging)  

      ↓  

[ Load Runlevel/Target Services ]  

      ↓  

[ Start User Login Prompt (mingetty) ]  

      ↓  

[ User Enters Credentials ]  

      ↓  

[ Authenticate via /etc/passwd & /etc/shadow ]  

      ↓  

[ Load User Profile & Shell (Bash) ]  

      ↓  

[ User Gains Access to the System ]  


Conclusion

Understanding the Linux boot process is essential for troubleshooting, performance optimization, and system customization.

📌 Key Takeaways:
✅ BIOS initializes hardware and loads MBR.
✅ MBR executes the bootloader (GRUB/LILO).
✅ Kernel is loaded along with initramfs.
✅ Root filesystem is mounted (first in read-only mode).
init or systemd manages system services.
✅ Runlevels (SysVinit) or targets (systemd) determine system state.
/bin/login handles user authentication.

💡 Want to dive deeper?
Comment below with your questions or requests for more Linux tutorials! 🚀

Comments

Popular posts from this blog

🔍 Why You Only See a Private IP Inside an AWS EC2 Instance — Even If It Has a Public IP

A Day in the Life of a DevOps Engineer – Roles & Responsibilities

Docker and Its Usage in DevOps – A Complete Guide