Understanding Linux Runlevels

In Linux, a runlevel is a mode of operation that defines what services and processes are running on the system. Each runlevel is assigned a specific purpose, such as system shutdown, single-user mode, or multi-user mode.

Common Runlevels

How to Change Runlevels

To change the runlevel in Linux, you can use the telinit or systemctl command, depending on your system's init system.

Using telinit Command

For systems using SysVinit, you can change the runlevel with the telinit command:

sudo telinit 
Example: To switch to runlevel 3 (multi-user mode with networking):
sudo telinit 3

Using systemctl Command

For systems using systemd, you can change the runlevel by switching the target:

sudo systemctl isolate .target
Example: To switch to graphical mode (runlevel 5 equivalent):
sudo systemctl isolate graphical.target

To switch to multi-user mode (runlevel 3 equivalent):

sudo systemctl isolate multi-user.target

To switch to single-user mode (runlevel 1 equivalent):

sudo systemctl isolate rescue.target

Checking the Current Runlevel

To check the current runlevel, use the following command:

runlevel
or
systemctl get-default
or
who -r
    

The output will show the previous and current runlevels.