VMware ESXi and vSphere Cluster Management

Change Linux Runlevels with init and systemctl

Learn how Linux runlevels work, how to check and change them with init, and how to use systemd targets safely for maintenance, text mode, graphics, reboot, and shutdown.

What is a Linux runlevel?

A runlevel is an operating mode that determines which services and user interfaces Linux starts. For example, one mode may provide a minimal maintenance shell, while another may provide networking, multiple-user services, and a graphical login screen.

Runlevels are primarily associated with SysV init, a traditional initialization and service-management system based on numbered modes and startup scripts. The exact meaning of a number can vary between Linux distributions and local configuration, so treat the following descriptions as typical rather than universal.

Init and legacy boot configuration

The traditional init process is the first userspace process started after the kernel. It normally has process ID 1. Init starts other processes, runs service scripts, and changes the system between operating modes.

On a SysV system, /etc/inittab traditionally defines the default runlevel and actions that init should perform. It can also describe consoles and responses to events such as system shutdown. Many current distributions use systemd and do not use /etc/inittab for normal service management. On those systems, systemd is usually PID 1, and named targets provide the practical equivalent of runlevels.

Traditional SysV runlevel meanings

RunlevelTypical purposeService and interface behaviorImportant cautions
0Halt or power offStops the system and performs shutdown actions.Disruptive; the machine becomes unavailable.
1, s, SSingle-user or maintenance modeStarts a restricted environment with limited services, usually for administrative repair.Networking and remote access may stop. Use a local console or out-of-band access when possible.
2Multi-user text modeSupports multiple users without a graphical desktop. Networking behavior differs between distributions.Do not assume networking is enabled.
3Multi-user text modeCommonly provides multiple users and networking without a graphical login.Local configuration may change which services start.
4Unused or locally customizedOften reserved for site-specific configuration.Its behavior cannot safely be inferred without inspecting the host.
5Multi-user graphical modeCommonly starts networking, normal services, and a graphical login or desktop.This mapping is distribution-specific and requires a working graphical stack.
6RebootStops services and restarts the machine.Disruptive; save work and warn users first.

Runlevels 0 and 6 are actions rather than normal working environments. Runlevel 1 is also disruptive because it can stop services required by users and remote administrators.

Change runlevels with init

The traditional command syntax is:

sudo init LEVEL

For example, to request single-user maintenance mode on a compatible SysV system:

sudo init 1

Init then starts and stops services according to the scripts configured for runlevel 1. Most normal services may stop, and the system may present a restricted administrative environment.

To return to graphical multi-user operation on a legacy system where runlevel 5 has that meaning:

sudo init 5

This requests the services associated with runlevel 5. The command requires root privileges, supplied here with sudo. Runlevel 5 is not guaranteed to mean graphical operation on every distribution.

Check the current and previous runlevels

On a compatible SysV system, run:

runlevel

The output usually contains two values: the previous runlevel and the current runlevel. For example, N 3 means that no previous runlevel is available and the current level is 3. An unknown previous level is normal early in boot or when the system has not transitioned from another level.

The runlevel command may be missing, may provide compatibility output, or may be less useful on a systemd host. To see active systemd targets, use:

systemctl list-units --type=target --state=active

To identify the init system directly, you can inspect process 1:

ps -p 1 -o comm=

If the result is systemd, use systemd targets and systemctl as the clearer management interface.

Modern systemd targets

A target is a systemd unit that groups other units to represent a desired system state. Targets replace much of the practical role of SysV runlevels on contemporary Linux systems.

Legacy concept or runlevelCommon systemd targetTypical useNotes on portability
Single-user maintenance moderescue.targetRestricted repair and administration environment.Comparable to single-user mode, but its exact services and authentication behavior depend on system configuration.
Text multi-user modemulti-user.targetNormal non-graphical multi-user operation.Usually includes server services and networking, but individual services may be customized.
Graphical multi-user modegraphical.targetMulti-user operation with a graphical login or desktop.Requires an installed and functioning display manager and graphical stack.
Reboot, runlevel 6reboot.targetRestart the system.Always disruptive.
Power off or halt, runlevel 0poweroff.targetShut down and power off the system.Always disruptive and may end remote access immediately.

On many systemd-based distributions, the legacy init command is a compatibility interface. For example, a request for a traditional runlevel may be translated into a systemd target. Even when this works, systemctl makes the intended target explicit and is the preferred modern interface.

Temporarily enter a maintenance target

To switch the current system state to a restricted systemd maintenance environment:

sudo systemctl isolate rescue.target

isolate activates the requested target and stops units that are not required by it. This can stop networking and disconnect remote users.

Temporarily switch to text mode

To leave graphical operation while keeping the normal non-graphical multi-user services:

sudo systemctl isolate multi-user.target

Graphical services may stop, so a desktop session can disappear. To temporarily return to graphical operation:

sudo systemctl isolate graphical.target

This does not change the target selected at the next boot. It only changes the active system state for the current session.

Temporary mode changes versus persistent boot settings

A temporary switch changes what is running now. A persistent setting changes the target systemd selects during future boots. Confusing these two operations can cause a host to keep booting into an unexpected interface.

TaskSysV-oriented approachsystemd approachEffect duration
Switch active operating modesudo init 1 or sudo init 5, where configuredsudo systemctl isolate rescue.target, multi-user.target, or graphical.targetCurrent session only
Inspect current or default moderunlevelsystemctl list-units --type=target --state=active for active targets; systemctl get-default for the boot defaultInformation only
Set the default boot modeConfigure the default in /etc/inittab on a SysV hostsudo systemctl set-default multi-user.target or sudo systemctl set-default graphical.targetFuture boots
Restore graphical defaultSet the local SysV default to the runlevel assigned to graphics, often 5sudo systemctl set-default graphical.targetFuture boots

Inspect the systemd boot default with:

systemctl get-default

To make text-mode multi-user operation the default:

sudo systemctl set-default multi-user.target

To make graphical operation the default again:

sudo systemctl set-default graphical.target

Changing the default does not necessarily switch the currently running system immediately. Use systemctl isolate for an immediate, temporary change, or reboot during a planned maintenance window to test the new default.

Reboot and power off safely

Systemd provides explicit commands for disruptive actions:

sudo systemctl reboot
sudo systemctl poweroff

Before using either command, save work, confirm the host and intended action, and warn logged-in users. On shared systems, use a planned maintenance window and a notification mechanism appropriate to your environment.

Safe remote administration practices

  • Prefer a local console, virtualization console, serial console, or out-of-band management interface for rescue and single-user work.
  • Assume that rescue.target, runlevel 1, reboot, and poweroff can terminate an SSH session.
  • Confirm whether the selected mode retains networking and the SSH service before isolating it remotely.
  • Warn users before stopping services, restarting, or powering off the system.
  • Keep a recovery path available before changing a server's active target or default boot target.
  • Verify the target name or runlevel number before pressing Enter; a typo involving reboot or poweroff can be immediately disruptive.

Troubleshooting

init does not behave as expected or /etc/inittab is absent

The host may use systemd, or init may be only a compatibility command. Check PID 1 with ps -p 1 -o comm=, then use the appropriate systemd target with systemctl. Do not create an /etc/inittab merely because a legacy guide mentions it.

Graphical mode does not produce a GUI

Check the active and default targets:

systemctl list-units --type=target --state=active
systemctl get-default

A graphical target also needs an installed desktop environment, display manager, graphics drivers, and a working configuration. If the target is selected but no login screen appears, inspect the display manager's service status and logs using the tools provided by the distribution.

An SSH session disconnects after a mode change

The selected configuration may have stopped networking or the SSH service, or the machine may have rebooted or powered off. Recover through a local console or out-of-band interface. Return to multi-user.target or graphical.target as appropriate, then plan future changes with console access available.

The system boots to a text login unexpectedly

Check the default target:

systemctl get-default

If multi-user.target is configured but a graphical desktop is intended, restore the graphical default:

sudo systemctl set-default graphical.target

If the host still boots to text mode, diagnose the display manager and graphical stack rather than repeatedly changing the target.

Runlevel meanings differ from the documentation

Runlevel 2, 3, 4, and 5 are especially likely to differ between distributions or local SysV configurations. Inspect the host's startup configuration and enabled services. On a systemd host, inspect the active and default targets instead of assuming a universal numeric mapping.

Exam-relevant notes

  • A runlevel is a legacy SysV operating mode; a systemd target is a named grouping that represents a desired state.
  • Runlevel 1, s, and S commonly describe single-user maintenance mode.
  • Runlevel 0 powers off, and runlevel 6 reboots. Both are disruptive.
  • /etc/inittab is a traditional SysV configuration file and is not normally used by systemd.
  • systemctl isolate TARGET changes the active state temporarily.
  • systemctl set-default TARGET changes the target used at future boots.
  • systemctl get-default reports the default target, not necessarily the target currently active.

For related service administration, continue with Linux runlevel and systemd target management.