Unix - Runlevels in UNIX (SysV init)

In traditional UNIX and old Linux systems (before systemd), the system startup and shutdown were controlled by a mechanism called Runlevels.

A Runlevel defines the state of the machine — which services should be running and which should be stopped.


What Are Runlevels?

A runlevel is a number between 0 and 6, and each level represents a specific mode of operation.

The system switches between runlevels using /etc/inittab (older systems) and startup scripts in:

/etc/rc.d/rc*.d/
/etc/init.d/

Each runlevel has a directory:

/etc/rc0.d/
/etc/rc1.d/
/etc/rc2.d/
/etc/rc3.d/
...

Each directory contains scripts that start (S) or stop (K) services.


Standard Runlevels (0–6)

Runlevel Meaning Description
0 Halt Shuts down the system
1 Single-user mode Maintenance mode (no networking, root only)
2 Multi-user (without networking)** or full multi-user (varies by OS)  
3 Full multi-user, networking enabled CLI mode (no GUI)
4 Unused / Custom Can be configured for custom tasks
5 Multi-user with GUI Runs graphical login (X11)
6 Reboot Restart the system

⚠️ Runlevels are OS-dependent.
Example: Ubuntu used runlevel 2 as full multi-user with networking.


Most Common Runlevels Used

Runlevel 1 (Single User Mode)

Used for:

  • Fixing filesystem issues

  • Resetting passwords

  • System recovery

No network, no regular users.


Runlevel 3 (Multi-user with networking — CLI mode)

Used on servers.
Standard mode for headless machines.


Runlevel 5 (Multi-user with GUI)

Used on desktops.
Starts graphical login (gdm, kdm, lightdm).


How to Check Current Runlevel

runlevel

Output example:

N 3

Meaning: moved from "N" (no previous) to level 3.


How to Change Runlevel

Temporary change (until restart):

init 3

or

telinit 3

Permanent change:

Edit the file:

/etc/inittab

Example:

id:3:initdefault:

Runlevel Script Structure

Every runlevel directory contains several scripts named like:

S20network
K75ntp
S30syslog

Meaning:

  • S → Start this service when entering the runlevel

  • K → Kill (stop) this service when leaving the runlevel

  • Numbers (20, 30, 75) → Execution order


How SysV init Works with Runlevels

  1. Kernel starts /sbin/init (PID 1).

  2. init reads /etc/inittab.

  3. Determines default runlevel.

  4. Executes startup scripts for that runlevel.

  5. Provides login prompt (getty) or GUI depending on runlevel.


Quick Summary

  • Runlevels define the system state in SysV init.

  • Levels 0–6 control shutdown, recovery, CLI, GUI, and reboot.

  • Startup scripts exist in /etc/rc*.d/.

  • Modern systems use systemd, which replaces runlevels with targets (e.g., multi-user.target, graphical.target).