RHEL7 Booting Process and Initialization
RHEL7 Booting Process and Initialization
RHEL goes through the boot process when the system is powered up or reset, with the boot process
lasting until all enabled services are started and a login prompt appears on the screen.
BIOS
The BIOS (Basic Input/output System), performs the POST (power on self test) to detect,
test and initialize system hardware components. Performs some system integrity checks
It looks for boot loader in floppy, CD-ROMs, or hard drive. You can press a key (typically F12
of F2, but it depends on your system) during the BIOS startup to change the boot
sequence.
Once the boot loader program is detected and loaded into the memory, BIOS gives the
control to it.
1
So, in simple terms BIOS loads and executes the MBR boot loader.
MBR
It is located in the 1st sector of the bootable disk. Typically /dev/hda, or /dev/sda
MBR is less than 512 bytes in size. This has three components as shown:
So, in simple terms MBR loads and executes the GRUB2 boot loader.
GRUB2
The default bootloader program used on RHEL 7 is GRUB 2. GRUB stands for Grand Unified
Bootloader. GRUB 2 replaces the older GRUB bootloader also called as legacy GRUB.
2
GRUB2 provides the following new features:
o ability to boot on various file systems (xfs, ext4, ntfs, hfs+, raid, etc),
o gzip files decompression on the fly,
o management of all disk geometries,
o support for GPT (GUID Partition Tables) and MBR (Master Boot Record),
o portability with different architectures (BIOS, EFI, Coreboot, etc),
o ability to load modules at execution time
a. /boot/grub2/grub.cfg: this file contains the final GRUB2 configuration (do not edit it
directly!),
b. /etc/grub2.cfg: this is a symbolic link to the /boot/grub2/grub.cfg file,
c. /etc/default/grub: this file contains the list of the GRUB2 variables (the values of
the environment variables can be edited),
d. /etc/sysconfig/grub: this is a symbolic link to the /etc/default/grub file,
e. /etc/grub.d: this directory contains all the individual files internally used by GRUB2.
The /etc/default/grub configuration file defines directives that govern how GRUB behaves at
boot time.
3
Values defined in this file are used to regenerate the /boot/grub2/grub.cfg file, which
controls the behavior of GRUB at boot time. This is the main configuration file that controls the
behavior of GRUB at boot time. This file is located in the /boot/grub2 directory on BIOS-based
This file can be regenerated manually with the grub2-mkconfig utility, or it is automatically
regenerated when a new kernel is installed. During this process, any manual changes made to
If changes are made to any of these parameters, you need to run grub2-mkconfig to re-
When this utility runs, it uses the settings defined in the /etc/default/grub file and in the
helper scripts located in the /etc/grub.d/ directory to regenerate this file for kernels
Here is the list of default helper scripts located in the /etc/grub.d/ directory:
4
[root@rhel7 ~]# ls -lrt /etc/grub.d/
total 72
-rwxr-xr-x. 1 root root 1043 Apr 11 19:35 00_tuned
-rw-r--r--. 1 root root 483 Aug 17 23:31 README
-rwxr-xr-x. 1 root root 216 Aug 17 23:31 41_custom
-rwxr-xr-x. 1 root root 214 Aug 17 23:31 40_custom
-rwxr-xr-x. 1 root root 11169 Aug 17 23:31 30_os-prober
-rwxr-xr-x. 1 root root 2559 Aug 17 23:31 20_ppc_terminfo
-rwxr-xr-x. 1 root root 10275 Aug 17 23:31 20_linux_xen
-rwxr-xr-x. 1 root root 10781 Aug 17 23:31 10_linux
-rwxr-xr-x. 1 root root 232 Aug 17 23:31 01_users
The first script, 00_header, sets the GRUB environment; the 10_linux script searches for all installed
kernels on the same disk partition; the 30_os-prober searches for the presence of other operating
systems; and the 40_custom and 41_custom scripts are for us to add any customization to the new
The grub.cfg file contains menuentry blocks for each installed kernel. Each block begins with
a title and includes the names of the kernel and RAM disk image files, their location with respect
to /boot, and several options and modules to be loaded. These menu entry titles are displayed at the
time of system boot and you can choose one of them to boot.
5
if a new kernel is added to the system, existing kernel entries will remain in this file and can be chosen
menuentry blocks. In these blocks, linux16 and initrd16 lines point to the kernel to be
The set root lines inside those blocks do not point to the root file system for the RHEL 7
system, but instead point to the file system from which grub2 should load the kernel and
initramfs files. The syntax is (harddrive, partition) where hd0 is the first hard drive in the
system, hd1 is the second etc… the partitions are indicated as msdos1 for the 1stMBR
GRUB2 searches the compressed kernel image file also called as vmlinuz in the /boot
6
GRUB2 loads the vmlinuz kernel image file into memory and extracts the contents of
the initramfs image file into a temporary, memory-based file system (tmpfs).
The initial RAM disk (Initrd) is an initial root file system that is mounted before the real root
file system.
The job of the initial RAM file system is to preload the block device modules, such as for
IDE, SCSI, or RAID, so that the root file system, on which those modules normally reside,
The initramfs is bound to the kernel and the kernel mounts this initramfs as part of a two-
Use the lsinitrd command to view the contents of the image created by dracut:
So, in simple terms GRUB2 just loads and executes Kernel and initramfs images.
7
Basic Management
To get the details about the current active kernel, type:
To permanently define the kernel to execute at boot time (here 0 for the first
entry), type:
# grub2-set-default 0
To list all the menu entries that will be displayed at system boot, issue the
following command:
8
[root@host ~]# awk -F\' '$1=="menuentry " {print i++ " : " $2}'
/etc/grub2.cfg
0 : CentOS Linux 7 (Core), with Linux 3.10.0-229.14.1.el7.x86_64
1 : CentOS Linux 7 (Core), with Linux 3.10.0-229.4.2.el7.x86_64
2 : CentOS Linux 7 (Core), with Linux 3.10.0-229.el7.x86_64
3 : CentOS Linux 7 (Core), with Linux 0-rescue-
605f01abef434fb98dd1309e774b72ba
Kernel
Linux Kernel is the central core of the OS and it is the first program loaded on the system
starts up. While system starting kernel loads all the necessary Kernel Modules and Drives
The kernel starts the systemd process with a process ID of 1 (PID 1) as shown below:
To enter rescue mode and Emergency Mode during boot, on the GRUB2 boot
screen
Rescue Mode During Grub2 Boot
To enter rescue mode during boot, on the GRUB2 boot screen, press the
'e' key for edit
9
Add the following parameters at the end of the linux line:
systemd.unit=rescue.target
Press CTRL -x and CTRL+e to jump to the start and end of the line
respectively
10
Press CTRL+x to boot the system with the parameter
In emergency mode, the system mounts the root file system only for
reading ,does not attempt to mount any other local file systems, does
not activate network interfaces and only starts few essential services
To enter rescue mode during boot, on the GRUB2 boot screen, press the
'e' key for edit
Steps followed in the above method are similar except the below change
systemd.unit=emergency.target
Press CTRL -x and CTRL+e to jump to the start and end of the line
respectively
11
Press CTRL+x to boot the system with the parameter
systemd
What is Systemd ?
12
systemd was designed to allow for better handling of dependencies and have the ability to
handle more work in parallel at system startup.
Systemd is becoming the default init system for Linux and has brought the following changes:
13
Systemd Unit Types
Service Unit .service Start and control daemons and process they consist of
Snapshot Unit .snapshot Used to temporarily save the state of the set of systemd
units, which can be later restored by activating the saved
snapshot point
Swap Unit .swap Encapsulates memory swap partition and swap files.
Directory Description
14
Systemd run levels/Targets:
The default boot level is set by /etc/systemd/system/default.target which is a symbolic link to the file
defining the appropriate run level target.
Set run level 3 (multi-user with networking and console only login):
rm /etc/systemd/system/default.target
ln -sf /lib/systemd/system/runlevel3.target /etc/systemd/system/default.target
Set run level 5 (graphic mode):
rm /etc/systemd/system/default.target
ln -sf /lib/systemd/system/runlevel5.target /etc/systemd/system/default.target
Runlevel "3" will boot to text or console mode and "5" will boot to the graphical login mode.
A systemd target is a set of systemd units that should be started to reach a desired state. The
Note that the user friendly name is just a symbolic link to the runlevel name:
# ls -l /lib/systemd/system/runlevel3.target
lrwxrwxrwx. 1 root root 17 May 24 10:55 /lib/systemd/system/runlevel3.target -> multi-
user.target
Controlling Runlevels/Targets :
15
To display the default Runlevels/target unit, type run the following command in shell:
#systemctl get-default
graphical.target is equivalent of run level 5. This can be verified using runlevel command.
To List the predefined systemd Targets units , type below command in shell :find / -name
"runlevel*.target"
16
Each runlevel[0123456].target file is a symbolic link to the system-start target equivalent.
For e.g.
To configure the system to use the multi-user.target unit by default, run the following command as
root :
#systemctl set-default multi-user.target
Commands:
17
rm /etc/systemd/system/default.target
ln -s /lib/systemd/system/runlevel3.target /etc/systemd/system/default.target
Alternatively ,link command with the "-f" parameter indicating that the destination file is to be
removed:
18
To Change to a different target unit in the current session, type the following at a shell
prompt as root:
To turn off the multi-user.target and change to graphical user interface unit in the current session, run
the following command as root:
Isolating a target will stop services not required by that target and
start any required services that have not yet been started.
Note: Not all targets can be isolated. Only targets that have AllowIsolate=yes set in their
19
[root@rhel7 ~]# cat /usr/lib/systemd/system/multi-user.target
[Unit]
Description=Multi-User System
Documentation=man:systemd.special(7)
Requires=basic.target
Conflicts=rescue.service rescue.target
After=basic.target rescue.service rescue.target
AllowIsolate=yes
[root@rhel7 ~]#
To enter rescue mode in the current session, run the following command as root:
#systemctl rescue
To change the current target and enter emergency mode, type the following at a shell
prompt as root:
#systemctl emergency
Previous versions of Red Hat Enterprise Linux, which were distributed with SysV init or Upstart,
used init scripts located in the /etc/rc.d/init.d/ directory
20
These inits scripts where typically used by system Administrators to control states of services and
Daemons in their system.
In Red Hat Enterprise Linux 7,these init scripts have been replaced with service units.
Service-status-all Systemctl list-units --type service --all Displays the status of all services
Service units end with the ".service" file extension and serve a similar purpose as init scripts.
To view,start,stop,restart,enable,disbale system services ,use the systemctl command .
Chkconfig --list Systemctl list-unit-files --type.service List all services and checks if they
are enabled
systemctl list-dependencies --after Lists services that are ordered to
21
start before the specified unit.
systemctl list-dependencies --before
Lists services that are ordered to
start after the specified uni
For clarity, all command examples use full unit names with the .service file extension, for example:
However, the file extension can be omitted, in which case the systemctl utility assumes the argument
is a service unit. The following command is equivalent to the one above:
Additionally, some units have alias names. Those names can have shorter names than units, which can
be used instead of the actual unit names. To find all aliases that can be used for a particular unit, use:
# systemctl -t help
22
Listing Services
To list all currently loaded service units, run the following commands:
#systemctl list-units --type service
For each service unit file, this command displays its full name (UNIT) followed by a note whether the
unit file has been loaded (LOAD), its high-level (ACTIVE) and low-level (SUB) unit file activation state,
and a short description (DESCRIPTION).
To list all installed service units, ,to determine if they are enabled type :
#systemctl list-unit-files --type service
23
For each service unit, this command displays its full name (UNIT FILE) followed by information whether
the service unit is enabled or not (STATE)
To display detailed information about a service unit that corresponds to a system service, type
the following at a shell prompt:
#systemctl status name. service
The service unit for the GNOME Display Manager is named gdm.service. To determine the current
status of this service unit, type the following at a shell prompt:
24
To only verify that a particular service unit is running ,run the following command :
#systemctl is-active name. service
Note that both systemctl is-active and systemctl is-enabled return an exit status of 0 if the specified
service unit is running or enabled.
Systemctl command to list all currently running services on our RedHat Linux server system:
25
systemctl list all services which failed to load during the system's boot time:
All active services available on your system simply execute the above systemctl command without
the grep pipe:
To determine what services are ordered to start before the specified service, type the
following at a shell prompt:
# systemctl list-dependencies --after gdm.service
26
systemd-analyze Boot Process Performance
Systemd primary task is to manage the boot process and provides information about it
systemd-analyze may be used to determine system boot-up performance statistics and retrieve
other state and tracing information from the system and service manager
.
To get the boot process duration, type:
To get the time spent by each task during the boot process, type:
# systemd-analyze blame
27
.
Starting a Service
To start a service unit that corresponds to a system service, type the following at a shell prompt as
root
#systemctl start name. service
The service unit for the Firewall Server is named firewalld.service. To activate this service unit and
start the firewalld daemon in the current session, run the following command as root:
The service unit for the Apache HTTP Server is named httpd.service. To activate this service unit and
start the httpd daemon in the current session, run the following command as root:
Stopping a Service
To stop a service unit that corresponds to a system service, type the following at a shell prompt as root
#systemctl stop name.service
Restarting Service
To restart a service unit that corresponds to a system service, type the following at a shell prompt as
root
#systemctl restart name. service
This command stops the selected service unit in the current session and immediately starts it again.
Importantly, if the selected service unit is not running, this command starts it too
28
try-restart Service
To tell systemd to restart a service unit only if the corresponding service is already running, run the
following command as root:
Certain system services also allow you to reload their configuration without interupting their execution.
To do so type as root :
#systemctl reload name.service
In order to prevent users from encountering unnecessary error messages or partially rendered web
pages, the Apache HTTP Server allows you to edit and reload its configuration without the need to
restart it and interrupt actively processed requests.
29
[root@rhel7 ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset:
enabled)
Active: active (running) since Tue 2017-09-26 18:35:38 IST; 2min 58s ago
Docs: man:firewalld(1)
Process: 3921 ExecReload=/bin/kill -HUP $MAINPID (code=exited, status=0/SUCCESS)
Main PID: 3769 (firewalld)
CGroup: /system.slice/firewalld.service
└─3769 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
To determine the current status of this service unit, type the following at a shell promTo
30
[root@rhel7 ~]# systemctl stop firewalld.service
[root@rhel7 ~]# systemctl is-active firewalld.service
inactive
[root@rhel7 ~]#
Enable a service
To configure a service unit that corresponds to a system service to be automatically started at boot
time, type the following at a shell prompt as root:
This command reads the [Install] section of the selected service unit and creates appropriate symbolic
links to the /usr/lib/systemd/system/name.service file in the /etc/systemd/system/ directory and its
subdirectories.
This command does not, however, rewrite links that already exist.
31
To configure the Apache HTTP Server to start automatically at boot time, run the following
command as root:
Reenable a Service
If you want to ensure that the symbolic links are re-created, use the following command as root:
This command disables the selected service unit and immediately enables it again
To list all installed service units to determine if they are enabled, type :
#systemctl is-enabled name. service
32
Note: If the service is enabled at boot, you get enabled.
Disable a Service
To prevent a service unit that corresponds to a system service from being automatically started at
boot time, type the following at a shell prompt as root:
Replace name with the name of the service unit you want to disable (for example, bluetooth). This
command reads the [Install] section of the selected service unit and removes appropriate symbolic
links to the /usr/lib/systemd/system/name.service file from the /etc/systemd/system/ directory and its
subdirectories
To prevent firewalld service unit that corresponds to a system service from being automatically
started at boot time ,type below command in shell prompt as root:
# systemctl disable firewalld.service
This command replaces the /etc/systemd/system/name.service file with a symbolic link to /dev/null,
rendering the actual unit file inaccessible to systemd
To permanently disable a service (here firewalld) to prevent it from being started manually
or by another service, type:
# systemctl mask firewalld.service
33
[root@rhel7 ~]#
Unmask
To enable the Service again Use unmask .
# Systemctl unmask firewalld.service
34