Skip to content

System Run Levels

Run levels in Linux are predefined states of a system that determine which services and processes are running. They control the system’s operational state and help administrators configure the system to start in specific modes such as multi-user mode, single-user mode, or graphical interface mode.


1. What are Run Levels?

Run levels are numbered states that define the set of services or processes that are active on a Linux system. Different run levels are used for various tasks such as maintenance, troubleshooting, or full operational mode.

  • Run levels range from 0 to 6 in traditional SysVinit systems.
  • Each run level has a specific purpose.

2. Traditional SysVinit Run Levels

Run LevelDescription
0System halt (shutdown mode).
1Single-user mode (maintenance).
2Multi-user mode without networking.
3Full multi-user mode with networking (text-based).
4Undefined (user-defined/custom).
5Multi-user mode with graphical interface (GUI).
6Reboot.

Details of Key Run Levels

  1. Run Level 0 (Halt)
    1. Shuts down the system.
    1. Activated with:

init 0

  • Example use case: Powering off the machine.
  • Run Level 1 (Single-User Mode)
    • Minimal services started.
    • No networking, and only the root user can log in.
    • Activated with:

init 1

  • Example use case: Troubleshooting system issues.
  • Run Level 3 (Multi-User Mode with Networking)
    • All system services are started, except the graphical interface.
    • Activated with:

init 3

  • Example use case: Server operations.
  • Run Level 5 (Multi-User Mode with GUI)
    • Full multi-user mode with a graphical desktop environment.
    • Activated with:

init 5

  • Example use case: Desktop workstations.
  • Run Level 6 (Reboot)
    • Restarts the system.
    • Activated with:

init 6


3. Managing Run Levels

3.1 Checking the Current Run Level

  • Command:

who -r

3.2 Changing Run Levels

  • Command:

sudo init <runlevel>

  • Example:

sudo init 3

3.3 Setting Default Run Level

  • Default run level is defined in the /etc/inittab file (SysVinit systems):

id:3:initdefault:


4. Systemd Targets (Modern Linux Systems)

Most modern Linux distributions have replaced SysVinit with systemd, which uses targets instead of run levels. Targets provide more flexibility and modularity.

Systemd Targets and Their Equivalents

SysVinit Run LevelSystemd TargetDescription
0poweroff.targetShutdown the system.
1rescue.targetSingle-user mode.
3multi-user.targetFull multi-user mode (text-based).
5graphical.targetMulti-user mode with GUI.
6reboot.targetReboot the system.

4.1 Checking the Current Target

  • Command:

systemctl get-default

4.2 Changing the Current Target

  • Command:

sudo systemctl isolate <target>

  • Example:

sudo systemctl isolate multi-user.target

4.3 Setting the Default Target

  • Command:

sudo systemctl set-default <target>

  • Example:

sudo systemctl set-default graphical.target


5. Best Practices

  1. Use Targets Over Run Levels:
    1. For modern systems with systemd, use targets as they offer better flexibility and control.
  2. Set Appropriate Default Mode:
    1. For servers, set multi-user.target to save resources by avoiding GUI.
    1. For desktops, use graphical.target.
  3. Secure Single-User Mode:
    1. Set a password for the root account to prevent unauthorized access in rescue.target.
  4. Monitor and Troubleshoot Services:
    1. Use systemd’s robust logging and service management tools for diagnosing issues.

6. Key Commands Summary

CommandDescription
who -rCheck current run level.
sudo init <runlevel>Switch to a specific run level.
systemctl get-defaultView the default systemd target.
sudo systemctl isolate <target>Change to a specific target.
sudo systemctl set-default <target>Set the default systemd target.

7. Conclusion

Run levels in Linux (or their modern equivalents, systemd targets) are crucial for controlling the system’s operational state. They provide flexibility in configuring the system for different use cases such as troubleshooting, server management, or desktop operations. While traditional run levels are still relevant for legacy systems, most modern Linux distributions rely on systemd targets for better performance and functionality.