Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
22 views34 pages

RHEL7 Booting Process and Initialization

The document outlines the booting process of Red Hat Enterprise Linux 7, detailing the roles of BIOS, MBR, and GRUB2 in loading the operating system. It explains the configuration files associated with GRUB2, how to manage kernel entries, and the function of the initramfs during boot. Additionally, it introduces systemd as the new service manager in RHEL 7, highlighting its features and unit types.

Uploaded by

abhisheksafeeka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views34 pages

RHEL7 Booting Process and Initialization

The document outlines the booting process of Red Hat Enterprise Linux 7, detailing the roles of BIOS, MBR, and GRUB2 in loading the operating system. It explains the configuration files associated with GRUB2, how to manage kernel entries, and the function of the initramfs during boot. Additionally, it introduces systemd as the new service manager in RHEL 7, highlighting its features and unit types.

Uploaded by

abhisheksafeeka
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 34

Red Hat Enterprise Linux 7 Booting Process

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

 Searches, loads, and executes the boot loader program.

 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

 MBR stands for Master Boot Record.

 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:

o Primary boot loader info in 1st 446 bytes

o Partition table info in next 64 bytes

o MBR validation check in last 2 bytes.

 It contains information about GRUB2 (GRUB or LILO in old systems).

 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

The GRUB2 configuration is spread over several files:

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.

[root@rhel7 ~]# cat /etc/default/grub


GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="crashkernel=1281M rd.lvm.lv=centos/root
rd.lvm.lv=centos/swa p rhgb quiet"
GRUB_DISABLE_RECOVERY="true"

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

systems and in the /boot/efi/EFI/redhat directory on UEFI-based systems.

 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

this file are lost.

 If changes are made to any of these parameters, you need to run grub2-mkconfig to re-

generate the /boot/grub2/grub.cfg

[root@rhel7 ~]# grub2-mkconfig -o /boot/grub2/grub.cfg


Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-693.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-693.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-
4a8e1d32c856464e865a15b910c91393
Found initrd image: /boot/initramfs-0-rescue-
4a8e1d32c856464e865a15b910c91393.img
done
[root@rhel7 ~]#
On UEFI-based systems, the command will be grub2-mkconfig -o /boot/efi/EFI/centos/grub.cfg

 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

located in the /boot directory

 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

-rwxr-xr-x. 1 root root 8702 Aug 17 23:31 00_header

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

GRUB configuration file.

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

in the GRUB menu at startup to boot.

 To troubleshoot a broken grub2 configuration, an administrator will need to understand

the syntax of /boot/grub2/grub.cfg Actual bootable entries are encoded inside

menuentry blocks. In these blocks, linux16 and initrd16 lines point to the kernel to be

loaded from disk and the initramfs to be loaded.

 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

partition or gpt1 for the 1st GPT partition on that drive.

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

About Initramfs – /etc/dracut.conf

 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,

can then be accessed and mounted.

 The initramfs is bound to the kernel and the kernel mounts this initramfs as part of a two-

stage boot process.

 The Dracut utility creates initramfs whenever a new kernel is installed.

 Use the lsinitrd command to view the contents of the image created by dracut:

[root@rhel7 ~]# lsinitrd |less

 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:

[root@rhel7 ~]# grub2-editenv list


saved_entry=CentOS Linux (3.10.0-693.el7.x86_64) 7 (Core)

Note: This information is stored in the /boot/grub2/grubenv file.

To get the list of the kernels displayed at boot time, 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

from initrd.img to load system first process systemd in Linux 7.

 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

Note that equivalent parameters,1,s and single, can be passed to the


kernel as well

10
Press CTRL+x to boot the system with the parameter

Emergency Mode During Grub2 Boot

Emergency mode provides the most minimal environment possible and


allows you to repair your system even in situations when the system is
unable to enter rescue mode

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

Add the following parameters at the end of the linux line:


systemd.unit=emergency.target

11
Press CTRL+x to boot the system with the parameter

systemd

What is Systemd ?

 systemd is a replacement to the older traditional "System V init" system .


 systemd stands for system daemon.
 systemd is the new system and service manager in RHEL 7.
 It is backward compatible with SysV init scripts used by previous versions of Oracle .Systemd is
used in later versions of Linux (Fedora 15+, RHEL 7, OpenSUSE 12.1+, ...) which is compatible
with Unix SysV and Linux Standard Base (LSB) init scripts.

 systemd is the first process that starts after the system boots, and is the final process that is
systemd is the first daemon to start during booting and the last daemon to terminate
during shutdown
 The systemd daemon serves as the root of the user space's process tree; the first process
(pid 1)

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:

Boot scripts in /etc/systemd/system/ and /lib/systemd/system/

 Service control command:


o Fedora 15+: systemctl
o Ubuntu 12.04+, 14.04: initctl
 initctl list: List all system services and their current state.
 initctl stop service-name: Stop a specified service. See "list" above to list
names.
 Requires kernel support: (Kernel compile config options)
o CONFIG_DEVTMPFS=y
o CONFIG_CGROUPS=y
o CONFIG_AUTOFS4_FS=[y|m]
 The kernel command line in GRUB will include "init=/bin/systemd" Gnome desktop D-Bus
dependency on systemd
 Systemd supports parallelization (faster boot) Speeds up booting by loading services
concurrently, socket management, process tracking, mounting of file systems and
dependency-based service control.
 systemd manages the services with "cgroups .Daemon processes are categorized into
"cgroups" which have categorized resource limits.
 systemd supports snapshotting of your system and the restoring of your systems state, keeps
track of processes stored in what is known as a "cgroup" as opposed to the conventional "PID"
method.
 Mount points can be configured as systemd targets.
 Allows you to manage various types of units on a system :

The architecture of systemd

13
Systemd Unit Types

Unit Type File Extension Description

Service Unit .service Start and control daemons and process they consist of

Target Unit .target Replaces sysV init run levels

Automount Unit .automount A file system automount unit.

Device Unit .device Expose Kernel devices in systemd

Mount Unit .mount Control mount points in the file system

Path Unit .path A file or directory in a file system .

Scope Unit .scope An externally created process

Slice Unit .slice

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

Socket Unit .socket An Inter-process communication socket

Swap Unit .swap Encapsulates memory swap partition and swap files.

Timer Unit .timer A Systemd timer .

Systemd unit configuration files

Directory Description

/usr/lib/systemd/system/ systemd units distributed with installed RPM packages.

/run/systemd/system/ systemd units created at runtime. This directory takes


precedence over the directory with installed service units

/etc/systemd/system/ systemd units created and managed by the system


administrator. This directory takes precedence over the
directory with runtime units

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

The run level targets are defined as runlevel0.target, runlevel1.target, runlevel2.target,


runlevel3.target, ...
Ubuntu 12.04+: (Upstart: Mix of SysV init and systemd. Not all services have been migrated)

 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

most important of these targets are listed in the following table:

Runleve Target Units Description


l (Directory: /lib/systemd/system/)
0 runlevel0.target , poweroff.target shutdown/halt system

Single user mode, sulogin prompt, basic system


1 runlevel1.target, rescue.target
initialization completed

2 runlevel2.target Multiuser with no network services exported


3 runlevel3.target , multi-user.target Default text/console only start. Full multiuser
Reserved for local use. Also X-windows
4 runlevel4.target
(Slackware/BSD)
5 runlevel5.target, graphical.target Multiuser , GUI mode
6 runlevel6.target, reboot.target Shutdown and Reboot the system

 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

[root@rhel7 ~]# systemctl get-default


graphical.target
[root@rhel7 ~]#

 Note: that the default.target symbolic file points to graphical.target file.

[root@rhel7 ~]# ls -l /etc/systemd/system/default.target


lrwxrwxrwx. 1 root root 36 Sep 24 22:32 /etc/systemd/system/default.target ->
/lib/systemd/system/graphical.target

 graphical.target is equivalent of run level 5. This can be verified using runlevel command.

[root@rhel7 ~]# runlevel


N5

To View the new runlevels/targets by issuing the following command


:
ls -al /lib/systemd/system/runlevel*

[root@rhel7 ~]# ls -al /lib/systemd/system/runlevel*


lrwxrwxrwx. 1 root root 15 Sep 24 22:04 /lib/systemd/system/runlevel0.target -> poweroff.target
lrwxrwxrwx. 1 root root 13 Sep 24 22:04 /lib/systemd/system/runlevel1.target -> rescue.target
lrwxrwxrwx. 1 root root 17 Sep 24 22:04 /lib/systemd/system/runlevel2.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 Sep 24 22:04 /lib/systemd/system/runlevel3.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 Sep 24 22:04 /lib/systemd/system/runlevel4.target -> multi-user.target
lrwxrwxrwx. 1 root root 16 Sep 24 22:04 /lib/systemd/system/runlevel5.target -> graphical.target
lrwxrwxrwx. 1 root root 13 Sep 24 22:04 /lib/systemd/system/runlevel6.target -> reboot.target

To list the predefined systemd run level target units :

To List the predefined systemd Targets units , type below command in shell :find / -name
"runlevel*.target"

[root@rhel7 ~]# find / -name "runlevel*.target"


find: ‘/run/user/1000/gvfs’: Permission denied
/usr/lib/systemd/system/runlevel0.target
/usr/lib/systemd/system/runlevel1.target
/usr/lib/systemd/system/runlevel2.target
/usr/lib/systemd/system/runlevel3.target
/usr/lib/systemd/system/runlevel4.target
/usr/lib/systemd/system/runlevel5.target
/usr/lib/systemd/system/runlevel6.target

16
 Each runlevel[0123456].target file is a symbolic link to the system-start target equivalent.
For e.g.

[root@rhel7 ~]# ls -l /usr/lib/systemd/system/runlevel?.target


lrwxrwxrwx. 1 root root 15 Sep 24 22:04 /usr/lib/systemd/system/runlevel0.target -> poweroff.target
lrwxrwxrwx. 1 root root 13 Sep 24 22:04 /usr/lib/systemd/system/runlevel1.target -> rescue.target
lrwxrwxrwx. 1 root root 17 Sep 24 22:04 /usr/lib/systemd/system/runlevel2.target -> multi-
user.target
lrwxrwxrwx. 1 root root 17 Sep 24 22:04 /usr/lib/systemd/system/runlevel3.target -> multi-
user.target
lrwxrwxrwx. 1 root root 17 Sep 24 22:04 /usr/lib/systemd/system/runlevel4.target -> multi-
user.target
lrwxrwxrwx. 1 root root 16 Sep 24 22:04 /usr/lib/systemd/system/runlevel5.target -> graphical.target
lrwxrwxrwx. 1 root root 13 Sep 24 22:04 /usr/lib/systemd/system/runlevel6.target -> reboot.target
[root@rhel7 ~]#

Changing the Default Target :

To configure the system to use a different target unit by default


# systemctl set-default name.target

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

[root@rhel7 ~]# systemctl set-default multi-user.target


Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-
user.target.
[root@rhel7 ~]#

To set a default runlevel/target, run:

Example : To change the runlevel from "multi-user.target" to "graphical.target" (Runlevel 3 to


Runlevel 5).

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:

1. ln -sf /lib/systemd/system/runlevel5.target /etc/systemd/system/default.target

i. Here we are first deleting the existing "default.target" and


ii. then replacing with our link command.

Our new "target.default" will be that of "runlevel5.target". i.e graphical.target


[root@rhel7 ~]# ln -sf /lib/systemd/system/runlevel5.target /etc/systemd/system/default.target
[root@rhel7 ~]# systemctl get-default
graphical.target
[root@rhel7 ~]#

To View all available targets :

Commands :systemctl list-units --type=target --all

To view all targets installed on disk Run below command :

# systemctl list-unit-files --type=target --all

18
To Change to a different target unit in the current session, type the following at a shell
prompt as root:

#systemctl isolate name.target

To turn off the multi-user.target and change to graphical user interface unit in the current session, run
the following command as root:

#systemctl isolate multi-user.target

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

Isolating a target will stop services not required by that target and
start any required services that have not yet been started.

[root@rhel7 ~]# systemctl get-default


graphical.target

[root@rhel7 ~]# runlevel


5 3

Note: Not all targets can be isolated. Only targets that have AllowIsolate=yes set in their

unit files can be isolated.

19
[root@rhel7 ~]# cat /usr/lib/systemd/system/multi-user.target

# This file is part of systemd.


#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.

[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

 emergency.target : sulogin prompt,initramfs pivot complete and system root mounted on


/read-only

Old command Rhel6 New Command RHEL7 Description

halt Systemctl halt Halts the system

poweroff Systemctl poweroff Power off the system


Managing Services
reboot Systemctl reboot Restarts the system

pm-suspend Systemctl suspend Suspend the system

pm-hibernate Systemctl hibernate Hibernate the system

pm-suspend-hybrid Systemctl hybrid-sleep Hibernates and Suspends the system

Service Utility Vs systemctl

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.

Comparison of the service Utility with systemctl

Unit Type Systemctl Description

Service name start Systemctl start name.service Starts a service

Service name stop Systemctl stop name.service Stops a service

Systemctl restart name.service Restarts a service


Service name restart

Restarts a service only if it is


Service name condrestart running
Systemctl try-restart name.service

Systemctl reload name.service Reloads configuration


Service name reload

Service name status Systemctl status name.service Checks if a service is running


Systemctl is-active name.service

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 Utility Vs systemctl

Chkconfig Systemctl Description

Systemctl disable name.service Enables a service


Chkconfig name on

Systemctl status name.service Disables a service


Chkconfig name off

Systemctl status name.service


Chkconfig --list name
Systemctl is-enabled name.service Checks if a service is enabled

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

SPECIFYING SERVICE UNITS

For clarity, all command examples use full unit names with the .service file extension, for example:

~]# systemctl stop nfs-server.service

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:

~]# systemctl stop nfs-server

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 show nfs-server.service -p Names

# systemctl -t help

Gives all Possible unit

systemctl command to determine systemd version :

[root@rhel7 ~]# systemctl --version


systemd 219
+PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT
+GNUTLS +ACL +XZ -LZ4 -SECCOMP +BLKID +ELFUTILS +KMOD +IDN

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)

Displaying Service Status

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

Displaying Service Status

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:

# systemctl status gdm.service

24
To only verify that a particular service unit is running ,run the following command :
#systemctl is-active name. service

To determine whether a particular service unit is enabled, type:

systemctl is-enabled 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:

[root@rhel7 ~]# systemctl list-units --type=service | grep failed

All active services available on your system simply execute the above systemctl command without
the grep pipe:

Displaying Services Ordered to Start Before a Service

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

[root@rhel7 ~]# systemctl list-dependencies --after gdm.service


gdm.service
● ├─[email protected]
● ├─plymouth-quit.service
● ├─plymouth-start.service
● ├─rc-local.service
● ├─system.slice
● ├─systemd-journald.socket
● ├─systemd-user-sessions.service
● └─basic.target
● ├─rhel-import-state.service
● ├─systemd-ask-password-plymouth.path
● ├─paths.target
● │ ├─brandbot.path
● │ ├─cups.path
● │ ├─systemd-ask-password-console.path
● │ └─systemd-ask-password-wall.path
● ├─slices.target
● │ ├─-.slice
● │ ├─system.slice
● │ └─user.slice
● ├─sockets.target
● │ ├─avahi-daemon.socket
● │ ├─cups.socket
● │ ├─dbus.socket

Displaying Services Ordered to Start After a Service


To determine what services are ordered to start after the specified service, type the following at a shell
prompt:

[root@rhel7 ~]# systemctl list-dependencies --before 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:

[root@rhel7 ~]# systemd-analyze


Startup finished in 614ms (kernel) + 4.994s (initrd) + 1min 13.814s (userspace) = 1min 19.422s
[root@rhel7 ~]#

To get the time spent by each task during the boot process, type:

# systemd-analyze blame

[root@rhel7 ~]# systemd-analyze blame


38.167s plymouth-quit-wait.service
19.521s kdump.service
13.218s postfix.service
7.944s firewalld.service
7.348s accounts-daemon.service
6.366s systemd-udev-settle.service
6.168s tuned.service
5.506s abrt-ccpp.service
4.895s dev-mapper-centos\x2droot.device
……….
………..
4.712s gssproxy.service
4.599s libvirtd.service
4.318s polkit.service
4.247s lvm2-monitor.service
3.815s rsyslog.service

27
.

Start stop and Restart conditional Restart ,Reload, is-active

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:

[root@rhel7 ~]# systemctl start firewalld.service


[root@rhel7 ~]#

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:

~]# systemctl start httpd.service

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

To stop a firewalld service type:

[root@rhel7 ~]# systemctl stop firewalld.service


[root@rhel7 ~]#

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

[root@rhel7 ~]# systemctl restart firewalld.service


[root@rhel7 ~]#

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:

#systemctl try-restart name.service

systemctl try-restart name.service

[root@rhel7 ~]# systemctl try-restart firewalld.service


[root@rhel7 ~]#

Reload -Restarting a Service

Certain system services also allow you to reload their configuration without interupting their execution.
To do so type as root :
#systemctl reload name.service

[root@rhel7 ~]# systemctl reload firewalld.service


[root@rhel7 ~]#

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.

To do so, type the following at a shell prompt as root:

~]# systemctl reload httpd.service

Displaying Service Status

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

check the status of a network service (here httpd), type:

#systemctl status httpd

# systemctl status httpd


httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
Active: active (running) since Fri 2015-06-19 16:47:18 CEST; 6min ago
Main PID: 3868 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
CGroup: /system.slice/httpd.service
└─3868 /usr/sbin/httpd -DFOREGROUND
└─3869 /usr/sbin/httpd -DFOREGROUND
└─3870 /usr/sbin/httpd -DFOREGROUND
└─3871 /usr/sbin/httpd -DFOREGROUND
└─3872 /usr/sbin/httpd -DFOREGROUND
└─3873 /usr/sbin/httpd -DFOREGROUND

Jun 19 16:47:18 server1.example.com systemd[1]: Starting The Apache HTTP Ser....


Jun 19 16:47:18 server1.example.com systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.

To check if Service is Active


You will Get inactive if Service is not running .Firewalld service is stopped and not running

30
[root@rhel7 ~]# systemctl stop firewalld.service
[root@rhel7 ~]# systemctl is-active firewalld.service
inactive
[root@rhel7 ~]#

To check if a network service (here httpd) is running, type:

[root@rhel7 ~]# systemctl is-active httpd


unknown
[root@rhel7 ~]#

Note: If the service is running, you get active.

[root@rhel7 ~]# systemctl start firewalld.service


[root@rhel7 ~]# systemctl is-active firewalld.service
active
[root@rhel7 ~]#

enable, disable, is-enabled,is-disabled

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:

systemctl enable name.service

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.

To Configure firewalls service to automatically started at boot time, type following at a


shell prompt as root :
# systemctl enable firewalld.service

[root@rhel7 ~]# systemctl enable firewalld.service

Created symlink from /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service to


/usr/lib/systemd/system/firewalld.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/firewalld.service to
/usr/lib/systemd/system/firewalld.service.
[root@rhel7 ~]#

This command does not, however, rewrite links that already exist.

[root@rhel7 ~]# systemctl enable firewalld.service

31
To configure the Apache HTTP Server to start automatically at boot time, run the following
command as root:

~]# systemctl enable httpd.service

Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to


/usr/lib/systemd/system/httpd.service.

Reenable a Service

If you want to ensure that the symbolic links are re-created, use the following command as root:

systemctl reenable name.service

This command disables the selected service unit and immediately enables it again

[root@rhel7 ~]# systemctl reenable firewalld.service

Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.


Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

Created symlink from /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service to


/usr/lib/systemd/system/firewalld.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/firewalld.service to
/usr/lib/systemd/system/firewalld.service.
[root@rhel7 ~]#

To list all installed service units to determine if they are enabled, type :
#systemctl is-enabled name. service

To check if a firewalld service is enabled at boot time , type

[root@rhel7 ~]# systemctl is-enabled firewalld.service


enabled
[root@rhel7 ~]#

To check if a network service (here httpd) is enabled at boot, type:

# systemctl is-enabled httpd


disabled

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:

systemctl disable name.service

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

#systemctl disable httpd.service

To Stop network service firewalld service to start at boot time ,Type

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

[root@rhel7 ~]# systemctl disable firewalld.service


Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@rhel7 ~]#

Masking and Unmasking -

Masking will permanently disable a service


you can mask any service unit to prevent it from being started manually or by another 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

[root@rhel7 ~]# systemctl mask firewalld.service


Created symlink from /etc/systemd/system/firewalld.service to /dev/null.
[root@rhel7 ~]#
[root@rhel7 ~]# systemctl start firewalld.service
Failed to start firewalld.service: Unit is masked.

33
[root@rhel7 ~]#

Unmask
To enable the Service again Use unmask .
# Systemctl unmask firewalld.service

[root@rhel7 ~]# systemctl unmask firewalld.service


Removed symlink /etc/systemd/system/firewalld.service.
[root@rhel7 ~]#
[root@rhel7 ~]# systemctl restart firewalld.service
[root@rhel7 ~]#

34

You might also like