Linux online course

Linux Runlevels and SysV Init

Learn traditional Linux runlevels, SysV init, /etc/inittab, checking the active runlevel, changing modes, and safely entering maintenance or reboot states.

What Is a Linux Runlevel?

A runlevel is a predefined operating state managed by the traditional System V initialization, or SysV init, system. Each state represents a broad combination of running processes and services.

When the system enters a runlevel, SysV init uses that level's service-start and service-stop scripts. These scripts determine which services should be started and which should be stopped.

A runlevel is broader than an individual service state. For example, a web server being active describes one service. Runlevel 3 describes a complete multiuser operating mode that may include networking, login services, logging, and many other processes.

Important terminology

  • SysV init: The traditional System V-style Linux initialization and service-management framework.
  • init: The traditional first userspace process. It controls system startup and transitions between runlevels.
  • single-user mode: A restricted, maintenance-oriented operating state, conventionally associated with runlevel 1, S, or s.
  • multiuser mode: An operating state designed to support multiple users and a broader collection of services.
  • graphical mode: A multiuser state that starts a graphical login or desktop environment.

Scope: Traditional SysV Init

Numeric runlevels primarily belong to SysV init. Many current Linux distributions use systemd or another initialization system instead. systemd uses targets, while Upstart uses a different event and job model.

As a result, numeric runlevels do not work identically on every current Linux distribution. The meanings of levels 2 through 5 may be changed by the distribution or by an administrator. Always check the local documentation before relying on a particular mapping.

For background on the broader Linux environment, see Linux and Linux file structure.

Traditional Linux Runlevel Reference

The following table shows the commonly taught SysV convention. It is a reference model, not a guarantee for every distribution.

RunlevelTypical purposeService and access characteristicsImportant cautions
0Halt or shutdownStops normal services and powers down the system.Destructive operational action; use deliberately.
1, S, sSingle-user maintenanceStarts a limited service set, usually for local administration and repair.Networking, remote login, and ordinary user sessions may be unavailable.
2Distribution-defined; commonly multiuser text mode without networkingSupports multiple users with a reduced service set in the common convention.Exact behavior varies by distribution and local configuration.
3Multiuser text mode with networkingUsually provides consoles, networking, remote login, and non-graphical services.Do not assume every distribution assigns level 3 this way.
4Distribution-defined; commonly unusedAvailable for local customization or a special operating state.May have a meaningful administrator-defined purpose.
5Multiuser graphical modeCommonly starts networking, multiuser services, and a graphical login or desktop.Graphical behavior depends on the distribution and configured scripts.
6RebootStops services and restarts the system.Destructive operational action; active work and sessions can be interrupted.

Levels 0, 1, and 6 have special or reserved roles. Use them only when you understand the effect and have suitable access to recover from an unexpected result.

How SysV Init Uses /etc/inittab

/etc/inittab is the primary configuration file for conventional SysV init systems. It can define the default runlevel selected after boot and associate actions or processes with particular runlevels.

The default runlevel is the level that init enters automatically during boot. A typical illustrative entry is:

id:5:initdefault:

In this entry, the fields are separated by colons. The value 5 identifies the default runlevel. This is only an example; the configured value is system-specific.

Other entries can specify processes or actions that apply to selected runlevels. For example, a fragment might look like this:

# Illustrative only; exact entries vary by distribution
id:5:initdefault:
si::sysinit:/etc/rc.d/rc.sysinit
l3:3:wait:/etc/rc.d/rc 3
l5:5:wait:/etc/rc.d/rc 5

The exact scripts, paths, identifiers, and actions differ between systems. Do not copy an example into a production /etc/inittab without checking the local init implementation and documentation.

Checking the Current Runlevel

Use the runlevel command to display the previous and current SysV runlevels:

runlevel

The command normally prints two values:

  • The first value is the previous runlevel.
  • The second value is the current runlevel.

An N in the previous-runlevel position means that no prior runlevel transition has been recorded since startup.

Sample outputPrevious stateCurrent stateInterpretation
N 5No previous transition recordedRunlevel 5The system is currently in level 5 and has not recorded an earlier runlevel change since boot.
3 5Runlevel 3Runlevel 5The system moved from level 3 to level 5; level 5 is now active.

dmesg can help inspect kernel and boot messages while investigating initialization behavior, but it does not itself report the current runlevel.

Changing Runlevels

The traditional init process can be asked to transition to a numbered runlevel. For example, an administrator can request single-user maintenance mode with:

init 1

Changing to a different level causes SysV init to compare the current and requested states, then start and stop services according to the configured service scripts for the destination level.

Runlevel changes generally require administrative privileges. On systems where direct root access is restricted, use the approved administrative mechanism for that host.

Maintenance example

  1. Confirm that you have local console or physical access before entering a restricted mode.
  2. Notify users and stop or protect applications that may have unsaved data.
  3. Request the maintenance level with init 1.
  4. Perform the required local maintenance.
  5. Return to the normal documented multiuser runlevel when the work is complete.

Remote administration can be interrupted when entering runlevel 1 or another reduced-service state. Networking, the SSH service, the remote user's session, or all three may stop. Confirm a local console or an approved recovery path before making the change.

SysV Runlevels and Modern systemd Equivalents

systemd targets are approximate conceptual equivalents, not guaranteed numeric aliases. A systemd target groups units, which are systemd's managed service and resource objects.

Traditional runlevelTypical historical roleApproximate systemd target conceptPortability note
1Single-user maintenancerescue.targetBehavior and access controls depend on the systemd configuration.
3Multiuser text mode with networkingmulti-user.targetNot every system maps legacy level 3 to this target in the same way.
5Multiuser graphical modegraphical.targetRequires a configured graphical login environment.
0Halt or shutdownpoweroff.targetUse the native systemd shutdown tools on systemd hosts.
6Rebootreboot.targetUse the native systemd reboot tools on systemd hosts.

Troubleshooting Runlevel Problems

runlevel is unavailable or behaves unexpectedly

The host may use systemd or another non-SysV init implementation. Identify the active init system and use its native service and boot-target tools. Do not assume that a legacy command has the same meaning everywhere.

The selected runlevel does not provide expected networking or graphics

Levels 2 through 5 are not standardized across all distributions and may have been customized. Review the local /etc/inittab, service-script configuration, and distribution documentation.

A remote session disconnects after changing levels

The transition may have stopped networking, the remote-login service, or the user session. Perform this type of maintenance from a local console or verify an approved recovery method first.

The system shuts down or restarts

Runlevel 0 was selected for shutdown or runlevel 6 was selected for reboot. Verify the intended level before executing an init command.

/etc/inittab is missing

The host likely does not use a conventional SysV init layout. Do not create an inittab solely to imitate SysV. Use the configuration model of the active init system instead.

Exam- and Administration-Relevant Notes

  • Runlevels are broad SysV operating modes, not individual service states.
  • The traditional convention assigns 0 to halt, 1/S/s to single-user maintenance, 5 to graphical multiuser operation, and 6 to reboot.
  • Levels 2, 3, and 4 are distribution- or administrator-defined, although common teaching often associates them with no-network text mode, networked text mode, and unused, respectively.
  • /etc/inittab can contain the default-runlevel entry and runlevel-specific actions.
  • runlevel reports previous then current level. For example, 3 5 means the system moved from level 3 to level 5.
  • Administrative privileges and a reliable local or recovery console are important before changing runlevels.