How to Check and Set Linux systemd Runlevels

()

Runlevel today implemented on systemd, previously most Linux distributions were equipped with the init system, Sys-V style. Sys-V used seven different runlevels to determine which processes can be started on the system. For example, runlevel 3 was usually reserved for the command line and associated programs, while runlevel 5 launched a GUI and all the processes required to do so. Results may vary by distribution.

The vast majority of Linux distributions have adopted systemd as their init system. Some distributions still use Sys-V where the traditional implementation of runlevels still exists. The systemd implementation adopted the concept of runlevels, converting them to systemd “targets”.

On some systems there are still scraps of Sys-V, on which commands such as runlevel can still be found. But some modern systemd distributions have completely eradicated this support. In this tutorial we show how to check the current runlevel on Linux.

Check current Linux runlevel?

Check current Linux runlevel?

Below are two commands to determine the current Linux runlevel.

$ runlevel
N 5
$ who -r
  run-level 5 2022-11-07 14:52

As you can see, runlevel 5 has started here. Alternatively, the command who -r can be ran. The runlevel command is only available on some systemd distributions, but should work on any sys-V system.

The different runlevels were assigned to corresponding systemd targets. This command can be used to check the targets.

$ ls -l /lib/systemd/system/runlevel*

Below is the output of the runlevels at a Linux Mint, which is based on Ubuntu/Debian.

$ lrwxrwxrwx 1 root root 15 Aug 31 17:27 /lib/systemd/system/runlevel0.target -> poweroff.target
lrwxrwxrwx 1 root root 13 Aug 31 17:27 /lib/systemd/system/runlevel1.target -> rescue.target
lrwxrwxrwx 1 root root 17 Aug 31 17:27 /lib/systemd/system/runlevel2.target -> multi-user.target
lrwxrwxrwx 1 root root 17 Aug 31 17:27 /lib/systemd/system/runlevel3.target -> multi-user.target
lrwxrwxrwx 1 root root 17 Aug 31 17:27 /lib/systemd/system/runlevel4.target -> multi-user.target
lrwxrwxrwx 1 root root 16 Aug 31 17:27 /lib/systemd/system/runlevel5.target -> graphical.target
lrwxrwxrwx 1 root root 13 Aug 31 17:27 /lib/systemd/system/runlevel6.target -> reboot.target

/lib/systemd/system/runlevel1.target.wants:
Total 0

/lib/systemd/system/runlevel2.target.wants:
Total 0

/lib/systemd/system/runlevel3.target.wants:
Total 0

/lib/systemd/system/runlevel4.target.wants:
Total 0

/lib/systemd/system/runlevel5.target.wants:
Total 0

Linux Runlevels

0Halt shut down the system
1Single-user mode (Rescue and special administration)
2Multi-user mode not start network interfaces and daemons
3Multi-user mode with Networking starts system normally
4Not Used
5Multi-user mode as runlevel 3 + display manager X11 GUI
6Reboot the system

As with runlevels, there are 7 systemd targets by default. The two main targets are multi-user.target and graphical.target. The following command displays the default systemd targets.

$ systemctl get-default
graphical.target

In this example, graphical.target is started, which makes sense because we need a graphical desktop environment. On a server where often no GUI is running, multi-user.target is usually started.

$ systemctl get-default
multi-user.target

Use the command to see which services are associated with this target.

$ systemctl list-dependencies graphic.target
graphic.target

Try the following command to see which systemd target (or runlevel) a service needs to run. In this example, we check the SSH service.

$ systemctl show -p WantedBy sshd.service
WantedBy=multi-user.target

How to set systemd?

The Linux systemd runlevel can be set with this command.

$ sudo systemctl set-default multi-user.target

The next time the system boots in multi-user mode (multi-user.target).

How useful was this post?

Click on a star to rate it!

Average rating / 5. Vote count:

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Leave a Reply

Your email address will not be published. Required fields are marked *