Controlling The Boot Process: Selecting A Systemd Target
Controlling The Boot Process: Selecting A Systemd Target
systemctl poweroff stops all running services, unmounts all file systems (or remounts them
read-only when they cannot be unmounted), and then powers down the system.
systemctl reboot stops all running services, unmounts all file systems, and then reboots the
system.
systemctl halt are also available to stop the system, but unlike poweroff, these commands do
not power off the system; they bring a system down to a point where it is safe to power it off
manually.
You can also use the shorter version of these commands, poweroff, reboot and halt which
are symbolic links to their systemctl equivalents.
Target Purpose
graphical.target System supports multiple users, graphical- and text-based logins.
multi-
user.target
System supports multiple users, text-based logins only.
A target can be a part of another target. For example, the graphical.target includes
multi-user.target, which in turn depends on basic.target and others. You can view
these dependencies with the following command.
Not all targets can be isolated. You can only isolate targets that have AllowIsolate=yes set
in their unit files. For example, you can isolate the graphical target, but not the cryptsetup
target.
...output omitted...
[Unit]
Description=Graphical Interface
Documentation=man:systemd.special(7)
Requires=multi-user.target
Wants=display-manager.service
Conflicts=rescue.service rescue.target
AllowIsolate=yes
systemd.unit=rescue.target
Reboot workstation.
Notice that after reboot the system presents a text-based console and not a graphical login
anymore.
In this second part of the exercise, you are practicing the rescue mode.
Access the boot loader by rebooting workstation again. From within the boot loader menu,
boot into the rescue target.
Initiate the reboot.
When the boot loader menu appears, press any key to interrupt the countdown (except
Enter, which would initiate a normal boot).
Use the cursor keys to highlight the default boot loader entry.
Press e to edit the current entry.
Using the cursor keys, navigate to the line that starts with linux.
Press End to move the cursor to the end of the line.
Append systemd.unit=rescue.target to the end of the line.
Press Ctrl+x to boot using the modified configuration.
Log in to rescue mode. The root password is redhat You may need to hit enter to
get a clean prompt.
Confirm that in rescue mode, the root file system is in read/write mode.
To reset the root password from this point, use the following procedure:
1. Remount /sysroot as read/write.
2. Switch into a chroot jail, where /sysroot is treated as the root of the file-system
tree.
4. Make sure that all unlabeled files, including /etc/shadow at this point, get relabeled
during boot.
5. Type exit twice. The first command exits the chroot jail, and the second command
exits the initramfs debug shell.
At this point, the system continues booting, performs a full SELinux relabel, and then reboots
again.
1.
1. When the boot-loader menu appears, press any key to interrupt the countdown,
except Enter.
2. Looking at the error from the previous boot, it appears that at least parts of the system
are still functioning. Because you know the root password, redhat, attempt an
emergency boot.
1. Use the cursor keys to highlight the default boot loader entry.
2. Press e to edit the current entry.
3. Use the cursor keys to navigate to the line that starts with linux.
4. Press End to move the cursor to the end of the line.
5. Append systemd.unit=emergency.target to the end of the line.
6. Press Ctrl+x to boot using the modified configuration.
3. Log in to emergency mode. The root password is redhat.
6. Use the mount -a command to attempt to mount all the other file systems. With the
--all (-a) option, the command mounts all the file systems listed in /etc/fstab that
are not yet mounted.
Update systemd for the system to register the new /etc/fstab configuration.
8. Verify that your /etc/fstab is now correct by attempting to mount all entries.
9. Reboot the system and wait for the boot to complete. The system should now boot
normally.
Configure the system to automatically perform a full SELinux relabel after boot.
Type exit twice to continue booting your system. The system fails to boot because of
an issue you resolve in the next step.
2) The system fails to boot. A start job does not seem to complete. From the console, fix the
issue.
Boot the system into emergency mode. To do so, reboot serverb by sending a
Ctrl+Alt+Del to your system using the relevant button or menu entry.
When the boot-loader menu appears, press any key to interrupt the countdown, except
Enter.
Use the cursor keys to highlight the default boot loader entry.
Press e to edit the current entry.
Use the cursor keys to navigate to the line that starts with linux.
Press End to move the cursor to the end of the line.
Append systemd.unit=emergency.target to the end of the line.
Press Ctrl+x to boot using the modified configuration.
Log in to emergency mode. The root password is redhat.
Use the mount -a command to attempt to mount all the other file systems.
Update systemd for the system to register the new /etc/fstab configuration.
Verify that your /etc/fstab is now correct by attempting to mount all entries.
Reboot the system and wait for the boot to complete. Because you created the
/.autorelabel file in the first step, after setting the root password, the system runs
an SELinux relabel, then reboots again by itself. The system should now boot
normally.
3) Change the default systemd target on serverb for the system to automatically start a
graphical interface when it boots.
No graphical interface is installed yet on serverb. For this exercise, only set the default
target and do not install the packages.
Log in to serverb as the root user. Use redhat as the password.
Use the systemctl set-default command to set graphical.target as the default
target.
graphical.target