RHCSA Rapid Track
Course update
An updated version of this course is available that uses a newer version of Red Hat Enterprise Linux in the lab environment. Therefore, the RHEL 9.0 version of the lab environment will retire on December 31, 2024. Please complete any work in this lab environment before it is removed on December 31, 2024. For the most up-to-date version of this course, we recommend moving to the RHEL 9.3 version.
Describe the Red Hat Enterprise Linux boot process, set the default target when booting, and boot a system to a non-default target.
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 many pieces of hardware and software to work together.
The following list gives a high-level overview of the tasks for a physical x86_64 system that boots Red Hat Enterprise Linux 9.
The list for x86_64 virtual machines is similar, except that the hypervisor handles some hardware-specific steps in software.
The machine is powered on. The system firmware, either modern UEFI or earlier BIOS, runs a Power On Self Test (POST) and starts to initialize the hardware.
The system BIOS or UEFI is configured by pressing a specific key combination, such as F2, early during the boot process.
The UEFI boot firmware is configured by searching for a bootable device, which searches for or configures the Master Boot Record (MBR) on all disks.
The system BIOS or UEFI configuration is configured 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 9 system, the boot loader is the GRand Unified Bootloader version 2 (GRUB2).
The
grub2-installcommand installs GRUB2 as the boot loader on the disk for BIOS systems. Do not use thegrub2-installcommand directly to install the UEFI boot loader. RHEL 9 provides a prebuilt/boot/efi/EFI/redhat/grubx64.efifile, which contains the required authentication signatures for a Secure Boot system. Executinggrub2-installdirectly on a UEFI system generates a newgrubx64.efifile without those required signatures. You can restore the correctgrubx64.efifile from thegrub2-efipackage.GRUB2 loads its configuration from the
/boot/grub2/grub.cfgfile for BIOS, and from the/boot/efi/EFI/redhat/grub.cfgfile for UEFI, and displays a menu to select which kernel to boot.GRUB2 is configured by using the
/etc/grub.d/directory and the/etc/default/grubfile. Thegrub2-mkconfigcommand generates the/boot/grub2/grub.cfgor/boot/efi/EFI/redhat/grub.cfgfiles for BIOS or UEFI, respectively.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
initramfsimage is an archive with the kernel modules for all the required hardware at boot, initialization scripts, and more. In Red Hat Enterprise Linux 9, theinitramfsimage contains a bootable root file system with a running kernel and asystemdunit.The
initramfsimage is configured by using the/etc/dracut.conf.d/directory, thedracutcommand, and thelsinitrdcommand to inspect theinitramfsfile.The boot loader hands control over to the kernel, and passes in any specified options on the kernel command line in the boot loader, and the location of the
initramfsimage in memory.The boot loader is configured by using the
/etc/grub.d/directory, the/etc/default/grubfile, and thegrub2-mkconfigcommand to generate the/boot/grub2/grub.cfgfile.The kernel initializes all hardware for which it can find a driver in the
initramfsimage, and then executes the/sbin/initscript from theinitramfsimage as PID 1. On Red Hat Enterprise Linux 9, the/sbin/initscript is a link to thesystemdunit.The script is configured by using the kernel
init=command-line parameter.The
systemdunit from theinitramfsimage executes all units for theinitrd.targettarget. This unit includes mounting the root file system on disk to the/sysrootdirectory.Configured by using the
/etc/fstabfile.The kernel switches (pivots) the root file system from the
initramfsimage to the root file system in the/sysrootdirectory. Thesystemdunit then re-executes itself by using the installed copy of thesystemdunit on the disk.The
systemdunit looks for a default target, which is either passed in from the kernel command line or is configured on the system. Thesystemdunit then starts (and stops) units to comply with the configuration for that target, and solves dependencies between units automatically. Asystemdunit is a set of units that the system activates to reach the intended state. These targets typically start a text-based login or a graphical login screen.Configured by using the
/etc/systemd/system/default.targetfile and the/etc/systemd/system/directory.
To power off or reboot a running system from the command line, you can use the systemctl command.
The systemctl poweroff command stops all running services, unmounts all file systems (or remounts them read-only when they cannot be unmounted), and then powers down the system.
The systemctl reboot command 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
The systemctl halt and halt commands are also available to stop the system.
Unlike the poweroff command, these commands do not power off the system; they bring down a system to a point where it is safe to power it off manually.
A systemd target is a set of systemd units that the system must start to reach an intended state.
The following table lists the most important targets:
Table 11.4. Commonly Used Targets
| Target | Purpose |
|---|---|
graphical.target
| This target supports multiple users, and provides graphical- and text-based logins. |
multi-user.target
| This target supports multiple users, and provides text-based logins only. |
rescue.target
| This target provides a single-user system to enable repairing your system. |
emergency.target
| This target starts the most minimal system for repairing your system when the rescue.target unit fails to start. |
A target can be a part of another target.
For example, the graphical.target unit includes the multi-user.target unit, which in turn depends on the basic.target unit and others.
You can view these dependencies with the following command:
[user@host ~]$ systemctl list-dependencies graphical.target | grep target
graphical.target
* └─multi-user.target
* ├─basic.target
* │ ├─paths.target
* │ ├─slices.target
* │ ├─sockets.target
* │ ├─sysinit.target
* │ │ ├─cryptsetup.target
* | | ├─integritysetup.target
* │ │ ├─local-fs.target
...output omitted...To list the available targets, use the following command:
[user@host ~]$ systemctl list-units --type=target --all
UNIT LOAD ACTIVE SUB DESCRIPTION
---------------------------------------------------------------------------
basic.target loaded active active Basic System
...output omitted...
cloud-config.target loaded active active Cloud-config availability
cloud-init.target loaded active active Cloud-init target
cryptsetup-pre.target loaded inactive dead Local Encrypted Volumes (Pre)
cryptsetup.target loaded active active Local Encrypted Volumes
...output omitted...On a running system, administrators can switch to a different target by using the systemctl isolate command.
[root@host ~]# systemctl isolate multi-user.targetIsolating a target stops all services that the target does not require (and its dependencies), and starts any required services that are not yet started.
Not all targets can be isolated.
You can isolate only targets where AllowIsolate=yes is 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)
When the system starts, the systemd unit activates the default.target target.
Normally, the default target the /etc/systemd/system/ directory is a symbolic link to either the graphical.target or the multi-user.target targets.
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
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 affects only a single boot, and is a useful tool to troubleshoot the boot process.
To use this method to select 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 to start.
Press e to edit the current entry.
Move the cursor to the line that starts with
linuxwhich 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/9/html-single/configuring_basic_system_settings/index#managing-services-with-systemd