Chapter 14. Booting into a target system state
As a system administrator, you can control the boot process of your system, and define the state you want your system to boot into. This is called a systemd
target, and it is a set of systemd
units that your system starts to reach a certain level of functionality. While working with systemd targets, you can view the default target, select a target at runtime, change the default boot target, boot into emergency or rescue target.
14.1. Target unit files
Targets in systemd
are groups of related units that act as synchronization points during the start of your system. Target unit files, which end with the .target
file extension, represent the systemd
targets. The purpose of target units is to group together various systemd
units through a chain of dependencies.
Consider the following examples:
-
The
graphical.target unit
for starting a graphical session, starts system services such as the GNOME Display Manager (gdm.service
) or Accounts Service (accounts-daemon.service
), and also activates themulti-user.target unit
. -
Similarly, 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 namedbasic.target
.
You can set the following systemd
targets as default or current targets:
Table 14.1. Common systemd
targets
rescue | unit target that pulls in the base system and spawns a rescue shell |
multi-user | unit target for setting up a multi-user system |
graphical | unit target for setting up a graphical login screen |
emergency | unit target that starts an emergency shell on the main console |
Additional resources
-
systemd.special(7)
man page -
systemd.target(5)
man page
14.2. Changing the default target to boot into
When a system starts, systemd
activates the default.target
symbolic link, which points to the true target unit. You can find the currently selected default target unit in the /etc/systemd/system/default.target
file. Each target represents a certain level of functionality and is used for grouping other units. Additionally, target units serve as synchronization points during boot. You can change the default target your system boots into. When you set a default target unit, the current target remains unchanged until the next reboot.
Prerequisites
- Root access
Procedure
Determine the current default target unit
systemd
uses to start the system:# systemctl get-default graphical.target
List the currently loaded targets:
# systemctl list-units --type target
Configure the system to use a different target unit by default:
# systemctl set-default <name>.target
Replace
<name>
with the name of the target unit you want to use by default.Example: # systemctl set-default multi-user.target Removed /etc/systemd/system/default.target Created symlink /etc/systemd/system/default.target -> /usr/lib/systemd/system/multi-user.target
Verify the default target unit:
# systemctl get-default multi-user.target
Apply the changes by rebooting:
# reboot
Additional resources
-
systemctl(1)
man page -
systemd.special(7)
man page -
bootup(7)
man page
14.3. Changing the current target
On a running system, you can change the target unit in the current boot without reboot. If you switch to a different target, systemd
starts all services and their dependencies that this target requires, and stops all services that the new target does not enable. Isolating a different target affects only the current boot.
Procedure
Optional: Determine the current target:
# systemctl get-default graphical.target
Optional: Display the list of targets you can select:
# systemctl list-units --type target
NoteYou can only isolate targets that have the
AllowIsolate=yes
option set in the unit files.Change to a different target unit in the current boot:
# systemctl isolate <name>.target
Replace <name> with the name of the target unit you want to use in the current boot.
Example: # systemctl isolate multi-user.target
This command starts the target unit named
multi-user
and all dependent units, and immediately stops all other unit.
Additional resources
-
systemctl(1)
man page
14.4. Booting to rescue mode
You can boot to the rescue mode that provides a single-user environment for troubleshooting or repair if the system cannot get to a later target, and the regular booting process fails. In rescue mode, the system attempts to mount all local file systems and start certain important system services, but it does not activate network interfaces.
Prerequisites
- Root access
Procedure
To enter the rescue mode, change the current target in the current session:
# systemctl rescue 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!
NoteThis command is similar to
systemctl isolate rescue.target
, but it also sends an informative message to all users that are currently logged into the system.To prevent
systemd
from sending a message, enter the following command with the--no-wall
command-line option:# systemctl --no-wall rescue
Troubleshooting steps
If your system is not able to enter the rescue mode, you can boot to emergency mode, which provides the most minimal environment possible. In emergency mode, the system mounts the root file system only for reading, does not attempt to mount any other local file systems, does not activate network interfaces, and only starts a few essential services.
14.5. Troubleshooting the boot process
As a system administrator, you can select a non-default target at boot time to troubleshoot the boot process. Changing the target at boot time affects only a single boot. You can boot to emergency mode, which provides the most minimal environment possible.
Procedure
- Reboot the system, and interrupt the boot loader menu countdown by pressing any key except the Enter key, which would initiate a normal boot.
- Move the cursor to the kernel entry that you want to start.
- Press the E key to edit the current entry.
Move to the end of the line that starts with
linux
and press Ctrl+E to jump to the end of the line:linux ($root)/vmlinuz-5.14.0-70.22.1.e19_0.x86_64 root=/dev/mapper/rhel-root ro crash\ kernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv/swap rhgb quiet
To choose an alternate boot target, append the
systemd.unit=
parameter to the end of the line that starts withlinux
:linux ($root)/vmlinuz-5.14.0-70.22.1.e19_0.x86_64 root=/dev/mapper/rhel-root ro crash\ kernel=auto resume=/dev/mapper/rhel-swap rd.lvm.lv/swap rhgb quiet systemd.unit=<name>.target
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.