systemd — Complete, Concise Notes

naruto · Dec 19, 2025 Public

What is systemd?

systemd is the init system and service manager for modern Linux distributions.

It is responsible for:

  • Booting the system
  • Starting & supervising services
  • Managing processes, logs, devices, mounts, users, timers, and networking

It replaced SysVinit & Upstart in most distros (Ubuntu, RHEL, CentOS, Debian, Arch).


Why systemd exists (Problems it solved)

Old init systems:

  • Sequential startup (slow)
  • Poor dependency handling
  • No supervision after start
  • Scattered logging

systemd provides:

  • Parallel startup → faster boot
  • Dependency-aware service management
  • Automatic restarts & monitoring
  • Unified logging & control interface

Core Concepts

1. Units

Everything in systemd is a unit.

A unit is a configuration file describing something systemd manages.

Common unit types:

Unit TypePurpose
serviceDaemons / background processes
socketSocket activation
targetGroup of units (like runlevels)
mountMount points
automountOn-demand mounts
timerCron replacement
pathFile/directory watcher
deviceHardware devices
sliceResource control (cgroups)
scopeExternally created processes

Example unit name:

nginx.service


2. Unit File Locations

Priority order:

/etc/systemd/system/     # Admin overrides (highest priority) 

/run/systemd/system/     # Runtime units /lib/systemd/system/     

# Distribution default units


How systemd Boots (Boot Flow)

  1. BIOS/UEFI
  2. Bootloader (GRUB)
  3. Kernel loads
  4. PID 1 = systemd
  5. systemd:
    • Mounts filesystems
    • Starts default target
    • Launches services in parallel
    • Applies dependencies & ordering

Check PID 1:

ps -p 1 -o comm=


Targets (Runlevels Replacement)

Targets replace SysV runlevels.

TargetEquivalent
poweroff.target0
rescue.target1
multi-user.target3
graphical.target5
reboot.target6

Default target:

systemctl get-default

Set default:

systemctl set-default multi-user.target


Services

Service lifecycle

systemctl start nginx 

systemctl stop nginx 

systemctl restart nginx 

systemctl reload nginx 

systemctl status nginx

Enable at boot:

systemctl enable nginx

Disable:

systemctl disable nginx


Anatomy of a Service File

Example:

[Unit] Description=Nginx Web Server After=network.target 

[Service] ExecStart=/usr/sbin/nginx -g 'daemon off;' Restart=always User=www-data

[Install] WantedBy=multi-user.target

Sections explained

  • [Unit] → description & dependencies
  • [Service] → how process runs
  • [Install] → when to start (target linkage)

Dependencies & Ordering

Dependency types

  • Requires= → hard dependency
  • Wants= → soft dependency
  • After= → start order
  • Before= → inverse order

Example:

Requires=network.target After=network.target


Socket Activation (Key systemd Feature)

systemd:

  • Opens socket before service starts
  • Starts service only when traffic arrives

Benefits:

  • Faster boot
  • Lower memory usage

Example:

sshd.socket → sshd.service


Timers (Cron Replacement)

Timer unit + service unit.

Example:

systemctl list-timers

Timer benefits over cron:

  • Missed jobs run after reboot
  • Dependency-aware
  • Unified logging

Logging — journald

systemd logging is handled by journald.

View logs:

journalctl journalctl -u nginx journalctl -b journalctl -f

Persistent logs:

/var/log/journal/


Process & Resource Management (cgroups)

systemd uses cgroups to:

  • Track all processes of a service
  • Enforce limits

Examples:

MemoryLimit=500M CPUQuota=50%

Check cgroups:

systemd-cgls


systemd vs traditional init

FeatureSysVinitsystemd
StartupSequentialParallel
DependenciesManualAutomatic
Supervision
Loggingsyslogjournald
Resource controlcgroups
Socket activation

Common Debugging Commands

systemctl status <service> journalctl -xe systemctl list-units systemctl list-unit-files systemctl show <service>


Key systemd Components

ComponentRole
systemdPID 1 init
systemctlControl interface
journaldLogging
logindUser sessions
udevdDevice manager
timesyncdTime sync
resolvedDNS
networkdNetwork management

Why interviewers care

systemd shows:

  • Linux internals knowledge
  • Service reliability understanding
  • Debugging ability
  • Production readiness

One-line summary (remember this)

systemd is a dependency-aware, parallel init and service management system that controls how Linux boots, runs, logs, and manages resources.