DEV Community

Rishi Vachhani
Rishi Vachhani

Posted on

Understanding Runlevels in Linux: A Complete Guide

Linux is a powerful and flexible operating system used in servers, embedded systems, and desktops worldwide. One of the essential components of Linux system administration is runlevels. Runlevels define the state of a Linux system by controlling the services and processes that run at startup.

Whether you’re troubleshooting boot issues or managing system services, understanding runlevels can significantly improve your Linux administration skills. In this blog, we’ll explore what runlevels are, where they are used, how to check the current runlevel, how to change it, and real-world use cases.


What Are Runlevels in Linux?

A runlevel in Linux is a mode of operation that determines what processes and services are active at a given time. Different runlevels are predefined for various system states, such as single-user mode, multi-user mode, or GUI mode. Traditionally, runlevels range from 0 to 6, each serving a specific purpose.


Standard Runlevels in Linux

The standard runlevels in SysVinit-based Linux distributions are:

Runlevel Description
0 Halt (Shutdown)
1 Single-user mode (Maintenance Mode)
2 Multi-user mode without network
3 Full multi-user mode (CLI)
4 Unused (customizable)
5 Multi-user mode with GUI
6 Reboot

However, modern Linux distributions such as Ubuntu (16.04+), RHEL 7+, and CentOS 7+ have replaced SysVinit with systemd, where targets are used instead of runlevels.


Where Are Runlevels Used?

Runlevels are used in various scenarios, including:

  • System Boot Management — Define what services should start during boot.
  • Troubleshooting — Switching to single-user mode (Runlevel 1) helps in fixing critical system issues.
  • Server Configurations — Servers often run in Runlevel 3 (CLI mode) to save resources.
  • GUI vs CLI Switching — Users can switch between GUI (Runlevel 5) and CLI (Runlevel 3) as needed.
  • Custom System ModesRunlevel 4 (unused by default) can be customized for specific requirements.

How to Check the Current Runlevel?

To check the current runlevel of your Linux system, use:

runlevel
Enter fullscreen mode Exit fullscreen mode

Example Output:

N 5
Enter fullscreen mode Exit fullscreen mode

Here, N indicates there was no previous runlevel change, and 5 represents the current runlevel (multi-user mode with GUI).

For systemd-based distributions, use:

systemctl get-default
Enter fullscreen mode Exit fullscreen mode

Example Output:

graphical.target
Enter fullscreen mode Exit fullscreen mode

This corresponds to Runlevel 5 in SysVinit.


How to Change Runlevels in Linux?

In SysVinit-based Systems

To switch to a different runlevel temporarily:

init <runlevel>
Enter fullscreen mode Exit fullscreen mode

For example, to switch to runlevel 3:

init 3
Enter fullscreen mode Exit fullscreen mode

Or:

telinit 3
Enter fullscreen mode Exit fullscreen mode

To change the default runlevel permanently, edit the /etc/inittab file and modify this line:

default:5:initdefault:
Enter fullscreen mode Exit fullscreen mode

Change 5 to your desired runlevel and reboot.


In Systemd-based Systems

To change the current runlevel (target) in systemd-based systems:

systemctl isolate multi-user.target
Enter fullscreen mode Exit fullscreen mode

To set a default runlevel (target):

systemctl set-default multi-user.target
Enter fullscreen mode Exit fullscreen mode

To switch back to GUI mode:

systemctl isolate graphical.target
Enter fullscreen mode Exit fullscreen mode

Real-Time Use Cases of Runlevels

  1. Recovering a Broken System — Boot into single-user mode (Runlevel 1) to fix misconfigured files or disk errors.
  2. Running a Server Efficiently — Use Runlevel 3 (multi-user CLI mode) to optimize performance by disabling GUI.
  3. Switching to Maintenance Mode — If you need to perform updates or maintenance, temporarily move to Runlevel 1.
  4. Troubleshooting Network IssuesRunlevel 2 (no network) helps isolate networking problems.
  5. Automating Startup Services — Customize runlevel scripts for specific startup configurations.

Conclusion

Understanding Linux runlevels is crucial for system administrators and advanced users. Whether you’re using an old SysVinit-based system or a modern systemd-based one, knowing how to check, change, and utilize runlevels can improve system management.

By mastering runlevels, you can efficiently manage services, troubleshoot issues, and optimize system performance. Start experimenting with different runlevels today to enhance your Linux skills!


@vikram_patel, @thisaakash , @shreyansh_1904 Thanks for colloborations.

Top comments (0)