Skip to main content

Linux Init Systems: From SysV to systemd

Compare Linux init systems through interactive visualizations. Understand the evolution from SysV Init to systemd, service management, and boot orchestration.

The Heartbeat of Linux

At the very core of every Linux system beats a special process - PID 1, the init system. This is the first process started by the kernel and the last one to die when the system shuts down. It's the ancestor of all other processes, the supervisor of system services, and the orchestrator of your system's lifecycle.

Think of the init system as the conductor of an orchestra. While the kernel provides the instruments (hardware resources), the init system coordinates when each musician (service) plays, ensuring they work in harmony. Some conductors (SysV Init) follow a strict, sequential score, while others (systemd) allow sections to play simultaneously for a faster, more dynamic performance.

The evolution from SysV Init to systemd represents one of the most significant changes in Linux history, transforming how we think about system initialization and service management.

The figure below compares the major init systems. Switch views to compare systemd, SysV Init, OpenRC and Upstart, step through a boot, start services one by one, or see how systemd and SysV Init are built.

Init systems
view
Pros
  • Fast boot times
  • Feature-rich
  • Active development
  • Good documentation
Cons
  • Complex
  • Large codebase
  • Controversial design
  • Binary logs
Key Features
Parallel service startupOn-demand service activationDependency managementUnified logging (journald)
FeaturesystemdSysV InitOpenRCUpstart
Boot SpeedFastSlowMediumMedium
Parallel StartYesNoYesYes
DependenciesAutomaticManualAutomaticEvent-based
ComplexityHighLowMediumMedium

The Init Process Hierarchy

PID 1: The Immortal Process

The kernel searches for init in order: /sbin/init, /etc/init, /bin/init, /bin/sh. If none found, kernel panics. PID 1 never exits - it's the ancestor of all processes and adopts orphans.

bash
# View process tree
pstree -p
# systemd(1)───systemd-journal(289)
#           ├──systemd-udevd(315)
#           ├──sshd(890)───bash(1235)
#           └──nginx(1001)───nginx(1002)

SysV Init: The Traditional Approach

Sequential startup: Services start one at a time based on numeric order. Simple but slow.

Runlevels: System states controlling which services run.

  • 0: Halt/Shutdown
  • 1: Single user mode (rescue)
  • 3: Multiuser with network
  • 5: Multiuser with GUI
  • 6: Reboot
bash
# Change runlevel
init 3
telinit 5

# Check current
runlevel

Service Management

Scripts in /etc/init.d/ handle start, stop, restart. Simple shell scripts with case statements.

bash
# Start/stop services
service httpd start
service httpd stop

# Enable/disable at boot
chkconfig httpd on
chkconfig --list

systemd: The Modern Powerhouse

Parallel startup: Services start simultaneously when dependencies met. Fast and efficient.

Unit Files: Declarative Configuration

Unlike SysV's shell scripts, systemd uses declarative unit files. Each directive has a specific meaning. The figure shows a service, a timer and a socket unit; select a directive to see what it does and how much it matters.

Unit file anatomy
unit
/etc/systemd/system/nginx.service
[Unit]
[Service]
[Install]
[Unit]
Generic info and dependencies. Applies to all unit types.
[Service]
Type-specific configuration. Defines how the unit operates.
[Install]
Defines how "systemctl enable" installs the unit.
Critical: Required for functionRecommended: Best practiceOptional: Nice to have

Socket Activation: On-Demand Services

One of systemd's most powerful features is socket activation. Instead of starting services at boot, systemd creates sockets and only spawns services when connections arrive. This dramatically speeds up boot time and saves memory. Connections queue in the kernel while the service starts, so none are lost, and the socket exists before the service, which simplifies dependencies. Step through the phases, from the socket created at boot to the service handling requests.

Socket activation
Step 1 / 6
  1. 1System Boot
  2. 2Idle
  3. 3First Request
  4. 4Service Starting
  5. 5Socket Handoff
  6. 6Running
systemd
PID 1
Always running
Socket: inactive
nginx.socket
Port 80
[Socket]
ListenStream=80
Accept=no
nginx.service
Not spawned
Zero memory usage
Connection log

Step forward to see socket activation in action

System Boot: systemd creates socket, service not started

Process Supervision: Automatic Recovery

systemd monitors services and automatically restarts them based on configurable policies. Understanding these policies is crucial for building reliable systems. Pick a policy and a restart delay, then simulate an exit to see whether systemd restarts the service.

Restart policies
5s

Restart=on-failure: Restart on non-zero exit, signal, timeout. RestartSec is the delay between service exit and restart attempt.

Simulate Exit Event
systemctl status myapp.service
[00:00] Service started (PID 12345)
Restart Policy Matrix
PolicyClean ExitError ExitCrash (SIGSEGV)Abort (SIGABRT)Killed (SIGKILL)
no
on-success
on-failure
on-abnormal
on-abort
on-watchdog
always

Best practice: use Restart=on-failure for most services. It restarts on crashes but respects intentional stops. Combine with RestartSec=5s to prevent rapid restart loops and StartLimitBurst=3 to give up after repeated failures.

Unit Types

  • .service: System services (nginx, postgresql)
  • .socket: Network sockets for activation
  • .target: Groups of units (like runlevels)
  • .timer: Scheduled tasks (replaces cron)
  • .mount: Filesystem mount points
  • .path: Path-based activation

systemd Commands

bash
# Service management
systemctl start nginx
systemctl status nginx
systemctl enable nginx

# System state
systemctl list-units --failed
systemctl get-default

# Logs
journalctl -u nginx
journalctl -f
journalctl -b

# Analyze boot
systemd-analyze
systemd-analyze blame

Timer Units: Better Than Cron

Timer units offer advantages over traditional cron:

  • Persistent timers (run missed events after reboot)
  • Randomized delays (prevent thundering herd)
  • Calendar syntax with second precision
  • Integrated logging via journald
ini
# /etc/systemd/system/backup.timer
[Timer]
OnCalendar=daily
Persistent=true
RandomizedDelaySec=30min

OpenRC: The Elegant Alternative

Dependency-based: Services declare dependencies explicitly (need, use, after, before). Parallel startup within constraints.

bash
# Service control
rc-service nginx start
rc-status

# Enable at boot
rc-update add nginx default

# Runlevels: boot, default, nonetwork, shutdown

Comparison: SysV vs systemd vs OpenRC

FeatureSysV InitsystemdOpenRC
StartupSequentialParallelDependency-based parallel
Boot Time30-60s10-20s15-25s
DependenciesNumeric (S01, S02)Explicit (After, Requires)Functions (need, use)
ConfigShell scriptsUnit files (INI)Shell scripts
Resource ControlLimited (ulimit)Full (cgroups)Basic (cgroups)
LoggingSyslogjournaldSyslog

Advanced systemd Features

Generators: Create units dynamically at boot (e.g., mount units from /etc/fstab).

Drop-in Directories: Override unit settings without modifying originals.

bash
systemctl edit nginx  # Creates override in /etc/systemd/system/nginx.service.d/

Template Units: Instantiate multiple services from one template.

bash
# app@.service → app@web.service, app@api.service
systemctl start app@web.service

Resource Control: Limit CPU, memory, and I/O per service using cgroups.

ini
[Service]
CPUQuota=50%
MemoryMax=512M
IOWeight=100

Troubleshooting

bash
# Service fails
systemctl status failed-service
journalctl -u failed-service

# Dependency issues
systemctl list-dependencies service

# Boot analysis
systemd-analyze critical-chain

# Emergency mode
systemctl rescue

If you found this explanation helpful, consider sharing it with others.

Mastodon