Linux Runlevels and Targets Explained
This article explores the concept of runlevels and systemd targets in the Linux operating system, detailing their operational significance, transition from legacy SysVinit to modern systemd, and practical use cases. In Linux, these states define precisely what services, daemons, and subsystems are active at any given moment. By understanding runlevels and targets, administrators gain the ability to troubleshoot boot failures, manage system resources efficiently, and safely conduct critical maintenance tasks.
What Are Runlevels and Targets?
In the Linux operating system, a runlevel represents a preset operating state that determines which system resources, processes, and network interfaces are available. Historically managed by the traditional System V init (SysVinit) system, these states were represented numerically from 0 to 6.
Modern Linux distributions—such as Ubuntu, Red Hat Enterprise Linux,
Debian, and Fedora—have largely replaced SysVinit with
systemd. In systemd, the concept of runlevels is
superseded by targets. Targets are configuration files
ending with the .target extension that group multiple
systemd units (services, sockets, mount points) together to achieve a
specific operational state. While the syntax and underlying architecture
differ, systemd targets serve the exact same fundamental purpose as
legacy runlevels.
Mapping Traditional Runlevels to Systemd Targets
Understanding the mapping between legacy numerical runlevels and modern systemd targets is essential for managing diverse Linux environments:
- Runlevel 0 (
poweroff.target): Halts and completely shuts down the system. - Runlevel 1 / Single-User Mode
(
rescue.target): A minimal environment with a local root shell, no network connectivity, and no non-essential daemons. Primarily used for low-level system repair. - Runlevel 2 (
multi-user.targetwithout networking on some SysV systems): Multi-user text-mode environment, traditionally configured without network support on specific Unix-like systems. - Runlevel 3 (
multi-user.target): The standard multi-user command-line interface (CLI) mode with full networking and multi-user access enabled. This is the default target for most headless Linux servers. - Runlevel 4: Reserved and user-definable; rarely utilized by default configurations.
- Runlevel 5 (
graphical.target): Multi-user mode with full networking and a graphical user interface (GUI) managed by a display manager (such as GDM or LightDM). This is the standard state for Linux desktop installations. - Runlevel 6 (
reboot.target): Initiates a full system reboot, cleanly stopping all running services before restarting the machine.
Beyond these direct mappings, systemd also includes dedicated
emergency states such as emergency.target, which provides
an even more stripped-down environment than rescue.target
by mounting only the root filesystem in read-only mode without starting
other basic system services.
The Significance of Runlevels and Targets
1. Controlled Boot and Shutdown Sequences
Runlevels and targets guarantee that processes launch and terminate in a deterministic order. During startup, core hardware and networking stacks must initialize before high-level database or web services start. During shutdown, databases and dependent services must stop cleanly before storage filesystems are unmounted, preventing data corruption.
2. Streamlined Troubleshooting and Disaster Recovery
When a system fails to boot properly—due to corrupted configuration
files, broken drivers, or failed package upgrades—switching to
rescue.target (Runlevel 1) or emergency.target
bypasses high-level services like the display manager or network
daemons. This drops the administrator directly into a root shell to
inspect logs, repair broken filesystems, or roll back faulty
configurations without external interference.
3. Resource Optimization
Headless servers do not require graphical environments, which consume
substantial CPU, memory, and disk resources. Setting the default target
to multi-user.target rather than
graphical.target ensures the system dedicates maximum
hardware resources to core services and applications, while
simultaneously reducing the attack surface by avoiding unnecessary
software packages.
4. Controlled State Isolation
System administrators frequently need to isolate states during runtime without rebooting. For instance, an administrator can transition a running server from a graphical environment to a command-line environment to perform kernel upgrades or memory-intensive batch processing, cleanly freeing up hardware resources on the fly.
Common Management Commands
To manage and inspect system states in modern systemd environments:
- View current default target:
systemctl get-default - Change default target permanently:
sudo systemctl set-default multi-user.target - Switch targets immediately (without rebooting):
sudo systemctl isolate rescue.target - Check current and previous runlevel (legacy
compatibility):
who -r