Switch Boot Target to Text or GUI in systemd Linux
Most modern Linux distro uses systemd
as init
replacement.
It is a suite of basic building blocks for Linux distros such as RHEL/CentOS, OpenSUSE/SUSE, Fedora, Arch, Debian, Ubuntu, and more.
By default, most distro boot into GUI, but you can change to text or vice versa.
The older version of the Linux distros came with SysV init
or Upstart.
Such init
provided a set of runlevels for text, multi user, and GUI system.
However, systemd
uses the concept of targets instead of runlevels.
This page explains procedures to implement runlevel like config when working with systemd
targets.
In other words, you will learn how to switch between text or GUI mode using systemd
instead of init
levels on modern Linux distros.
Switch Boot Target to Text
The procedure is as follows to change into a text mode runlevel under systemd
:
Open the terminal application.
For remote Linux servers, use the SSH command.
Find which target unit is used by default:
systemctl get-default
To change boot target to the text mode:
sudo systemctl set-default multi-user.target
Reboot the system using the reboot command:
sudo reboot
Switch Boot Target to GUI (Graphical UI)
Want to revert change boot to GUI instead of console/text mode? Try:
Open the Linux terminal application.
Again, for remote Linux servers, use the SSH command.
Find which target unit is used by default:
systemctl get-default
To change boot target to the GUI mode:
sudo systemctl set-default graphical.target
Make sure you reboot the Linux box using the reboot command:
sudo reboot
Understanding Boot Targets Under systemd
The default target is set by /etc/systemd/system/default.target
.
Run the following ls
command to verify it using the symbolic link:
ls -l /etc/systemd/system/default.target |
Of course, we can use the systemctl
command itself too:
systemctl get-default |
Listing all systemd targets
Execute the following command:
systemctl list-units --type target |
Here is a list of all currently loaded target units on Ubuntu Linux 20.04 LTS desktop:
1 | UNIT LOAD ACTIVE SUB DESCRIPTION |
SysV Runleves vs systemd Targets
Let us understand older SysV runlevels and their equivalents under systemd
.
systemd Target |
runlevel |
Description | Old Command | New Command |
---|---|---|---|---|
runlevel0.target , poweroff.target |
0 | Power off the Linux box. | init 0 |
systemctl isolate poweroff.target |
runlevel1.target , rescue.target |
1 | Boot into emergency rescue mode (single user mode). | init 1 |
systemctl isolate rescue.target |
runlevel2.target , multi-user.target |
2 | Text based multi-user system that does not configure network interfaces and does not export networks services. | init 2 |
systemctl isolate runlevel2.target |
runlevel3.target , multi-user.target |
3 | Starts the system normally in multi-user text mode for the Linux server usage. | init 3 |
systemctl isolate runlevel3.target |
runlevel4.target , multi-user.target |
4 | For special purposes text mode. | init 4 |
systemctl isolate runlevel4.target |
runlevel5.target , graphical.target |
5 | Same as runlevel 3 and boot into GUI display manager. | init 5 |
systemctl isolate graphical.target |
runlevel6.target , reboot.target |
6 | Reboot the Linux desktop or laptop. | init 6 |
systemctl isolate reboot.target |
How to change the default systemd target using symbolic link
Earlier I explained how to use the systemctl
command.
But one can use other commands.
Therefore, use the ln
command as follows to switch to the GUI mode:
sudo ln -s -f -v \ |
Want to go back to the text mode:
sudo ln -s -f -v \ |
Verify it using the ls
command
ls -l /etc/systemd/system/default.target |