From Power On to Login: The Linux Boot Process
The Linux boot process involves several steps, starting from powering on the machine to loading the operating system. Here’s a step-by-step explanation
1. Power On: “The Awakening”
- Description: When you press the power button, the computer’s hardware components (CPU, RAM, motherboard, etc.) are powered up. The CPU starts executing instructions from a predefined location in its firmware.
- Example: After powering on your PC or server, the fans spin up, and you might hear a beep (from the BIOS POST — Power-On Self-Test), indicating that the hardware check has begun.
2. BIOS/UEFI: “The Gatekeeper”
- Description: The BIOS (older systems) or UEFI (modern systems) initializes the hardware and checks devices like RAM and the keyboard. Then, it looks for a bootable device like a hard drive, USB, or CD-ROM. Once it finds one, it loads the bootloader from the first sector of that device (Master Boot Record — MBR or GUID Partition Table — GPT).
- Example: When you press a key like
Del
orF2
after turning on the machine, you can enter the BIOS/UEFI menu where you can set boot priorities or overclock CPU settings. - Practical Scenario: A user might set the boot priority to boot from a USB drive containing a Linux live image for installation.
3. Bootloader: “The Keymaster”
- Description: The bootloader, typically GRUB (GRand Unified Bootloader) or LILO, is responsible for loading the Linux kernel into memory. If multiple operating systems are installed, the bootloader presents a selection menu.
- Example: After BIOS/UEFI finishes, you see the GRUB menu with options like:
Ubuntu 22.04 Advanced options for Ubuntu Windows 10
- You can select which operating system to boot. Once selected, GRUB loads the kernel.
- Command:
sudo grub-install /dev/sda
- This command installs the GRUB bootloader on the primary hard drive (sda).
4. Kernel Initialization: “The Heartbeat”
- Description: The Linux kernel is the core of the operating system, responsible for hardware communication, memory management, and process scheduling. Once loaded, the kernel initializes all necessary drivers (e.g., disk, network, USB) and mounts the root filesystem (
/
). - Example: After selecting Ubuntu from GRUB, you see a lot of text flying by on the screen. These are kernel messages showing hardware being initialized, like:
[ 0.000000] Initializing cgroup subsys cpuset
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Linux version 5.15.0-50-generic (buildd@lcy02-amd64-036) (gcc version 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.1))
- Command:
uname -r
- This command displays the kernel version running.
5. Init Process: “The Maestro”
- Description: After the kernel loads, it starts the
init
process (orsystemd
in most modern Linux distributions). This is the first process that runs, and it has a process ID (PID) of 1. It is responsible for starting all other system processes, such as networking, logging, and other services. - Example: On most Linux systems today,
systemd
handles process management. For instance, when you run:
systemctl status
- You’ll see a list of all active services and their status, such as networking and SSH services.
- Command:
ps -p 1
- This command shows that
systemd
is the first process:
PID TTY TIME CMD
1 ? 00:00:03 systemd
6. Runlevel/Target: “The Conductor”
- Description: In the old SysV init system, a “runlevel” was used to define what state the machine should be in (e.g., single-user mode, multi-user mode, etc.). In
systemd
, the equivalent is called "target". The system can boot into different targets likemulti-user.target
(which supports multiple users and networking) orgraphical.target
(which includes a graphical interface). - Example: On a server system, the default target might be
multi-user.target
, meaning it boots into a text-based interface with networking enabled. A desktop system might boot intographical.target
for a graphical user interface (GUI). - Command:
systemctl get-default
- This shows the default target your system boots into (e.g.,
graphical.target
ormulti-user.target
).
7. Login Prompt: “The Gateway to Control”
- Description: Once the system reaches the final stage of booting, the user is presented with a login prompt. This can be either a command-line interface (CLI) or a graphical login screen, depending on the system configuration.
- Example: On a server, you might see a text login prompt:
Ubuntu 20.04.1 LTS server1 tty1
server1 login:
- For desktop systems, you might get a graphical login prompt (GDM, LightDM, etc.) where you can log in by selecting your user account and entering your password.
- Command: If you’re in a terminal-based environment, you can use:
whoami
- To confirm your login, this command will display the username of the logged-in user.
Real-World Example
Imagine booting a server running Ubuntu 22.04. You press the power button, and the BIOS/UEFI kicks in to check your hardware and find a bootable drive. GRUB then shows a menu, offering you a choice between Ubuntu and perhaps another OS like Windows. Once you select Ubuntu, the kernel starts loading, initializing hardware and mounting the root filesystem. systemd
then steps in to start critical services like networking. Finally, you're presented with a login prompt, where you log in as a user and begin working.
In modern Linux distributions like Ubuntu, you’ll primarily interact with systemd
, which streamlines a lot of these steps and makes managing services much easier.