Skip to main content

Command Palette

Search for a command to run...

Linux init system

The Story of PID 1: What Really Happens When You Boot Linux?

Updated
6 min read
Linux init system
M

🎃 Curious tech explorer 💣Open Source ⚡Full stack dev 🧨 Technical writer 💎 Linux guy

Who should read this?

I would like you to ask a couple of questions and provide a yes or no answer before proceeding with the article.

  1. Have I used a Linux Distro before?

  2. Do I like spending time in the terminal?

  3. Am I interested in a deep dive into Linux systems?

In case your answer is yes to more than one question, then you are in. Knowing a bit about the Linux ecosystem gives an edge to quickly grasp further concepts of Linux. Now, let’s quickly understand what the heck is init sys.

What is init sys

In short, the init system is the very first process that starts after the kernel finishes loading. It has a process ID (PID) of 1. Alright, that was a mouthful of information. Let’s try to break it down piece by piece. For that, we need to understand what happens when we press the start button of the computer.

This flowchart illustrates the sequential stages of a Linux system startup process, showing how control passes from hardware initialization to a fully operational user environment. It begins with Power On (represented by a green hatched circle) and flows through six main stages, each depicted as rounded rectangles with pink diagonal hatching:

BIOS/UEFI: The Hardware Detective

When you press that power button, BIOS or UEFI firmware springs into action like a hardware detective. This low-level software performs the Power-On Self-Test (POST), checking if your RAM, CPU, and storage devices are ready for action.

Modern systems use UEFI, which offers faster boot times and support for drives larger than 2TB. You've probably seen this stage if you've ever entered the "BIOS setup" by pressing F2 or Delete during startup.

The firmware then scans your boot devices—whether it's your SSD, USB drive, or network—to find something bootable.

Bootloader: The System's Traffic Controller

Think of the bootloader as a sophisticated traffic controller that decides which operating system gets to run. GRUB (Grand Unified Bootloader) is the most common choice on Linux systems, presenting you with that familiar menu when you dual-boot Windows and Linux.

This tiny program, usually just a few megabytes, has the critical job of loading the Linux kernel from your hard drive into RAM. It also passes important boot parameters like which root filesystem to use and whether to boot in quiet mode or show detailed startup messages.

Kernel: The Digital Brain Awakens

The Linux kernel is where the real magic happens—it's the core that transforms your collection of hardware into a functioning computer. Once loaded, the kernel decompresses itself and immediately takes control of your CPU, memory, and hardware devices.

You'll see this stage if you remove the "quiet" parameter from your boot options—watch as it detects your network card, graphics driver, and storage controllers in rapid succession.

The kernel then mounts your root filesystem (usually from /dev/sda1 or similar) and prepares to hand control over to user space by starting the very first process with PID 1.

Init System: The Process Orchestrator

The init system is the first user-space process that takes control after the kernel loads, and there are several options available. Traditional systems used SysVinit with its simple but slow sequential startup, while alternatives like OpenRC (used by Gentoo) and runit (found in Void Linux) offer different approaches to service management.

However, systemd has become the dominant choice across major distributions like Ubuntu, Fedora, and Red Hat. As process number 1, systemd acts like a conductor orchestrating a complex symphony of services, revolutionizing how modern Linux systems start up.

Unlike older systems that started services one by one, systemd launches multiple services simultaneously, dramatically reducing boot times. You can see systemd in action by running "systemctl status" on most modern distributions. It manages everything from your network connection (NetworkManager.service) to your display server, ensuring dependencies are respected—for instance, making sure the network is up before starting web servers.

System Services: The Background Workforce

While you're browsing the web or editing documents, dozens of background services work tirelessly behind the scenes. These daemons handle everything from managing your WiFi connection (wpa_supplicant) to logging system events (rsyslog) and keeping your system time synchronized (chrony or ntpd).

On a typical Ubuntu desktop, you'll find services like cups-browsed for printer discovery, bluetooth for wireless device management, and systemd-resolved for DNS resolution.

These services communicate through various mechanisms like D-Bus, creating an interconnected ecosystem that keeps your system running smoothly.

Login Manager: The Digital Gatekeeper

The login manager is your system's friendly gatekeeper, presenting either a graphical login screen or a simple text prompt depending on your setup. Desktop environments like Ubuntu use GDM (GNOME Display Manager), while others might use LightDM or SDDM.

This component doesn't just verify your password—it also sets up your user session, loads your desktop environment preferences, and manages multiple user sessions if needed.

Once you successfully authenticate, the login manager launches your chosen desktop environment, whether that's GNOME, KDE Plasma, or a lightweight window manager, finally bringing you to the familiar desktop you interact with daily.

💡
The flow concludes with the user environment loading (Gnome, KDE, etc.), indicating the system is ready for user interaction.

Build our System Service for the Minecraft server

Why do we need a service for a Minecraft server that needs to be managed by an init system? That’s a great question btw. It's because we need our server to run 24/7, running the Minecraft server on a terminal session remains in running mode till the terminal session remains active.

Let’s get our feet wet by quickly installing the Minecraft server from here https://www.minecraft.net/en-us/download/server. After downloading it we will get a server.jar file and our next step is to make it into a service so that run it everytime from the terminal.

The following connand spins the minecraft server, this will come handy while creating the service.

java -Xmx1024M -Xms1024M -jar minecraft_server.1.21.8.jar nogui
  1. Create a directory called as minecraft under /opt path and put the server jar file inside that directory.
cd /opt && mkdir -p minecraft/server
  1. Goto this path, /etc/systemd/system/
cd /etc/systemd/system/
  1. create a minecraft.service file under /etc/systemd/system path
nano minecraft.service
  1. Once the nano text editor opens, paste this piece of service configuration.
[Unit]
Description=Minecraft Server
After=network.target
StartLimitIntervalSec=0

[Service]
Type=forking
Restart=always
RestartSec=5
User=minecraft
Group=minecraft
WorkingDirectory=/opt/minecraft/server

# Adjust memory settings as needed (-Xmx4G = 4GB RAM, -Xms1G = 1GB initial)
ExecStart=/usr/bin/screen -dmS minecraft /usr/bin/java -Xmx4G -Xms1G -jar server.jar nogui

# Graceful shutdown sequence
ExecStop=/usr/bin/screen -p 0 -S minecraft -X eval 'stuff "say Server shutting down in 10 seconds..."\015'
ExecStop=/bin/sleep 10
ExecStop=/usr/bin/screen -p 0 -S minecraft -X eval 'stuff "stop"\015'
ExecStop=/bin/sleep 5

[Install]
WantedBy=multi-user.target
  1. After pasting the config, save the file using ctrl+o and then exit out using ctrl+x.

  2. Create a minecraft user

sudo useradd -r -m -U -d /opt/minecraft -s /bin/bash minecraft
  1. Set the required permision
sudo chown -R minecraft:minecraft /opt/minecraft
  1. Enable the minecraft service
sudo systemctl enable minecraft.service

Congratulations we have sucessfully created the minecraft service and its now running in background as a background process🚀

46 views

Linux

Part 1 of 3

Roll up those sleeves, folks! 😎 We're in for a jam-packed hacking day, complete with cool terminals and mind-blowing experiences! 🚀

Up next

Break into the Linux ecosystem

Guide to Linux journey, includes my personal experience 🎃