Init Systems
The init (short for initialization) system is the first program executed by the Linux kernel after the bootloader and kernel initialization phases are complete. It runs with a Process ID (PID) of 1 and is the ancestor of all other processes on the system.
The Role of an Init System
The primary responsibilities of an init system include:
- System Initialization: Setting up the environment, mounting filesystems not handled by the
initramfs, and configuring the network. - Service Management: Starting, stopping, and managing background daemons (like web servers, SSH servers, and databases).
- Runlevel/State Management: Bringing the system into a specific state, such as single-user mode for recovery, multi-user text mode, or a full graphical environment.
- Zombie Reaping: Adopting orphaned processes and cleaning up after they terminate.
SysVinit (The Legacy Standard)
For many years, System V init (SysVinit) was the standard across most Linux distributions.
- Sequential Execution: SysVinit starts services sequentially based on shell scripts located in
/etc/init.d/. Service A must finish starting before Service B can begin. - Runlevels: It relies on runlevels (0-6) to define the system state.
- Runlevel 0: Halt
- Runlevel 3: Multi-user text mode
- Runlevel 5: Graphical mode
- Runlevel 6: Reboot
- Limitations: The sequential nature of SysVinit made boot times slow. It also struggled with dynamically changing hardware (like hot-plugging a USB drive) and monitoring service states reliably.
Upstart (The Transitional Phase)
Developed by Canonical (Ubuntu), Upstart aimed to solve SysVinit's problems.
- Event-Driven: Upstart starts and stops services asynchronously based on events (e.g., "network interface eth0 is up" or "hardware device connected").
- Parallelization: This allowed for parallel startup of services, significantly reducing boot times.
- Lifespan: Upstart was the default in Ubuntu for several releases but was eventually phased out in favor of systemd.
systemd (The Modern Standard)
Today, systemd is the dominant init system, used by nearly all major Linux distributions (Debian, Ubuntu, RHEL, CentOS, Arch).
- Aggressive Parallelization: It uses socket activation and D-Bus activation to start services concurrently, further speeding up the boot process.
- Dependency Management:
systemdhandles dependencies implicitly. If Service B requires Service A,systemdknows to start A first. - Beyond Init:
systemdis not just an init system; it is a suite of basic building blocks for a Linux system, including logging (journald), device management (udevd), and time synchronization (timesyncd).
Best Practices
- Know your init system: Before trying to restart a service or troubleshoot a startup issue, verify which init system your Linux distribution uses. Modern systems almost exclusively use
systemd. - Avoid legacy commands on modern systems: While
systemdprovides compatibility commands (likeservice [name] start), it is best practice to use the nativesystemctlcommands to avoid unpredictable behavior.