How to switch boot target to text or GUI in systemd Linux nixCraft

Most modern Linux distro uses systemd as init replacement. It is a suite of basic building blocks for Linux distros such as RHEL/CentOS & co, 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, muli 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.

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements Linux systemd
reboot command:
sudo systemctl reboot

How to switch boot target to text or GUI in systemd LinuxHow to switch boot target to text or GUI in systemd Linux

How to switch boot target to GUI (graphical UI)

Want to revert change boot to GUI instead of console/text mode? Try:

  1. Open the Linux terminal application.
  2. Again, for remote Linux servers, use the ssh command.
  3. Find which target unit is used by default:
    systemctl get-default
  4. To change boot target to the GUI mode:
    sudo systemctl set-default
  5. Make sure you reboot the Linux box using the reboot command:
    sudo reboot

Changing Systemd Boot Target in Linux To GUIChanging Systemd Boot Target in Linux To GUI

Understanding boot targets under systemd

The default target is set by /etc/systemd/system/ Run the following ls command to verify it using the symbolic link:
ls -l /etc/systemd/system/
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
# list all loaded units in any state #
systemctl list-units --type target --all

Here is a list of all currently loaded target units on Ubuntu Linux 20.04 LTS desktop:

 UNIT LOAD ACTIVE SUB DESCRIPTION loaded active active Basic System loaded active active Block Device Preparation for /dev/mapper/md1_crypt loaded active active Bluetooth loaded active active Local Encrypted Volumes loaded active active Login Prompts loaded active active Graphical Interface loaded active active Local File Systems (Pre) loaded active active Local File Systems loaded active active Containers loaded active active Multi-User System loaded active active Network is Online loaded active active Network (Pre) loaded active active Network loaded active active User and Group Name Lookups loaded active active Paths loaded active active Remote File Systems (Pre) loaded active active Remote File Systems loaded active active Slices loaded active active Sockets loaded active active Sound Card loaded active active Swap loaded active active System Initialization loaded active active System Time Set loaded active active System Time Synchronized loaded active active Timers loaded active active Libvirt guests shutdown LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type. 26 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'. 

Sysv runleves vs systemd targets

Let us understand older Sysv runlevels and their equivalents under systemd.

Table 1
Systemd target Runlevel Description Old command New command, 0 Power off the Linux box. init 0 systemctl isolate, 1 Boot into emergency rescue mode (single user mode). init 1 systemctl isolate, 2 Text based multi-user system that does not configure network interfaces and does not export networks services. init 2 systemctl isolate, 3 Starts the system normally in multi-user text mode for the Linux server usage. init 3 systemctl isolate, 4 For special purposes text mode. init 4 systemctl isolate, 5 Same as runlevel 3 and boot into GUI display manager. init 5 systemctl isolate, 6 Reboot the Linux desktop or laptop. init 5 systemctl isolate

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:

Patreon supporters only guides 🤓

  • No ads and tracking
  • In-depth guides for developers and sysadmins at Opensourceflare✨
  • Join my Patreon to support independent content creators and start reading latest guides:

Join Patreon ➔

sudo ln -s -f -v /lib/systemd/system/ /etc/systemd/system/

Want to go back to the text mode:

sudo ln -s -f -v /lib/systemd/system/ /etc/systemd/system/

Verify it using the ls command
ls -l /etc/systemd/system/

Changing the default systemd target using symbolic link under LinuxChanging the default systemd target using symbolic link under Linux

Learn how to change the default target by creating a symlink to the systemd target (click to enlarge)

See how create soft link with under Linux or Unix using the ln command for more info.

How to boot in to rescue mode

Run the following systemctl command
$ sudo systemctl rescue
We can change to a different systemd target unit in the current log in session using the CLI as follows:
sudo systemctl isolate
# OR #
sudo systemctl isolate

What would get started if I booted into a specific target?

The systemd can calculate the “initial” transaction it would execute on boot, try something like this to see what services and stuff loaded in the
systemd --test --system
The --test option is used to determine the initial start-up transaction, dump it, and exit without actually executing any of the determined jobs. How cool is that?

Summing up

You learned about systemd targets and older runlevels used by SysV init system. Further, I explained how to use the systemctl command to switch between text and GUI mode from the CLI. There is more than one way to achieve results in Linux. Hence, this page also described how to modify the default target using the symbolic link method too. Debian Linux project maintains a good systemd specific page and strongly endorses you to visit the wiki page. However, you can read documentation locally using the man command in an emergency where the internet is not available:
man systemctl
man init
man upstart ini
man systemd


Posted by Contributor