Chapter 3. Booting into a target system state
To set a permanent boot environment or enter a recovery mode, use systemd targets to have full control over your system functionality. The systemd init system is a set of systemd unit types such as systemd.target, multi-user.target, shutdown.target.
3.1. Target unit files Copy linkLink copied to clipboard!
To group various systemd units through a chain of dependencies during boot process of a system, you need to use targets in systemd. Targets in systemd are groups of related units to act as synchronization points during the start of your system.
Target unit files end with the .target file extension. It represents the systemd targets. For example, the multi-user.target unit starts other essential system services such as NetworkManager (NetworkManager.service) or D-Bus (dbus.service) and activates another target unit named basic.target.
You can set the following systemd targets as default or current targets:
| Target | Purpose |
|---|---|
|
| unit target that pulls in the base system and spawns a rescue shell |
|
| unit target for setting up a multi-user system |
|
| unit target for setting up a graphical login screen |
|
| unit target that starts an emergency shell on the main console |
For more information, see systemd.special(7) and systemd.target(5) man pages on your system
3.2. Changing the default target for booting a system Copy linkLink copied to clipboard!
To change the default target, you need to modify the current default.target symbolic link to point to the new target unit. When you set a new default target unit, the current target remains unchanged until the next reboot.
During the boot process, the system initializes the systemd target to which default.target points. Then, systemd resolves this link and boots into the defined target. The selected default target unit is present in the /etc/systemd/system/default.target file. Each target has a certain level of functionality and groups other units. Additionally, target units act as synchronization points during boot. The systemd target types include graphical.target, multi-user target, and so on.
Prerequisites
- You have administrative privileges.
Procedure
Display the current default target unit
systemduses to start the system:systemctl get-default
# systemctl get-defaultCopy to Clipboard Copied! Toggle word wrap Toggle overflow graphical.target
graphical.targetCopy to Clipboard Copied! Toggle word wrap Toggle overflow List the currently loaded targets:
systemctl list-units --type target
# systemctl list-units --type targetCopy to Clipboard Copied! Toggle word wrap Toggle overflow Configure the system to use a different target unit by default:
systemctl set-default <name>.target
# systemctl set-default <name>.targetCopy to Clipboard Copied! Toggle word wrap Toggle overflow Replace
<name>with the name of the target unit you want to use by default.systemctl set-default multi-user.target
# systemctl set-default multi-user.targetCopy to Clipboard Copied! Toggle word wrap Toggle overflow Removed /etc/systemd/system/default.target Created symlink /etc/systemd/system/default.target -> /usr/lib/systemd/system/multi-user.target
Removed /etc/systemd/system/default.target Created symlink /etc/systemd/system/default.target -> /usr/lib/systemd/system/multi-user.targetCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: To immediately switch to the new default target unit:
systemctl isolate default.target
# systemctl isolate default.targetCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Verification
Verify the default target unit:
systemctl get-default multi-user.target
# systemctl get-default multi-user.targetCopy to Clipboard Copied! Toggle word wrap Toggle overflow - Reboot the system.
3.3. Temporarily changing the current target Copy linkLink copied to clipboard!
To troubleshoot or recover the system, you can temporarily change the current target without rebooting the system. To switch to a different target, use the systemctl isolate command.
By selecting or changing these targets, you define and control selective services and units starting during the boot process. Also, you can view the current default, switch targets, or access the emergency shell prompt as needed
Prerequisites
- You have administrative privileges.
Procedure
Display the list of targets you can select:
systemctl list-units --type target
$ systemctl list-units --type targetCopy to Clipboard Copied! Toggle word wrap Toggle overflow Change to a different target unit in the current session:
systemctl isolate <name>.target
# systemctl isolate <name>.targetCopy to Clipboard Copied! Toggle word wrap Toggle overflow Replace <name> with the name of the target unit you want to use in the current session.
systemctl isolate multi-user.target
# systemctl isolate multi-user.targetCopy to Clipboard Copied! Toggle word wrap Toggle overflow This command starts the target unit named
multi-userand all dependent units, and immediately stops all other units that are not part of the new target. As this is a temporary operation, the system will boot again into the default target when you reboot the host. You can only isolate targets that have theAllowIsolate=yesoption set in the unit files.For details, see the
systemctl(1)man page on your system.
3.4. Booting to rescue mode Copy linkLink copied to clipboard!
To troubleshoot or repair the system, you can boot into the rescue mode to enter a single-user environment. This happens when the system fails to reach a later target and the existing booting process fails.
In the rescue mode, apart from not activating network interfaces, the system tries to mount all local file systems and start required system services.
Prerequisites
- You have administrative privileges.
Procedure
Enter the rescue mode:
systemctl rescue
# systemctl rescueCopy to Clipboard Copied! Toggle word wrap Toggle overflow Broadcast message from root@localhost on pts/0 (Fri 2023-03-24 18:23:15 CEST): The system is going down to rescue mode NOW!
Broadcast message from root@localhost on pts/0 (Fri 2023-03-24 18:23:15 CEST): The system is going down to rescue mode NOW!Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteThis command is similar to
systemctl isolate rescue.target, but it also sends an informative message to all users currently logged in the system.To prevent
systemdfrom sending a message, enter:systemctl --no-wall rescue
# systemctl --no-wall rescueCopy to Clipboard Copied! Toggle word wrap Toggle overflow
Troubleshooting
If you cannot boot the system in the rescue mode, you need to boot in the emergency mode to enter in a minimal environment. In the emergency mode, the system mounts the root file system only for reading and initiates essential services. Additionally, the system neither mounts any other local filesystems nor activates network interfaces.
3.5. Troubleshooting the boot process Copy linkLink copied to clipboard!
To enter in the most minimal environment for troubleshooting the boot process, you can select a non-default target at boot time. Choose the emergency mode to enter in the most minimal environment. Changing the target at boot time affects only a single boot event.
Prerequisites
- You have administrative privileges.
Procedure
-
Reboot the system, and interrupt the boot loader menu countdown by pressing any key except the
Enterkey to initiate a normal boot. - Select the kernel entry that you want to start.
-
Press the
ekey to edit the current entry. -
Navigate to the end of the line that starts with
linuxand press Ctrl+E to jump to the end of this line. To select a different boot target, append the
systemd.unit=parameter to the end of the line that starts withlinux:linux ... systemd.unit=<name>.target
linux ... systemd.unit=<name>.targetCopy to Clipboard Copied! Toggle word wrap Toggle overflow Replace
<name>with the name of the target unit you want to use. For example,systemd.unit=emergency.target- Press Ctrl+X to boot with these settings.