2.5 Systemd Boot Targets & Unit Management (101.3)

Key Takeaways

  • systemd is the modern PID 1 service manager in Linux, offering parallel unit startup, socket activation, and explicit dependency modeling.
  • Systemd manages 11 distinct unit types: .service, .target, .socket, .mount, .automount, .swap, .device, .timer, .path, .slice, and .scope.
  • Unit configuration files follow strict precedence: /etc/systemd/system/ (admin overrides) > /run/systemd/system/ (runtime) > /lib/systemd/system/ (vendor defaults).
  • System operating states are defined by targets: rescue.target (single-user), multi-user.target (CLI server), and graphical.target (desktop GUI).
  • systemctl is used for service control (start/stop/restart), enablement (enable/disable), inspection (status/is-active), masking, and changing targets (isolate, set-default).
Last updated: August 2026

2.5 Systemd Boot Targets & Unit Management

Quick Summary: systemd is the standard initialization system and service manager for modern Linux distributions. Acting as PID 1, it replaces traditional SysVinit with parallel service activation, socket- and D-Bus-based activation, and declarative unit configuration. Operating states are organized into targets (e.g., multi-user.target, graphical.target), and all runtime service administration is performed through the systemctl command.


1. Systemd Architecture & Core Features

Unlike traditional sequential init scripts, systemd treats services and resources as structured objects called Units.

Core Systemd Capabilities

  • Parallel Execution: Starts non-dependent services concurrently, drastically reducing boot times.
  • Socket-Based Activation: Creates listening sockets (UNIX domain or TCP) before launching daemons. When a packet arrives, systemd launches the service instantly, eliminating startup race conditions.
  • cgroups Process Tracking: Groups service child processes inside dedicated Control Groups (cgroups). When a service stops, systemd cleanly terminates all child processes, preventing orphaned daemons.
  • Explicit Dependency Modeling: Uses unit directives (Requires=, Wants=, BindsTo=, Conflicts=, Before=, After=) to establish rigorous startup sequences.

2. The 11 Systemd Unit Types

Systemd organizes all system resources into 11 distinct unit types, distinguished by their filename extensions.

Unit ExtensionResource ManagedReal-World Example & Purpose
.serviceDaemons and background processessshd.service, nginx.service (manages starting, stopping, restarting daemons)
.targetLogical grouping of units representing a system statemulti-user.target, graphical.target (replaces SysV runlevels)
.socketIPC or network sockets for on-demand daemon activationsshd.socket, cups.socket (activates .service when traffic arrives)
.mountFilesystem mount pointsvar-log.mount (mounts /var/log; filename must match mount path dashes)
.automountOn-demand filesystem mounting upon accesshome-backup.automount (mounts filesystem only when directory is accessed)
.swapSwap partitions or swap filesdev-nvme0n1p3.swap (activates swap space in kernel)
.deviceHardware devices exposed by udev/kernelsys-subsystem-net-devices-eth0.device (enables dependency on hardware)
.timerMonotonic or calendar-based job schedulerlogrotate.timer, fstrim.timer (replaces traditional cron jobs)
.pathInotify-based file/directory monitoringspool-watch.path (activates a service when a file is created or modified)
.sliceHierarchical cgroups resource partitionuser.slice, system.slice (manages CPU, memory, and I/O resource limits)
.scopeExternally created transient processessession-1.scope (tracks user login sessions)

3. Unit File Locations & Configuration Precedence

Systemd loads unit files from three main directory locations. If unit files with identical names exist across multiple directories, systemd strictly follows a top-down priority hierarchy.

[1. /etc/systemd/system/]     ──► Priority 1 (Highest): Local Administrator Configuration
         │                        (Custom units, modified copies, enabled symlinks)
         ▼
[2. /run/systemd/system/]     ──► Priority 2 (Intermediate): Volatile Runtime Units
         │                        (Dynamically generated at boot in RAM)
         ▼
[3. /lib/systemd/system/]     ──► Priority 3 (Lowest): Vendor Package Defaults
    /usr/lib/systemd/system/      (Installed by rpm/dpkg packages; overwritten on updates)

Drop-In Configuration Overrides (.d/ Directories)

Instead of copying an entire 100-line vendor unit file to /etc/systemd/system/sshd.service, administrators can create a drop-in override directory named <unit>.d/:

# /etc/systemd/system/sshd.service.d/override.conf
[Service]
Restart=always
RestartSec=5s

After creating or modifying unit files, you must reload the systemd manager configuration:

sudo systemctl daemon-reload

Exam Trap — Unit Masking: Masking a unit renders it completely unstartable (manually or as a dependency). Systemd accomplishes this by creating a symbolic link pointing to /dev/null:

sudo systemctl mask apache2
# Creates: /etc/systemd/system/apache2.service -> /dev/null

4. Systemd Targets & Operating States

A target unit (.target) does not run a daemon directly. Instead, it groups other unit files together using dependency symlinks located in <target_name>.wants/ and <target_name>.requires/ directories.

Standard Systemd Targets

Systemd TargetSysV EquivalentDescription & Operating Environment
poweroff.targetRunlevel 0Shuts down and powers off the system hardware.
rescue.targetRunlevel 1 / SSingle-user maintenance mode with a root shell and all local filesystems mounted read-write. No network services.
emergency.targetN/AMinimal emergency shell. Root filesystem is mounted read-only, no extra services or background daemons are started.
multi-user.targetRunlevel 3Standard multi-user command-line environment with full networking and multi-user login. Default for Linux servers.
graphical.targetRunlevel 5Full multi-user environment with networking and a graphical display manager (X11 / Wayland / GDM / SDDM).
reboot.targetRunlevel 6Shuts down and reboots the system.
default.targetinitdefaultA symbolic link pointing to the default boot target (e.g., /etc/systemd/system/default.target -> /lib/systemd/system/multi-user.target).
Loading diagram...
Systemd Target Dependency and Inheritance Hierarchy

5. System Administration with systemctl

systemctl is the central CLI utility for inspecting, controlling, enabling, and diagnosing systemd units.

Service Lifecycle Management

  • sudo systemctl start <unit>: Starts (activates) the unit immediately.
  • sudo systemctl stop <unit>: Stops (deactivates) the unit immediately.
  • sudo systemctl restart <unit>: Stops and restarts the unit.
  • sudo systemctl reload <unit>: Instructs the service to reload its configuration files without dropping active connections (e.g., nginx -s reload).
  • sudo systemctl reload-or-restart <unit>: Reloads configuration if supported; otherwise, restarts the service.

Boot Enablement & State Inspection

  • sudo systemctl enable <unit>: Enables the unit to start at boot by creating a symlink in the target's .wants/ directory under /etc/systemd/system/.
  • sudo systemctl disable <unit>: Disables automatic startup by deleting the .wants/ symlink.
  • sudo systemctl enable --now <unit>: Enables and immediately starts the service in a single command.
  • systemctl status <unit>: Displays unit state (active, inactive, failed), PID, memory usage, cgroup processes, and recent log snippets.
  • systemctl is-active <unit>: Returns exit code 0 and prints active if running.
  • systemctl is-enabled <unit>: Returns exit code 0 and prints enabled if configured for auto-start.
  • systemctl is-failed <unit>: Checks if the unit crashed or entered an error state.
  • systemctl list-units --type=service: Lists all currently loaded service units in memory.
  • systemctl list-unit-files: Lists all unit files installed on disk and their enablement status.

Target Operations & System Control

  • systemctl get-default: Queries and prints the current default boot target.
  • sudo systemctl set-default graphical.target: Updates the /etc/systemd/system/default.target symlink.
  • sudo systemctl isolate multi-user.target: Immediately switches the system state to multi-user.target, stopping all units not part of the new target.
  • sudo systemctl reboot: Reboots the machine.
  • sudo systemctl poweroff: Powers off the machine.
Test Your Knowledge

Which systemctl command changes the persistent default boot state of a Linux server from a graphical desktop interface to a multi-user command-line interface?

A
B
C
D
Test Your Knowledge

An administrator wants to completely prevent the 'cups.service' printing daemon from being started under any circumstances, including manual execution by users or automatic invocation as a dependency of another service. Which command should be used?

A
B
C
D
Test Your Knowledge

In systemd unit configuration hierarchy, which directory takes the highest priority when evaluating unit files with identical names?

A
B
C
D