Boot or Change System Into Different Operating Modes Optional
This article explains how to use systemd targets in Linux to control the boot process and modify the default boot target for different environments.
In this article, we explore how Linux leverages systemd targets to control the boot process and how you can modify the default boot target to suit different system environments. By understanding systemd targets, you gain flexibility in managing resource usage and operational modes.Currently, the Linux system boots to a graphical login screen. At startup, the operating system loads various programs and services in a specific order using instructions defined in systemd target files. To see which boot target is active by default, run:
Copy
Ask AI
systemctl get-default
If the output is “graphical.target,” it means the system is configured to boot into a full graphical environment. The corresponding graphical.target file contains the necessary instructions to start services and programs required for a graphical login.Booting into the graphical target requires additional system resources due to the loading of the graphical user interface. If you do not need the graphical environment, you can change the default boot target to a more resource-efficient option, such as the multi-user target. This target provides essential services—like daemons and network services—running in a text-based mode. To switch the default boot target, execute:
Copy
Ask AI
sudo systemctl set-default multi-user.target
Changing the default boot target means that on the next reboot, the system will operate in text mode rather than launching a graphical interface.
Below is an example session showing how to check and change the default boot target:
Copy
Ask AI
# Check the current default targetjeremy@kodekloud:~$ systemctl get-defaultgraphical.target# Set the default target to multi-userjeremy@kodekloud:~$ sudo systemctl set-default multi-user.target[sudo] password for jeremy:Removed "/etc/systemd/system/default.target".Created symlink /etc/systemd/system/default.target → /lib/systemd/system/multi-user.target.jeremy@kodekloud:~$
The multi-user target is named so because it supports simultaneous logins by multiple users, while still keeping network services active to ensure continuous connectivity.After changing the default target, reboot the system. Instead of the usual graphical login screen, you will encounter a text-based login console, similar to the following:
Copy
Ask AI
Ubuntu 23.10 kodekloud tty1kodekloud: jeremyPassword:Welcome to Ubuntu 23.10 (GNU/Linux 6.5.0-27-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage68 updates can be applied immediately.To see these additional updates run: apt list --upgradeableThe list of available updates is more than a week old.To check for new updates, run: sudo apt updateLast login: Tue May 28 12:25:21 PDT 2024 on tty1jeremy@kodekloud:~$
If you temporarily need a graphical interface—perhaps to work with a 3D modeling application—you don’t have to permanently switch the boot target. Instead, you can start the graphical environment immediately using:
Copy
Ask AI
sudo systemctl isolate graphical.target
This command activates the graphical interface on demand without altering the system’s default text-based boot mode.Additional systemd targets include emergency.target and rescue.target. The table below summarizes the most commonly used targets and their purposes:
Target
Description
Use Case
Command Example
graphical.target
Boots into a full graphical desktop environment
Standard desktop usage
systemctl get-default
multi-user.target
Boots into a text-based environment with network services
Server or low-resource environments
sudo systemctl set-default multi-user.target
emergency.target
Boots with minimal system services; root FS is read-only
Critical troubleshooting when other services cause issues
(Invoked automatically when selected)
rescue.target
Loads essential services with a root shell access
Administrative tasks in a minimal environment
(Invoked automatically when selected)
When booting into emergency.target or rescue.target, ensure that the root account has a password set. Without a root password, these modes will not be accessible.
This concludes the demonstration on changing systemd targets and boot modes. For further details on system management and troubleshooting, be sure to refer to the official systemd documentation.