RHCSA Rapid Track
Objectives
After completing this section, you should be able to:
Describe the Red Hat Enterprise Linux boot process.
Set the default target used when booting.
Boot a system to a non-default target.
Describing the Red Hat Enterprise Linux 8 Boot Process
Modern computer systems are complex combinations of hardware and software.
Starting from an undefined, powered-down state to a running system with a login prompt requires a large number of pieces of hardware and software to work together.
The following list gives a high-level overview of the tasks involved for a physical x86_64 system booting Red Hat Enterprise Linux 8.
The list for x86_64 virtual machines is roughly the same, but the hypervisor handles some of the hardware-specific steps in software.
The machine is powered on. The system firmware, either modern UEFI or older BIOS, runs a Power On Self Test (POST) and starts to initialize some of the hardware.
Configured using the system BIOS or UEFI configuration screens that you typically reach by pressing a specific key combination, such as F2, early during the boot process.
The system firmware searches for a bootable device, either configured in the UEFI boot firmware or by searching for a Master Boot Record (MBR) on all disks, in the order configured in the BIOS.
Configured using the system BIOS or UEFI configuration screens that you typically reach by pressing a specific key combination, such as F2, early during the boot process.
The system firmware reads a boot loader from disk and then passes control of the system to the boot loader. On a Red Hat Enterprise Linux 8 system, the boot loader is the GRand Unified Bootloader version 2 (GRUB2).
Configured using the grub2-install command, which installs GRUB2 as the boot loader on the disk.
GRUB2 loads its configuration from the
/boot/grub2/grub.cfgfile and displays a menu where you can select which kernel to boot.Configured using the
/etc/grub.d/directory, the/etc/default/grubfile, and the grub2-mkconfig command to generate the/boot/grub2/grub.cfgfile.After you select a kernel, or the timeout expires, the boot loader loads the kernel and initramfs from disk and places them in memory. An
initramfsis an archive containing the kernel modules for all the hardware required at boot, initialization scripts, and more. On Red Hat Enterprise Linux 8, theinitramfscontains an entire usable system by itself.Configured using the
/etc/dracut.conf.d/directory, the dracut command, and the lsinitrd command to inspect theinitramfsfile.The boot loader hands control over to the kernel, passing in any options specified on the kernel command line in the boot loader, and the location of the
initramfsin memory.Configured using the
/etc/grub.d/directory, the/etc/default/grubfile, and the grub2-mkconfig command to generate the/boot/grub2/grub.cfgfile.The kernel initializes all hardware for which it can find a driver in the
initramfs, then executes /sbin/init from theinitramfsas PID 1. On Red Hat Enterprise Linux 8,/sbin/initis a link tosystemd.Configured using the kernel
init=command-line parameter.The
systemdinstance from theinitramfsexecutes all units for theinitrd.targettarget. This includes mounting the root file system on disk on to the/sysrootdirectory.Configured using
/etc/fstabThe kernel switches (pivots) the root file system from
initramfsto the root file system in/sysroot.systemdthen re-executes itself using the copy ofsystemdinstalled on the disk.systemdlooks for a default target, either passed in from the kernel command line or configured on the system, then starts (and stops) units to comply with the configuration for that target, solving dependencies between units automatically. In essence, asystemdtarget is a set of units that the system should activate to reach the desired state. These targets typically start a text-based login or a graphical login screen.Configured using
/etc/systemd/system/default.targetand/etc/systemd/system/.
Rebooting and Shutting Down
To power off or reboot a running system from the command line, you can use the systemctl command.
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.
You can also use the shorter version of these commands, poweroff and reboot, which are symbolic links to their systemctl equivalents.
Note
systemctl halt and 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.
Selecting a Systemd Target
A systemd target is a set of systemd units that the system should start to reach a desired state.
The following table lists the most important targets.
Table 9.4. Commonly Used Targets
| Target | Purpose |
|---|---|
graphical.target
| System supports multiple users, graphical- and text-based logins. |
multi-user.target
| System supports multiple users, text-based logins only. |
rescue.target
| sulogin prompt, basic system initialization completed. |
emergency.target
|
sulogin prompt, initramfs pivot complete, and system root mounted on / read 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.
[user@host ~]$systemctl list-dependencies graphical.target | grep targetgraphical.target * └─multi-user.target * ├─basic.target * │ ├─paths.target * │ ├─slices.target * │ ├─sockets.target * │ ├─sysinit.target * │ │ ├─cryptsetup.target * │ │ ├─local-fs.target * │ │ └─swap.target ...output omitted...
To list the available targets, use the following command.
[user@host ~]$systemctl list-units --type=target --allUNIT LOAD ACTIVE SUB DESCRIPTION --------------------------------------------------------------------------- basic.target loaded active active Basic System cryptsetup.target loaded active active Local Encrypted Volumes emergency.target loaded inactive dead Emergency Mode getty-pre.target loaded inactive dead Login Prompts (Pre) getty.target loaded active active Login Prompts graphical.target loaded inactive dead Graphical Interface ...output omitted...
Selecting a Target at Runtime
On a running system, administrators can switch to a different target using the systemctl isolate command.
[root@host ~]#systemctl isolate multi-user.target
Isolating a target stops all services not required by that target (and its dependencies), and starts any required services not yet started.
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.
[user@host ~]$systemctl cat graphical.target# /usr/lib/systemd/system/graphical.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 After=multi-user.target rescue.service rescue.target display-manager.serviceAllowIsolate=yes[user@host ~]$systemctl cat cryptsetup.target# /usr/lib/systemd/system/cryptsetup.target ...output omitted... [Unit] Description=Local Encrypted Volumes Documentation=man:systemd.special(7)
Setting a Default Target
When the system starts, systemd activates the default.target target.
Normally the default target in /etc/systemd/system/ is a symbolic link to either graphical.target or multi-user.target.
Instead of editing this symbolic link by hand, the systemctl command provides two subcommands to manage this link: get-default and set-default.
[root@host ~]#systemctl get-defaultmulti-user.target[root@host ~]#systemctl set-default graphical.targetRemoved /etc/systemd/system/default.target. Created symlink /etc/systemd/system/default.target -> /usr/lib/systemd/system/graphical.target.[root@host ~]#systemctl get-defaultgraphical.target
Selecting a Different Target at Boot Time
To select a different target at boot time, append the systemd.unit= option to the kernel command line from the boot loader.
target.target
For example, to boot the system into a rescue shell where you can change the system configuration with almost no services running, append the following option to the kernel command line from the boot loader.
systemd.unit=rescue.target
This configuration change only affects a single boot, making it a useful tool for troubleshooting the boot process.
To use this method of selecting a different target, use the following procedure:
Boot or reboot the system.
Interrupt the boot loader menu countdown by pressing any key (except Enter which would initiate a normal boot).
Move the cursor to the kernel entry that you want to start.
Press e to edit the current entry.
Move the cursor to the line that starts with
linux. This is the kernel command line.Append
systemd.unit=. For example,target.targetsystemd.unit=emergency.target.Press Ctrl+x to boot with these changes.
References
info grub2 (GNU GRUB manual)
bootup(7), dracut.bootup(7), lsinitrd(1), systemd.target(5), systemd.special(7), sulogin(8), and systemctl(1) man pages
For more information, refer to the Managing services with systemd chapter in the Configuring basic system settings guide at https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/8/html-single/configuring_basic_system_settings/#managing-services-with-systemd