Bookmark this page

Select the Boot Target

Objectives

  • Describe the Red Hat Enterprise Linux boot process, set the default target when booting, and boot a system to a non-default target.

Describe the Red Hat Enterprise Linux 9 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 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-install command installs GRUB2 as the boot loader on the disk for BIOS systems. Do not use the grub2-install command directly to install the UEFI boot loader. RHEL 9 provides a prebuilt /boot/efi/EFI/redhat/grubx64.efi file, which contains the required authentication signatures for a Secure Boot system. Executing grub2-install directly on a UEFI system generates a new grubx64.efi file without those required signatures. You can restore the correct grubx64.efi file from the grub2-efi package.

  • GRUB2 loads its configuration from the /boot/grub2/grub.cfg file for BIOS, and from the /boot/efi/EFI/redhat/grub.cfg file 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/grub file. The grub2-mkconfig command generates the /boot/grub2/grub.cfg or /boot/efi/EFI/redhat/grub.cfg files 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 initramfs image is an archive with the kernel modules for all the required hardware at boot, initialization scripts, and more. In Red Hat Enterprise Linux 9, the initramfs image contains a bootable root file system with a running kernel and a systemd unit.

    The initramfs image is configured by using the /etc/dracut.conf.d/ directory, the dracut command, and the lsinitrd command to inspect the initramfs file.

  • 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 initramfs image in memory.

    The boot loader is configured by using the /etc/grub.d/ directory, the /etc/default/grub file, and the grub2-mkconfig command to generate the /boot/grub2/grub.cfg file.

  • The kernel initializes all hardware for which it can find a driver in the initramfs image, and then executes the /sbin/init script from the initramfs image as PID 1. On Red Hat Enterprise Linux 9, the /sbin/init script is a link to the systemd unit.

    The script is configured by using the kernel init= command-line parameter.

  • The systemd unit from the initramfs image executes all units for the initrd.target target. This unit includes mounting the root file system on disk to the /sysroot directory.

    Configured by using the /etc/fstab file.

  • The kernel switches (pivots) the root file system from the initramfs image to the root file system in the /sysroot directory. The systemd unit then re-executes itself by using the installed copy of the systemd unit on the disk.

  • The systemd unit looks for a default target, which is either passed in from the kernel command line or is configured on the system. The systemd unit then starts (and stops) units to comply with the configuration for that target, and solves dependencies between units automatically. A systemd target 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.target file and the /etc/systemd/system/ directory.

Figure 11.1: Boot process for BIOS-based and UEFI-based systems

Power Off and Reboot

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.

Select a Systemd Target

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

TargetPurpose
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...

Select a Target at Runtime

On a running system, administrators can switch to a different target by using the systemctl isolate command.

[root@host ~]# systemctl isolate multi-user.target

Isolating 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.service
AllowIsolate=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)

Set a Default Target

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-default
multi-user.target
[root@host ~]# systemctl set-default graphical.target
Removed /etc/systemd/system/default.target.
Created symlink /etc/systemd/system/default.target -> /usr/lib/systemd/system/graphical.target.
[root@host ~]# systemctl get-default
graphical.target

Select a Different Target at Boot Time

To select a different target at boot time, append the systemd.unit=target.target option to the kernel command line from the boot loader.

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:

  1. Boot or reboot the system.

  2. Interrupt the boot loader menu countdown by pressing any key (except Enter, which would initiate a normal boot).

  3. Move the cursor to the kernel entry to start.

  4. Press e to edit the current entry.

  5. Move the cursor to the line that starts with linux which is the kernel command line.

  6. Append systemd.unit=target.target, for example, systemd.unit=emergency.target.

  7. 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

Revision: rh199-9.3-8dd73db