DEV Community

Shivakumar
Shivakumar

Posted on

Boot Process & Init Systems

Imagine the Linux boot process is like a relay race. One player does their job and passes the baton (control) to the next player. Let’s break down the story of what happens from the moment you press the power button until your screen turns on.

The Boot Process Story (BIOS Systemd)

1. BIOS (Basic Input/Output System)

  • The Hardware Checker: As soon as you press the power button, the BIOS wakes up first. It is a small software already installed on your motherboard.
  • POST (Power-On Self-Test): The first thing it does is a health check. It checks, "Is the RAM connected? Is the keyboard there? Is the processor working?" This is called POST.
  • Finding the Boot Device: Once the hardware is okay, the BIOS asks, "Okay, where is the operating system?" It looks at your Hard Disk, USB, or CD-ROM based on the settings. When it finds the Hard Disk, it reads the very first sector (the first tiny block) of the disk. That block is called the MBR.

2. MBR (Master Boot Record)

  • The Signpost: The MBR is very, very small—only 512 bytes. Because it is so small, it cannot hold the whole operating system.
  • The Job: Think of MBR as a signpost. It contains information about your disk partitions (like C: drive, D: drive structure) and a tiny piece of code.
  • Handover: Its only job is to tell the computer: "Hey, I don't have the full software, but I know where the Bootloader (GRUB) is sitting. Go there." It passes control to GRUB.

3. GRUB (Grand Unified Bootloader)

  • The Menu Card: Now GRUB takes over. This is the black screen you usually see when you start Linux. It shows you a menu: "Do you want to open Ubuntu? Or Fedora? Or Windows?"
  • Loading the Brain: If you don’t touch anything, it picks the default option. GRUB has a very important job—it knows exactly where the Kernel is kept inside the /boot folder.
  • Handover: GRUB loads the Kernel into the RAM (memory) and says, "Sir, your turn."

4. Kernel

  • The Big Boss: The Kernel is the heart and brain of the OS. It is not a normal program; it is the core.
  • Hardware Setup: Once the Kernel starts, it immediately talks to all your hardware—processor, memory, graphics card—and gets them ready for work.
  • Mounting the Filesystem: The Kernel then mounts the root filesystem (the / drive) so it can read files from your hard disk.
  • Starting the First Process: The Kernel finishes its setup and looks for a program to manage the system. It runs a program called /sbin/init (which nowadays is Systemd). It gives this program the PID 1 (Process ID 1). This is the first official process of your computer.

5. Systemd

  • The Manager: Systemd is the "Mother of all Processes." It is the first process to start and the last one to die when you shut down.
  • Parallel Work: In older days, systems would start things one by one (Network... then Sound... then Bluetooth). But Systemd is smart. It starts many services at the same time (in parallel) to make booting faster.
  • Targets: It looks at its goal (called a Target). If you are using a server, it goes to multi-user.target (command line). If you are using a desktop, it goes to graphical.target.
  • Final Step: Once Systemd finishes starting the background services (like WiFi, Audio, Bluetooth), it shows you the Login Screen.

Here are the most important Systemd commands.

Think of the command systemctl as your main "Remote Control" for the Linux server. You use this command to tell Systemd what to do.

1. Managing Services (Immediate Actions)

These commands affect the service right now, but they don't change what happens when you restart the computer.

Command Explanation (Plain English)
sudo systemctl start <service> "Start it now."


Use this to switch ON a service immediately.


(Example: Start the web server software) |
| sudo systemctl stop <service> | "Stop it now."


Use this to kill or switch OFF a service immediately. |
| sudo systemctl restart <service> | "Turn it off and on again."


Useful if the software is hanging or behaving weirdly. It stops the service and starts it fresh. |
| sudo systemctl status <service> | "How are you doing?"


This is the most useful command. It tells you if the service is active (running), dead (stopped), or failed (crashed). It also shows the last few error logs. |
| sudo systemctl reload <service> | "Read the config file again."


Use this if you changed a configuration file (like nginx.conf) but don't want to stop the website. It just refreshes the settings without disconnecting users. |

2. Managing Boot Behavior (Permanent Actions)

These commands decide what happens when the server restarts.

Command Explanation (Plain English)
sudo systemctl enable <service> "Auto-start on boot."


This creates a permanent link. Even if you restart the server 100 times, this service will start automatically every time. |
| sudo systemctl disable <service> | "Don't auto-start."


This removes the link. The service won't start automatically when the server turns on. (You can still start it manually). |
| sudo systemctl is-enabled <service> | "Are you set to auto-start?"


It just answers "enabled" or "disabled". Good for checking if you forgot to enable something. |

3. System Health & Maintenance

Commands to check the overall system or update Systemd itself.

Command Explanation (Plain English)
sudo systemctl daemon-reload "Systemd, refresh yourself."


Run this whenever you create a new custom service file or edit an existing .service file. It forces Systemd to re-read all files from the disk. |
| systemctl list-units --type=service | "Show me everything running."


This lists every active service currently running on your computer. It’s a long list! |
| systemctl list-unit-files --type=service | "Show me everything installed."


This lists every service installed on your computer, even the ones that are stopped or disabled. |

4. Viewing Logs (The Detective)

When a service fails (shows "Failed" in status), you need to see why. Systemd has a partner tool called journalctl.

  • journalctl -u <service>
  • Meaning: "Show me the logs only for this specific service."
  • Example: journalctl -u nginx (Shows why Nginx crashed).

  • journalctl -xe

  • Meaning: "Show me the errors from the very end." (Usually the most recent crash details).

  • journalctl -f

  • Meaning: "Follow the logs live." (Like watching CCTV footage in real-time).

Imagine you just installed nginx (a web server). Here is the workflow:

  1. sudo systemctl start nginx Turn it on now so I can use it.
  2. sudo systemctl enable nginx Make sure it turns on automatically if the server reboots tonight.
  3. sudo systemctl status nginx Check if it is running green (Active) and happy.

What is a Custom Systemd Service?

Sometimes, you have a script or a program (like a Python script or a Java app) that you want to run automatically every time the computer restarts. You don't want to type the command manually every morning.

To do this, you create a "Service Unit." This is just a small text file that tells Systemd: "Hey, please run this script for me in the background."

Example: Running a Python script automatically

Let's say you have a Python script backup.py that takes a backup of your files.

Step 1: Create the file
You create a file named mybackup.service inside the folder /etc/systemd/system/.

Step 2: Write the instructions
Inside that file, you write something like this:

[Unit]
Description=My Daily Backup Service
# This line says: Only start this AFTER the internet is connected
After=network.target 

[Service]
# This is the actual command you want to run
ExecStart=/usr/bin/python3 /opt/backup.py
# If the script crashes, try to restart it automatically
Restart=always

[Install]
# This says: Start this when the computer boots up normally
WantedBy=multi-user.target

Enter fullscreen mode Exit fullscreen mode

Step 3: Enable it
Now you just tell Systemd to remember this:

  1. sudo systemctl enable mybackup.service (This makes it auto-start on next boot).
  2. sudo systemctl start mybackup.service (This starts it right now).

So, simply put: Systemd Service is just a way to tell Linux to handle your program automatically as a background task.

Top comments (0)