Systemd is a modern init system for Linux: a system and service manager which is compatible with the popular SysV init system and LSB init scripts. It was intended to overcome the shortcomings of SysV init as explained in the following article.
On Unix-like systems such as Linux, the current operating state of the operating system is known as a runlevel; it defines what system services are running. Under popular init systems like SysV init, runlevels are identified by numbers. However, in systemd runlevels are referred to as targets.
Suggested Read: Managing System Startup Process and Services (SysVinit, Systemd and Upstart)
In this article, we will explain how to change runlevels (targets) with systemd. Before we move any further, let’s briefly under the relationship between runlevels numbers and targets.
- Run level 0 is matched by poweroff.target (and runlevel0.target is a symbolic link to poweroff.target).
- Run level 1 is matched by rescue.target (and runlevel1.target is a symbolic link to rescue.target).
- Run level 3 is emulated by multi-user.target (and runlevel3.target is a symbolic link to multi-user.target).
- Run level 5 is emulated by graphical.target (and runlevel5.target is a symbolic link to graphical.target).
- Run level 6 is emulated by reboot.target (and runlevel6.target is a symbolic link to reboot.target).
- Emergency is matched by emergency.target.
How to View Current target (run level) in Systemd
When the system boots, by default systemd activates the default.target unit. It’s main work is to activate services and other units by pulling them in via dependencies.
To view the default target, type the command below.
#systemctl get-default graphical.target
To set the default target, run the command below.
# systemctl set-default multi-user.target
How to Change the target (runlevel) in Systemd
While the system is running, you can switch the target (run level), meaning only services as well as units defined under that target will now run on the system.
To switch to runlevel 3, run the following command.
# systemctl isolate multi-user.target
To change the system to runlevel 5, type the command below.
# systemctl isolate graphical.target
For more information about systemd, read through these useful articles:
- How to Manage ‘Systemd’ Services and Units Using ‘Systemctl’ in Linux
- How to Create and Run New Service Units in Systemd Using Shell Script
- Managing System Startup Process and Services (SysVinit, Systemd and Upstart)
- Manage Log Messages Under Systemd Using Journalctl [Comprehensive Guide]
In this guide, we showed how to change runlevels (targets) with systemd. Use the comment form below to send us any questions or thoughts concerning this article.
What’s the equivalent of run-level 2? i.e. multi-user, but no networking.
Troubleshooting some (probable) networking issues that prevent the server from fully booting. Normally I would boot into run-level 2, so I have multi-user, but without networking enabled.
There used to be a good GUI graphical interface for viewing enabling and disabling stuff on the various runlevels… what happened to that?
Thanks for the clear, concise explanation. It is needed and appreciated. However, I’m looking for a way to find the current target, not necessarily the same thing as the default target.
I’m writing a script using the runlevel man page as a guide. Some bright soul pointed out
`who -r`
gives the current run level (but not target). There should be an easier way (like get.target or similar).Have I missed something? TIA.
Thanks for the great details. It is really helpful.
Just what I needed: changing the runlevel using SystemD without rebooting, thank you!
@Pedro
Okay, thanks for the feedback.
Nice article and helpful info since I did need to know this.
Unfortunately I needed to look up something this simple as systemd is change for change sake and is unnecessarily over complicated.
There was nothing wrong with # init 3
@linuxdood
Thanks for the kind words of appreciation and for sharing your thoughts about systemd and init.
Thanks. This is well written. I had read another source that did not mention the graphical target so I ended up without a GUI for a while :)
@Eric
Welcome, we are overjoyed to know that you found this article useful. Many thanks for the feedback.
probably a typo: runlevel1.target cannot be a link to both poweroff.target and rescue.target
@Fred
Ooops, that’s correct. We will update the article soon; it is supposed to read:
“Run level 0 is matched by poweroff.target (and runlevel0.target is a symbolic link to poweroff.target)”