runlevel
Show current system runlevel
TLDR
Return previous and current SysV runlevel
Display help
SYNOPSIS
runlevel
DESCRIPTION
The runlevel command is a utility used in Linux and Unix-like operating systems to display the system's previous and current runlevel. Runlevels are distinct operating states of a system, defining which services are running. They are primarily associated with SysVinit-based systems but are often emulated or reported by systemd for backward compatibility.
The command reads information from the /var/run/utmp (or /run/utmp) file, which logs various system events, including runlevel changes. The output consists of two characters: the first indicating the previous runlevel and the second indicating the current runlevel. If there was no discernible previous runlevel (e.g., after a fresh boot), the first character will be 'N'. Understanding runlevels is crucial for system administrators to manage system states, boot processes, and service startup/shutdown.
CAVEATS
The runlevel command relies on the /var/run/utmp file for its information. If this file is corrupt or not properly updated by the init process, the output may be inaccurate or misleading.
While still present, the concept of runlevels is less central in modern Linux distributions that use systemd as their init system. systemd primarily uses "targets" (e.g., multi-user.target, graphical.target) to define system states, mapping them to traditional runlevels for compatibility.
The exact meaning of runlevels (especially runlevels 2-5) can vary significantly between different Linux distributions.
OUTPUT FORMAT EXPLAINED
The output of runlevel is always two characters: <previous_runlevel> <current_runlevel>.
- N: No previous runlevel (e.g., after initial boot).
- S or s: Single-user mode.
- 0: System halt (power off).
- 1: Single-user mode (often same as S).
- 2, 3, 4, 5: Multi-user modes. Their specific configurations (e.g., network services, graphical interface) can vary between distributions.
- 6: System reboot.
RUNLEVEL CONCEPT IN MODERN LINUX
While runlevel reports traditional runlevels, systemd manages system states using "targets." These targets effectively replace runlevels, offering more granular control. systemd ensures utmp is updated so that runlevel continues to function, allowing legacy scripts and administrators to use it.
For instance, multi-user.target typically corresponds to runlevel 3, and graphical.target to runlevel 5. While you can still use runlevel, systemd's systemctl isolate command is the modern way to change system states (targets).
HISTORY
The runlevel command has been a staple in Unix-like operating systems for decades, stemming from the original System V Init (SysVinit) system. It was designed to provide a quick way for administrators to ascertain the system's operational state based on the runlevel concept.
With the advent of systemd as the dominant init system in modern Linux distributions, runlevel's direct importance has diminished. However, it persists as a compatibility layer, often implemented as a simple script that reads the utmp file, which systemd populates to maintain backward compatibility with tools expecting traditional runlevel information. Its development has largely focused on maintaining this compatibility rather than introducing new features.