Most Linux distributions come with GUI-based desktop environments, and by default, they boot into the graphical mode. However, there is another mode called CLI mode, which is less resource-intensive. If your system hardware is struggling in GUI mode, it can be easily switched to CLI mode by changing the boot target.
In this tutorial, I will be covering the boot targets on Linux, and how to switch them using systemctl.
Note: The commands mentioned in this guide are executed on Ubuntu; they will work without any error on any Linux distribution with systemd init system.
What are Boot Targets
The boot target is a .target file Linux, which defines the system state. In order to understand the boot target, it is essential to learn the system run levels. In the older init systems like SysV, the run level terminology defines the states of the system. However, in systemd, the run levels are changed to target files. Run-levels and their associated target files are listed in the following table.
Run Level | Target Files | State |
0 | poweroff.target | Shutdown & Power off State |
1 | rescue.target | Starts the rescue shell |
2,3,4 | multi-user.target | Starts multi-user non-GUI shell |
5 | graphical.target | Starts multi-user GUI shell |
6 | reboot.target | Shutdown & Restart State |
The target files are located in the /lib/systemd/system directory.
How to Show the Current Boot Target
To get the current boot target file, use systemctl with the get-default option.
Or use the ls command with the -l flag, which indicates the long list format of the output.
How to Switch Boot Target
To switch the boot target on Linux, the systemctl command is used with the set-default option.
Replace the [Target-File] with the required target file name.
When selecting a target mode, there are two options available.
- Command Line Interface – CLI Mode
- Graphical User Interface – GUI Mode
The CLI, also known as the command-line interface, is a text-based tool commonly employed to set up web servers. It is simple and takes fewer resources. The target file that sets the CLI mode is multi-user.target. On the other hand, the graphical mode is easy to use, especially for beginners, and provides a fully customizable user interface. The graphical.target is the target file that sets the GUI mode.
Let’s explore how to switch the boot targets on Linux.
How to Switch Boot Target GUI to CLI
If you are using the GUI mode and want to switch to the CLI mode, the multi-user.target file will be used with the systemctl set-target command.
A symbolic link will be created between default.target and multi-user.target files.
After executing the command, reboot the system for verification.
How to Switch Boot Target CLI to GUI
To shift from a CLI to a GUI or graphical user interface, use graphical.target file with systemctl set-target command.
The next step is rebooting the system using the reboot command to boot into graphical mode.
You must have a display manager and desktop environment installed to switch from CLI mode to GUI mode. Otherwise, you cannot boot into GUI mode.
If you try to execute the above command without having the display manager and desktop environment, the system will boot back to CLI mode.
How to List All Target Files
To list all the systemd targets, use systemctl with the –type= option.
Conclusion
Two main boot options can be used to switch between the command line interface (CLI) and the graphical user interface (GUI). The target files multi-user.target and graphical.target correspond to both interfaces CLI and GUI, respectively. To switch between these boot targets, the systemctl set-default command is used with the respective target file. If you do not have a display manager and desktop environment, you cannot boot to GUI mode.