Professional Documents
Culture Documents
SERVICES AND
THE BOOT PROCESS
• GOAL
• Control and monitor network services, system daemons and the boot process using systemd.
• OBJECTIVES
• List system daemons and network services started by the systemd service and socket units.
• Control system daemons and network services, using systemctl.
• Describe the Red Hat Enterprise Linux boot process, set the default target used when
booting, and boot a system to a non-default target.
• Log into a system and change the root password when the current root password has been
lost.
• Manually repair file system configuration or corruption issues that stop the boot process.
• SECTIONS
• Identifying Automatically Started System Processes (and Guided Exercise)
• Controlling System Services (and Guided Exercise)
• Selecting the Boot Target (and Guided Exercise)
• Resetting the Root Password (and Guided Exercise)
• Repairing File System Issues at Boot (and Guided Exercise)
• LAB
• Controlling Services and the Boot Process
IDENTIFYING AUTOMATICALLY
STARTED SYSTEM PROCESSES
• The systemd daemon manages startup for Linux, including service startup and
service management in general. It activates system resources, server daemons,
and other processes both at boot time and on a running system.
• Daemons are processes that either wait or run in the background, performing
various tasks.
• Generally, daemons start automatically at boot time and continue to run until
shutdown or until they are manually stopped. It is a convention for names of
many daemon programs to end in the letter d.
• A service in the systemd sense often refers to one or more daemons, but starting
or stopping a service may instead make a one-time change to the state of the
system, which does not involve leaving a daemon process running afterward
(called oneshot).
systemd
• In Red Hat Enterprise Linux, the first process that starts (PID 1) is
systemd. A few of the features provided by systemd include:
• Parallelization capabilities (starting multiple services simultaneously),
which increase the boot speed of a system.
• On-demand starting of daemons without requiring a separate service.
• Automatic service dependency management, which can prevent long
timeouts. For example, a network-dependent service will not attempt
to start up until the network is available.
• A method of tracking related processes together by using Linux
control groups.
Systemd units
• systemd uses units to manage different types of objects. Some common unit types
are listed below:
• Service units have a .service extension and represent system services. This type of
unit is
• used to start frequently accessed daemons, such as a web server.
• Socket units have a .socket extension and represent inter-process communication
(IPC) sockets that systemd should monitor. If a client connects to the socket, systemd
will start a daemon and pass the connection to it. Socket units are used to delay the
start of a service at boot time and to start less frequently used services on demand.
• Path units have a .path extension and are used to delay the activation of a service
until a specific file system change occurs. This is commonly used for services which
use spool directories such as a printing system.
LISTING SERVICE UNITS
• use the systemctl command to explore the current state of the
system. For example, the following command lists all currently loaded
service units
Columns in the systemctl list-units
Command Output
• UNIT
• The service unit name.
• LOAD
• Whether systemd properly parsed the unit's configuration and loaded the unit into memory.
• ACTIVE
• The high-level activation state of the unit. This information indicates whether the unit has started
successfully or not.
• SUB
• The low-level activation state of the unit. This information indicates more detailed
informationabout the unit. The information varies based on unit type, state, and how the unit is
executed.
• DESCRIPTION
• The short description of the unit
• By default, the systemctl list-units --type=service command lists only
the service units with active activation states. The --all option lists all
service units regardless of the activation states. Use the --state=
option to filter by the values in the LOAD, ACTIVE, or SUB fields.
• The systemctl list-units command displays units that the systemd
service attempts to parse and load into memory; it does not display
installed, but not enabled, services. To see the state of all unit files
installed, use the systemctl list-unit-files command. For example:
VIEWING SERVICE STATES
• View the status of a specific unit with systemctl status name.type. If
the unit type is not provided, systemctl will show the status of a
service unit, if one exists.
Service Unit Information FIELD
• The meaning of the fields are:
Service States in the Output of systemctl
VERIFYING THE STATUS OF A
SERVICE
• use the following command to verify that the a service unit is
currently active (running):
• To stop a currently running service, use the stop argument with the
systemctl command. The example below shows how to stop the
sshd.service service:
• restart of a running service, the service is stopped and then started.
On the restart of service, the process ID changes and a new process ID
gets associated during the startup
• To verify whether the service is enabled or disable, use the systemctl is-
enabled command.
• To disable the service from starting automatically,
SUMMARY OF systemctl COMMANDS
exercise
SELECTING THE BOOT TARGET
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 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.
Powerdeon
System The system firmware searches for a bootable device, either by searching for
firmware a Master Boot Record (MBR) on all disks, or
(BIOS/UEIF) configured in the UEFI boot firmware in the order configured in the BIOS.
The boot loader hands control over to the kernel, passing in any options specified on
Bootloader the kernel command line in the boot loader, and the location of the initramfs in memory.
(GRUB2)
Target
• 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).
• 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 initramfs in
memory
• The kernel initializes all hardware for which it can find a driver in the initramfs, then
executes /sbin/init from the initramfs as PID 1. On Red Hat Enterprise Linux 8,
/sbin/init is a link to systemd.
• Configured using the kernel init= command-line parameter.
• The systemd instance from the initramfs executes all units for the initrd.target target.
This includes mounting the root file system on disk on to the /sysroot directory.
• Configured using /etc/fstab
• The kernel switches (pivots) the root file system from initramfs to the root
file system in /sysroot. systemd then re-executes itself using the copy of
systemd installed on the disk.
• systemd looks 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, a systemd target is a set of units
• that the system should activate to reach the desired state. These targets
typically start a textbased login or a graphical login screen.
• Configured using /etc/systemd/system/default.target and /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.
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.
• To list the available targets, use the following command.
• Switch into a chroot jail, where /sysroot is treated as the root of the
file-system tree.
• Make sure that all unlabeled files, including /etc/shadow at this point,
get relabeled during boot.
• Type exit twice. The first command exits the chroot jail, and the
INSPECTING LOGS
• Looking at the logs of previously failed boots can be useful. If the
system journals are persistent across reboots, you can use the
journalctl tool to inspect those logs.
• by default, the system journals are kept in the /run/log/journal
directory, which means the journals are cleared when the system
reboots. To store journals in the / var/log/journal directory, which
persists across reboots, set the Storage parameter to persistent in
/etc/systemd/journald.conf.
Inspect the logs of a previous boot
• use the -b option of journalctl. Without any arguments, the -b option
only displays messages since the last boot. With a negative number as
an argument, it displays the logs of previous boots.
Using the Emergency and Rescue Targets
• By appending either systemd.unit=rescue.target or
systemd.unit=emergency.target to the kernel command line from the
boot loader, the system spawns into a rescue or emergency shell
instead of starting normally.
• Both of these shells require the root password.
• Administrators can use these shells to fix any issues that prevent the
system from booting normally; for example, a dependency loop
between services, or an incorrect entry in /etc/fstab.
• Exiting from these shells continues with the regular boot process.
exercise
DIAGNOSING AND FIXING FILE
SYSTEM ISSUES
• Errors in /etc/fstab and corrupt file systems can stop a system from
booting. In most cases, systemd drops to an emergency repair shell
that requires the root password.
• The following table lists some common errors and their results.
exercise