0% found this document useful (0 votes)
27 views41 pages

Laboratory Work 5

Uploaded by

tynysbekn
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)
27 views41 pages

Laboratory Work 5

Uploaded by

tynysbekn
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/ 41

Lab 5 Hardware Configuration

Introduction
In order to provide the functionality you need to apply these concepts, this VM may require a minute or
two to load.
There are a variety of files and commands that will provide useful information regarding the hardware
that is attached to the system. This information can be used to configure or fine-tune how the hardware
behaves on the system. The information is also very useful when troubleshooting hardware device
issues.

15.1 Step 1
Please use the Ubuntu image to complete the following steps. Select the Ubuntu PC by clicking on the
tab in the window on the right side of the screen.
Log in to the system using the root account. When prompted, provide the root password:

root
netlab123
Ubuntu 18.04.2 LTS ubuntu tty1
ubuntu login: root
Password:

Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0-45-generic x86_64)


* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by


applicable law.

root@ubuntu:~#

15.2 Step 2
View information regarding your CPU by executing the following command:
lscpu
root@ubuntu:~# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 1
On-line CPU(s) list: 0
Thread(s) per core: 1
Core(s) per socket: 1
Socket(s): 1
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 44
Model name: Intel (R) Xeon(R) CPU. E5620 @ 2.40GHz
Stepping: 2
CPU MHz: 2393.988
BogoMIPS: 4787.97
Virtualization: VT-x
Hypervisor vendor: KVM
Virtualization type: full
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 12288K
NUMA node0 CPU(s): 0
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat
pse36 clflush pclmulqdq vmx ssse3 cx16 paid sse4_1 sse4_2 x2apic popcnt
tsc_deadline_timer aes hypervisor lahf_lm cpuid_fault pti tpr_shadow vnmi
flexpriority ept vpid tsc_adjust arat

Critical settings may include the number of CPUs and the CPU clock speed, both highlighted in the
graphic.

15.3 Step 3
For a more detailed look at your CPU's features, execute the following command:

cat /proc/cpuinfo
root@ubuntu:~# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 44
model name : Intel(R) Xeon(R) E5620 @2.40GHz
stepping : 2
microcode : 0x1
cpu MHz : 2393.992
cache size : 12288 KB
physical id : 0
siblings : 1
core id : 0
cpu cores : 1
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 11
wp : yes
flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca
cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1g rdtscp lm
constant_tsc arch_perfmon rep_good nopl eagerfpu pni pclmulqdq ssse3 cx16 pcid
sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes hpervisor lahf_lm tsc_adjust
arat

bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf


bogomips : 4787.98
clflush size : 64
cache_alignment : 64
address sizes : 40 bits physical, 48 bits virtual
power management:

Note the highlighted flags: field in the output above. One of the key settings of
the /proc/cpuinfo file is the flags that the CPU supports, which are a feature of the CPU. Some
advanced CPU functions require specific flags.

15.4 Step 4
The free command gives details on total, used, and free memory the system has access to, including
swap space on fixed disks that can be used as temporary storage for memory operations. Your output
may differ, depending on system loads.
To display information about memory usage, execute the following command:
free
root@ubuntu:~# free
total used free shared buff/cache
available
Mem: 498828 50920 344884 4532 103024
420876
Swap: 5517308 0 5517308

15.5 Step 5
The /proc/meminfo file provides a very detailed breakdown of how much memory a system has and
how it is being used. For a more detailed look at memory usage, execute the following command:

cat /proc/meminfo | less


root@ubuntu:~# cat /proc/meminfo | less
MemTotal: 492952 kB
MemFree: 298216 kB
MemAvailable: 436160 kB
Buffers: 10544 kB
Cached: 124068 kB
SwapCached: 0 kB
Active: 117304 kB
Inactive: 39200 kB
Active(anon): 22268 kB
Inactive(anon): 216 kB
Active(file): 95036 kB
Inactive(file): 38984 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 524284 kB
SwapFree: 524284 kB
Dirty: 0 kB
WriteBack: 0 kB
AnonPages: 21712 kB
Mapped: 27868 kB
Shmem: 576 kB
Slab: 26388 kB
SReclaimable: 11952 kB
SUnreclaim: 9316 kB

KernelStack: 1376 kB

PageTables: 3568 kB

NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 5766720 kB
Committed_AS: 236336 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 4708 kB

VmallocChunk: 34359731508 kB

HardwareCorrupted: 0 kB
AnonHugePages: 0 kB
:

Type Q to exit the less command:

15.6 Step 6
Execute the following command to display the USB devices that are attached to the system:

lsusb
root@ubuntu:~# lsusb

Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

Bus 001 Device 002: ID 0627:0001 Adomax Technology Co., Ltd

Bus 001 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub

Since the only devices listed in the output above are the root hub, and Adomax Technology
Co.,Ltd, we can determine that there are no real USB devices attached to the system. The root
hub is the USB port itself.

15.7 Step 7
Please use the CentOS image to complete the following steps. Select the CentOS PC by clicking on the
tab in the window on the right side of the screen.
Log in to the system using the root account. When prompted, provide the root password:

root
netlab123
CentOS Linux 7 (Core)
Kernel 3.10.0-957.el7.x86_64 on an x_86_64

centos login:
Password:
[root@localhost ~]#

Display the hardware devices by executing the following command:

lspci
[root@centos ~]# lspci
00:00.0 Host bridge: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev 02)

00:01.0 ISA bridge: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton II]
00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton II]
00:01.2 USB controller: Intel Corporation 82371SB PIIX3 USB [Natoma/Triton II]
(rev 01)
00:01.3 Bridge: Intel Corporation 82371AB/EB/MB PIIX4 (rev 03)
08:02.0 VGA compatible controller: Device 1234:1111 (rev 02)
00:03.0 Ethernet controller: Intel Corporation 82540EM Gigabit Ethernet
Controller (rev 03)
00:1a.0 USB controller: Intel Corporation 82371SB PIIX3 [Natoma/Triton II] (rev
01)

Some of the devices displayed in the output above include:

 IDE Interface - A device that permits you to attach IDE hard drives to the system.

00:01.1 IDE interface: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton


II]

 VGA compatible controller - A device that permits you to attach a monitor to the system.

08:02.0 VGA compatible controller: Device 1234:1111 (rev 02

 Ethernet controller - A device that allows you to connect to the network.


00:03.0 Ethernet controller: Intel Corporation 82540EM Gigabit Ethernet
Controller (rev 03)

15.8 Step 8
Display devices along with their device code by executing the lspci command with the -nn option:

lspci -nn
[root@cenos ~]# lspci -nn
00:00.0 Host bridge [0600]: Intel Corporation 440FX - 82441FX PMC [Natoma] (rev
02)[8086:1237]
00:01.0 ISA bridge [0601]: Intel Corporation 82371SB PIIX3 ISA [Natoma/Triton
II] [8086:7000]
00:01.1 IDE interface [0101]: Intel Corporation 82371SB PIIX3 IDE [Natoma/Triton
II] [8086:7010]
00:01.3 Bridge [0680]: Intel Corporation 82371AB/EB/MB PIIX4 ACPI [8086:7113]
(rev 03)
08:02.0 VGA compatible controller [0300]: Device [1234:1111] (rev 02)
00:03.0 Ethernet controller [0200]: Intel Corporation 82540EM Gigabit Ethernet
Controller [8086:100e](rev 03)
00:1a.0 USB controller 0c03]: Intel Corporation 82371SB PIIX3 [Natoma/Triton II]
[8086:7020] (rev 01)
00:01.2 USB controller [0c03]: Intel Corporation 82371SB PIIX3 USB
[Natoma/Triton II] [8086:7020] (rev 01)

Important Take note of the highlighted USB controller device code, as you will need this code to
perform the next example.

15.9 Step 9
Using the highlighted value from the output of the previous command, display the details about the USB
Controller:

lspci -v -d 8086:7020
[root@localhost ~]# lspci -v -d 8086:7020
00:01.2 USB controller [0c03]: Intel Corporation 82371SB PIIX3 USB
[Natoma/Triton II] [8086:7020] (rev 01) (prog-if 00 [UHCI])

Subsystem: Red Hat, Inc. QEMU Virtual Machine


Flags: bus master, fast devsel, latency 0, IRQ 11
I/O ports at c040 [size=32]

Kernel driver in use: uhci_hcd


00:04.0 USB controller: Intel Corporation 82371SB PIIX3 USB [Natoma/Triton II]
(rev 01) (prog-if 00 [UHCI])
Subsystem: Red Hat, Inc. QEMU Virtual Machine
Physical Slot: 4
Flags: bus master, fast devsel, latency 0, IRQ 10
I/O ports at c060 [size=32]

Kernel driver in use: uhci_hcd

15.10 Step 10
Display all of the SATA drives on the system by executing the following command:

ls /dev/sd*
[root@centos ~]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2
[root@centos ~]#

Devices that begin with sd in the /dev directory are device files that represent SATA or SCSI devices.

15.11 Step 11
Display kernel modules that are loaded into memory by executing the lsmod command:

lsmod | less
[root@centos ~]# lsmod | less
Module Size Used by
crc32_pclmul 13133 0
ghash_clmulni_intel 13273 0
ppdev 17671 0
aesni_intel 189414 0
lrw 13286 0 aesni_intel

gf128mul 15139 1 lwr

glue_helper 13990 1 aesni_intel

ablk_helper 21190 3 aesni_intel


cryptd 21190 3 ghash_clmulni_intel, aesni_intel, ablk_helper
joydev 17389 0

Some output has been omitted in the example above for brevity.
Type Q to exit the less command:
q

15.12 Step 12
Display information about the dm_mod module by executing the following command:

modinfo dm_mod | less


[root@centos ~]# modinfo dm_mod | less

Filename: /lib/modules/3.10.0-957.el7.x86_64/kernel/drivers/md/dm-mod.ko.xz
license: GPL
author: Joe Thornber <[email protected]>
description: device-mapper driver
alias: devname:mapper/control
alias: char-major-10-236
retpoline: Y
rhelversion: 7.6
srcversion: BA7CED77E4803DA1F325BC6
depends:
intree: 3.10.0-957.el7.x86_64 SMP mod_unload modversions
signer: CentOS Linux kernel signing key
sig_key: B7:0D:CF:0D:F2:D9:B7:F2:91:59:24:82:49:FD:6F:E8:7B:78:14:2
sig_hashalgo: sha256
PARM: reserved_rq_based_ios:Reserved IOs in request-based mempools
(uint)
parm: use_blk_mq:Use block multiqueue for request-based DM devices
(bool)
parm: dm_mq_nr_hw_queues:Number of hardware queues for request-based
dm-mq devices (uint)
parm: dm_mq_queue_depth:Queue depth for request-based dm-mq devices
(uint)
:

Type Q to exit the less command:

15.13 Step 13
Display information about the dm_log module by executing the following command:
modinfo dm_log
[root@centos ~]# modinfo dm_log
filename: /lib/modules/3.10.0-957.e17.x86_64/kernel/drivers/md/dm-log.ko.xz
license: GPL
author: Joe Thornber, Heinz Mauelshagen <[email protected]>
description: device-mapper dirty region log
retpoline: Y
rhelversion: 7.6
srcversion: 2520F689AFECC997AB36ADE
depends: dm-mod
intree: Y
vermagic: 3.10.0-957.el7.x86_64 SMP mod_unload modversions
signer: CentOS Linux kernel signing key
sig_key: B7:0D:CF:0D:F2:D9:B7:F2:91:59:24:82:49:FD:6F:E8:7B:78:14:27
sig_hashalgo: sha256

Notice that the dm_log module has a dependency module: dm-mod. Because the modules are currently
loaded into memory, you can see this dependency by looking at the output of the lsmod command:

lsmod
[root@centos ~]# lsmod
...
floppy 69432 0
dm_mirror 22289 0
dm_region_hash 20813 1 dm_mirror
dm_log 18411 2 dm_region_hash,dm_mirror
dm_mod 124407 8 dm_log,dm_mirror

Some output has been omitted in the example above for brevity.

15.14 Step 14
Determine if the fat or vfat modules are currently loaded into memory by executing the following
command:

lsmod | grep fat


[root@centos ~]# lsmod | grep fat
[root@centos ~]#

The lack of output from the previous command indicates that neither the fat nor vfat module is
currently loaded into memory.
15.15 Step 15
Load the vfat module into memory by executing the following command:

modprobe vfat
[root@centos ~]# modprobe vfat
[root@centos ~]#

15.16 Step 16
Verify that the vfat module has been loaded by executing the following command:

lsmod | grep fat


[root@centos ~]# lsmod | grep fat
vfat 10584 0
fat 54992 1 vfat

15.17 Step 17
Try to remove the fat module from memory by executing the following command:

modprobe -r fat
[root@centos ~]# modprobe -r fat
modprobe: FATAL: Module fat is in use.

15.18 Step 18
Remove the vfat module from memory and verify by executing the following commands:
modprobe -r vfat
lsmod | grep fat
[root@centos ~]# modprobe -r vfat
[root@centos ~]# lsmod | grep fat
[root@centos ~]#

17.0 Introduction
In order to provide the functionality required for this lab, the companion VM may require a minute or two
to load.
The boot process starts with the bootloader, the program that loads the kernel into memory and
executes instructions to boot the system. Typically, administrators do not find it necessary to make
many changes to the bootloader, but you should know how to modify some of the key GRUB
configurations, as well as know how to interact with the bootloader interactively when the system is
booting.

17.1 Step 1
Please use the Ubuntu image to complete the following steps. Select the Ubuntu PC by clicking on
the Ubuntu PC tab in the window on the right side of the screen.
Log in to the system using the root account. When prompted, provide the root password:

root
netlab123
Ubuntu 18.04.2 LTS ubuntu tty1
ubuntu login: root
Password:
Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0-45-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by


applicable law.

root@ubuntu:~#

17.2 Step 2
This system supports GRUB2. View the first 10 lines of the /boot/grub/grub.cfg file by executing
the following command:

head /boot/grub/grub.cfg
root@ubuntu:~# head /boot/grub/grub.cfg
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub
#
### BEGIN /etc/grub/d/00_header ###
if [ -s $prefix/grubenv ]; then
set have_grubenv=true

17.3 Step 3
Notice that this file is not designed to be edited directly. Instead, you modify settings in
the /etc/default/grub file. To edit this file, first launch the vi editor:

vi /etc/default/grub
root@ubuntu:~# vi /etc/default/grub

17.4 Step 4
Next, we will change the value of GRUB_TIMEOUT_STYLE to menu and GRUB_TIMEOUT to 30. Execute
the following vi commands ([ESC] means press the Escape key and the 0 character is zero):

7G
$
xxxxxx
a
menu
[ESC]
[Down Arrow Key]
x
a
30
[ESC]
:wq
[Enter]

17.5 Step 5
Next, execute the following command to verify your changes. They should look like the following
graphic:

root@ubuntu:~# head /etc/default/grub


# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
# info -f grub -n 'Simple configuration'

GRUB_DEFAULT=0

GRUB_TIMEOUT_STYLE=menu

GRUB_TIMEOUT=30
GRUB_DISTRIBUTOR='lsb_release -i -s 2> /dev/null || echo Debian'
GRUB_CMDLINE_LINUX_DEFAULT=“quiet”

17.6 Step 6
Notice that the first line of the /etc/default/grub file indicates that the update-grub command
must be executed after modifying this file. Execute that command, then reboot the system and watch
the screen for the countdown:

update-grub
root@ubuntu:~# update-grub
Sourcing file ‘/etc/default/grub’
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.15.0-45-generic
Found initrd image: /boot/initrd.img-4.15.0-45-generic
done
root@ubuntu:~# reboot

17.7 Step 7
When the system boots, you should see a countdown at the bottom of the screen. Before it reaches 0,
press the Escape key:

[ESC]

17.8 Step 8
After pressing the Escape key, you will be presented with the following menu:

17.9 Step 9
Press the Down Arrow key once and then press the Enter key to select Advanced options for
Ubuntu. This will display another menu, which includes the ability to boot to a recovery mode:

Press Down Arrow


[Enter]

17.10 Step 10
Press the Down Arrow key once so the "...(recovery mode)" option is selected and press the e key to
enter the edit mode:

Press Down Arrow


e

17.11 Step 11
This option will boot the system to a recovery runlevel where an administrator can fix system problems:
17.12 Step 12
Press the Escape key twice to return to the primary menu:

[ESC]
[ESC]

17.13 Step 13
Press the Enter key to boot the system:

[Enter]

17.14 Step 14
Please use the CentOS image to complete the remaining steps. Select the CentOS PC by clicking on
the CentOS Legacy PC tab in the window on the right side of the screen.
Note
This lab requires an older version of CentOS in order to practice using Grub Legacy, which is
unavailable on modern systems.
Log in to the system using the root account. When prompted, provide the root password:

root
netlab123
CentOS release 6.10 (Final)
Kernel 2.6.32-754.el6.x86_64 on an x86_64

centos login: root


Password:
Last login: Wed Aug 20 08:17:32 on tty1
[root@centos ~]#

17.15 Step 15
This system supports traditional GRUB. View the /boot/grub/grub.conf file by executing the
following command:

cat /boot/grub/grub.conf
[root@centos ~]# cat /boot/grub/grub.conf

The timeout value determines how long the user has before the system starts booting to the default
OS. In this example, there is only one OS, defined by the title directive. The hiddenmenu directive
indicates that the GRUB menu is not displayed by default during the countdown provided by the GRUB
before booting the system.

17.16 Step 16
Modify the /boot/grub/grub.conf file by executing the following command:

vi /boot/grub/grub.conf
[root@centos ~]# vi /boot/grub/grub.conf

17.17 Step 17
Next, change the timeout to 60 and "comment out" the hiddenmenu directive by executing the
following vi commands ([ESC] means press the Escape key):

11G
$
x
a
60
[ESC]
Enter
Press Down Arrow
I
#
[ESC]
:wq

17.18 Step 18
Verify your changes by viewing the /boot/grub/grub.conf file by executing the following command:

cat /boot/grub/grub.conf

In traditional GRUB, changes to the configuration file do not require running any commands after editing
the file.

17.19 Step 19
Reboot the system and watch the screen during the boot process for the countdown to begin:

[root@centos ~]# reboot

17.20 Step 20
When the system boots, you should see the GRUB menu countdown at the bottom of the screen.
Before it reaches 0, press the Escape key:

[ESC]

17.21 Step 21
After pressing the Escape key, you will be presented with the following menu:
17.22 Step 22
Type the letter e to edit the current title:

You will be provided with the following screen:


The line that you would most likely edit is the kernel line. By adding (or removing) arguments on this
line, you can affect how the system will boot. Keep in mind that any changes made here are not
permanent. To make them permanent, you must edit the /boot/grub/grub.conf file after booting
the system.

17.24 Step 24
You will be placed in edit mode at the end of the kernel line:

[ Minimal BASH-like line editing is supported. For the first word, TAB
lists possible command completions. Anywhere else TAB lists the possible
completions of a device/filename. ESC at any time cancels. ENTER
at any time accepts your changes.]

<=VolGroup/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet_

The rhgb argument stands for Red Hat Graphical Boot. Instead of displaying text messages during
boot, a graphical progress bar is displayed. While more user-friendly, this doesn't help the administrator
troubleshoot boot problems.
The quiet argument suppresses many of the text messages that are displayed if the rhgb argument
isn't used. Again, this may be more user-friendly, but an administrator should remove this setting when
troubleshooting boot problems.

17.25 Step 25
Press the Backspace key 10 times to remove the rhgb and quiet settings. Then, type single:

Press Backspace Key 10x


single

By adding single to the end of the kernel line, the system will be booted to the single user runlevel.

17.26 Step 26
Your screen should look like the following:

[ Minimal BASH-like line editing is supported. For the first word, TAB
lists possible command completions. Anywhere else TAB lists the possible
completions of a device/filename. ESC at any time cancels. ENTER
at any time accepts your changes.]

<=VolGroup/lv_root KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM single

17.27 Step 27
Press the Enter key to accept the changes:

Enter

17.28 Step 28
You will be presented the edit screen again:
7.29 Step 29
Press the b key to boot the system. Notice how the boot messages are displayed (your system may
appear different from what you see in the following graphic).

b
17.30 Step 30
Notice that when the system finishes booting, you are automatically logged in as the root user:

Checking filesystems
/dev/mapper/VolGroup-lv_root: clean, 22697/262144 files, 241986/1048576 blocks
/dev/sda1: clean, 38/32768 files, 12691/131072 blocks
[ OK ]
Remounting root filesystem in read-write mode: [ OK ]
Mounting local filesystems: [ OK ]
Enabling /etc/fstab swaps: [ OK ]
[root@centos /]#

17.31 Step 31
Type the runlevel command to verify that you are at runlevel S (or single user):

[root@centos /]# runlevel


N S

At the single user runlevel, very few processes are running, and only the administrator can access the
system. The purpose of this runlevel is to troubleshoot critical system problems.

7.32 Step 32
Let’s pretend you have fixed whatever problem prompted you to go to the single user runlevel. To boot
the system to the default runlevel, Press Ctrl+D (hold down the Control key and press the letter d):

Ctrl+d

The system will boot and you will be prompted with a login screen:

CentOS release 6.10 (Final)


Kernel 2.6.32-754.el6.x86_64 on an x86_64

centos login:

18.0 Introduction
In order to provide the functionality you need to apply these concepts, this VM may require a minute or
two to load.
Having different runlevels provides a means to fine-tune your operating system. You can have specific
services running at different runlevels, providing an easy way to change the state of the system.
In this lab, you will explore two distributions, which both make use of the Upstart service to different
degrees: CentOS and Ubuntu.

18.1 Step 1
Please use the Legacy CentOS image to complete the remaining steps. Select the CentOS PC by
clicking on the tab in the window on the right side of the screen.
This portion of the lab requires an older version of CentOS in order to practice using Grub Legacy,
which is unavailable on modern systems.
Click on the CentOS PC tab and log in to the system using the root account. When prompted, provide
the root password:

root
netlab123
CentOS release 6.10 (Final)
Kernel 2.6.32-754.el6.x86_64 on an x86_64

centos login: root


Password:
[root@centos ~]#

18.2 Step 2
List the contents of the /etc/init.d directory:
ls /etc/init.d
[root@centos ~]# 1s /etc/init.d

auditd halt killall multipathd quota_nld saslauthd


blk-availability ip6tables lvm2-lvmetad netconsole rdisc single
crond iptables lvm2-monitor netfs restorecond sshd .
functions iscsi mdmonitor network rsyslog udev-post
haldaemon iscsid messagebus postfix sandbox
[root@centos ~]#

18.3 Step 3
Execute the following command to see the current status of the sshd service:

/etc/init.d/sshd status
[root@centos ~]# /etc/init.d/sshd status
openssh-daemon (pid 984) is running...
[root@centos ~]#

The Process ID (pid) in the terminal above may be different in our virtual environment.

18.4 Step 4
Execute the following commands to stop the sshd service and verify that it is stopped:

/etc/init.d/sshd stop
[root@centos ~]# /etc/init.d/sshd stop
Stopping sshd: [ OK ]
[root@centos ~]#

18.5 Step 5
Execute the following commands to start the sshd service and verify that it is started:

/etc/init.d/sshd start
/etc/init.d/sshd status
[root@centos ~]# /etc/init.d/sshd start
Starting sshd: [ OK ]
[root@centos ~]# /etc/init.d/sshd status
openssh-daemon (pid 1295) is running...
[root@centos ~]#

18.6 Step 6
Execute the following commands to restart the sshd service and verify that it is started:

/etc/init.d/sshd restart
/etc/init.d/sshd status
[root@centos ~]# /etc/init.d/sshd restart
Stopping sshd: [ OK ]
Starting sshd: [ OK ]
[root@centos ~]# /etc/init.d/sshd status
openssh-daemon (pid 1315) is running...
[root@centos ~]#

18.7 Step 7
Execute the following command to determine which arguments can be passed to
the /etc/init.d/sshd command:

/etc/init.d/sshd
[root@centos ~]# /etc/init.d/sshd
Usage: /etc/init.d/sshd {start|stop|restart|reload|force-reload|condrestart|try-
restart|status}
[root@centos ~]#

A common question that beginning Linux users have is "what does this script really do?". The next step
of this lab focuses on how you can figure out by looking at the script itself.

18.8 Step 8
Use the more command to display the contents of the /etc/init.d/sshd file:

more /etc/init.d/sshd
#!/bin/bash
#
# sshd Start up the OpenSSH server daemon
#
# chkconfig: 2345 55 25
# description: SSH is a protocol for secure remote shell access. \
# This service starts up the OpenSSH server daemon.
#
# processname: sshd
# config: /etc/ssh/ssh_host_key
# config: /etc/ssh/ssh_host_key.pub
# config: /etc/ssh/ssh_random_seed
# config: /etc/ssh/sshd_config
# pidfile: /var/run/sshd.pid

### BEGIN INIT INFO


# Provides: sshd
# Required-Start: $local_fs $network $syslog
# Required-Stop: $local_fs $syslog
# Should-Start: $syslog
# Should-Stop: $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start up the OpenSSH server daemon
--More--(14%)

Note that the third line of this file, Start up the OpenSSH server daemon, describes what this
script does. The description line provides more details and the processname line provides the
exact name of the process that this script starts and stops.
Suppose the description provided isn't really enough for you to understand what this service actually
does. To learn more, you could look at the man page for sshd (although in this lab environment, the
man pages don't exist, so this would be more of a "real world" solution).
To quit the more command, type Q.

18.9 Step 9
Execute the following commands to view a list of the scripts that are started when the system is brought
to runlevel 3:

cd /etc/rc.d/rc3.d
ls S*
[root@centos ~]# cd /etc/rc.d/rc3.d
[root@centos rc3.d]# ls S*

S02lvm2-monitor S11auditd S15mdmonitor S26udev-post S90crond


S07iscsid S12rsyslog S25blk-availability S55sshd S99local
S10network S13iscsi S25netfs S80postfix
[root@centos rc3.d]#

18.10 Step 10
Execute the following command to view a list of the scripts that are stopped when the system is brought
to runlevel 3:

ls K*
[root@centos rc3.d]# ls K*
K10saslauthd K87restorecond K89rdisc K92iptables
K87multipathd K89netconsole K92ip6tables
[root@centos rc3.d]#

18.11 Step 11
Execute the following command to see the chkconfig information for the sshd script:

grep chkconfig /etc/init.d/sshd


[root@centos rc3.d]# grep chkconfig /etc/init.d/sshd
# chkconfig: 2345 55 25
[root@centos rc3.d]#

Recall that the first value (2345) is the runlevel that the sshd service should be run by default. The
second value (55) is the start number for the script, and the third value (25) is the stop value for the
script.

18.12 Step 12
Execute the following command to display when the sshd is started:

chkconfig --list sshd


[root@centos rc3.d]# chkconfig --list sshd
sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@centos rc3.d]#

Based on the output from the previous command, the ssh should start when the system goes to
runlevels 2,3,4, and 5. Conversely, the ssh services should be stopped at runlevels 0,1,and 6.

18.13 Step 13
Execute the following command to verify that runlevels 2, 3, 4, and 5 contains start scripts for
the sshd service:

ls /etc/rc.d/rc[0-6].d/S*sshd
[root@centos rc3.d]# ls /etc/rc.d/rc[0-6].d/S*sshd
/etc/rc.d/rc2.d/S55sshd /etc/rc.d/rc4.d/S55sshd
/etc/rc.d/rc3.d/S55sshd /etc/rc.d/rc5.d/S55sshd
[root@centos rc3.d]#

18.14 Step 14
Execute the following command to verify that runlevels 0, 1, and 6 contain stop scripts for
the sshd service:
ls /etc/rc.d/rc[0-6].d/K*sshd
[root@centos rc3.d]# ls /etc/rc.d/rc[0-6].d/K*sshd
/etc/rc.d/rc0.d/K25sshd /etc/rc.d/rc1.d/K25sshd /etc/rc.d/rc6.d/K25sshd
[root@centos rc3.d]#

18.15 Step 15
Execute the following commands to have the sshd script stopped at all runlevels and confirm:

chkconfig sshd off


chkconfig --list sshd
[root@centos rc3.d]# chkconfig sshd off
[root@centos rc3.d]# chkconfig --list sshd
sshd 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@centos rc3.d]#

18.16 Step 16
Execute the following commands to have the sshd script started only at runlevel 3 and confirm:

chkconfig --level 3 sshd on


chkconfig --list sshd
[root@centos rc3.d]# chkconfig --level 3 sshd on
[root@centos rc3.d]# chkconfig --list sshd
sshd 0:off 1:off 2:off 3:on 4:off 5:off 6:off
[root@centos rc3.d]#

18.17 Step 17
Execute the following command to verify the runlevels that contain stop scripts for the sshd service:

ls /etc/rc.d/rc[0-6].d/K*sshd
[root@centos rc3.d]# ls /etc/rc.d/rc[0-6].d/K*sshd
/etc/rc.d/rc0.d/K25sshd /etc/rc.d/rc2.d/K25sshd /etc/rc.d/rc5.d/K25sshd
/etc/rc.d/rc1.d/K25sshd /etc/rc.d/rc4.d/K25sshd /etc/rc.d/rc6.d/K25sshd
[root@centos rc3.d]#

18.18 Step 18
Execute the following command to display the current runlevel:
runlevel
[root@centos rc3.d]# runlevel
N 3
[root@centos rc3.d]#

8.19 Step 19
Execute the following command to view the default runlevel

tail /etc/inittab
[root@centos rc3.d]# tail /etc/inittab
# Default runlevel. The runlevels used are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser,without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#
id:3:initdefault:
[root@centos rc3.d]#

18.20 Step 20
Use the vi command to modify the /etc.inittab file in order to change the default runlevel:

vi /etc/inittab
[root@centos rc3.d]# vi /etc/inittab

18.21 Step 21
Use the Down Arrow to move to the last line and then use the vi command to replace the value of 3
with a value of 2:

Down Arrow
Right Arrow
i
Delete
2
Esc
:wq!

Before

# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.


#
# System initialization is started by /etc/init/rcS.conf
#
# Individual runlevels are started by /etc/init/rc.conf
#
# Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf
#
# Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf.
# with configuration in /etc/sysconfig/init.
#
# For information on how to write upstart even handlers, or how
# upstart works, see init(5), init(8), and initctl(8).
#
# Default runlevel. The runlevels used are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#
id:3:initdefault:

After

# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.


#
# System initialization is started by /etc/init/rcS.conf
#
# Individual runlevels are started by /etc/init/rc.conf
#
# Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf
#
# Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf.
# with configuration in /etc/sysconfig/init.
#
# For information on how to write upstart even handlers, or how
# upstart works, see init(5), init(8), and initctl(8).
#
# Default runlevel. The runlevels used are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#
id:2:initdefault:

18.22 Step 22
Verify these changes by typing the following command

tail /etc/inittab
[root@centos rc3.d]# tail /etc/inittab
# Default runlevel. The runlevels used are:
# 0 - halt (Do NOT set initdefault to this)
# 1 - Single user mode
# 2 - Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 - Full multiuser mode
# 4 - unused
# 5 - X11
# 6 - reboot (Do NOT set initdefault to this)
#
id:2:initdefault:
[root@centos rc3.d]#
18.23 Step 23
Reboot the machine:

reboot
[root@centos rc3.d]# reboot

18.24 Step 24
After the system is finished booting, log in to the system using the root account. When prompted,
provide the root password:

root
netlab123
CentOS release 6.10 (Final)
Kernel 2.6.32-754.el6.x86_64 on an x86_64

centos login: root


Password:
Last login: Mon Nov 3 13:45:47 on tty1
[root@centos ~]#

18.25 Step 25
Execute the following command to view the previous and current runlevel:

runlevel
[root@centos ~]# runlevel
N 2
[root@centos ~]#

18.26 Step 26
Execute the following command to verify the status of the sshd daemon:

/etc/init.d/sshd status
[root@centos ~]# /etc/init.d/sshd status
openssh-daemon is stopped
[root@centos ~]#

18.27 Step 27
Execute the following system to runlevel 3 by executing the following command:

telinit 3
[root@centos ~]# telinit 3

[root@centos ~]# Mounting filesystems: [ OK ]


Retrigger failed udev events [ OK ]
Starting sshd: [ OK ]

You may need to press Enter for the prompt to appear after the command has executed.

18.28 Step 28
Wait for the process to comment and verify that the telinit command took the system to runlevel 3 by
executing the following command:

runlevel
[root@centos ~]# runlevel
2 3
[root@centos ~]#

18.29 Step 29
Verify that the sshd daemon started by checking the status:

/etc/init.d/sshd status
[root@centos ~]# /etc/init.d/sshd status
openssh-daemon (pid 1203) is running...
[root@centos ~]#

18.30 Step 30
View the contents of the /etc/init directory:

ls /etc/init
[root@centos ~]# ls /etc/init
control-alt-delete.conf quit-plymouth.conf serial.conf
init-system-dbus.conf rc.conf splash-manager.conf
kexec-disable.conf rcS.conf start-ttys.conf
plymouth-shutdown.conf rcS-emergency.conf tty.conf
prefdm.conf rcS-sulogin.conf
[root@centos ~]#

Recall that the /etc/init directory is used by Upstart. If this distribution purely used Upstart (and no
traditional init scripts), then there would be more files in this directory to define when services would
start.

18.31 Step 31
View the contents of the /etc/init/control-alt-delete.conf file:

more /etc/init/control-alt-delete.conf
[root@centos ~]# more /etc/init/control-alt-delete.conf
# control-alt-delete - emergency keypress handling
#
# This task is run whenever the Control-Alt-Delete key combination is
# pressed. Usually used to shut down the machine.
#
# Do not edit this file directly. If you want to change the behaviour,
# please create a file control-alt-delete.override and put your changes there.

start on control-alt-delete

exec /sbin/shutdown -r now "Control-Alt-Delete pressed"


[root@centos ~]#

If you look at the last line of this file, you will see that if someone performs a Control-Alt-Delete,
the shutdown command would be executed. The system would be rebooted immediately after
the shutdown command sends everyone the message Control-Alt-Delete pressed.
Note that you should not modify this file directly. Instead, create a file called control-alt-
delete.override and specify your customizations in that file.

18.32 Step 32
To modify the behavior of the system when someone performs a control-alt-delete key sequence, first
make a copy of the /etc/init/control-alt-delete.conf file:

cd /etc/init
cp control-alt-delete.conf control-alt-delete.override
[root@centos ~]# cd /etc/init
[root@centos init]# cp control-alt-delete.conf control-alt-delete.override
[root@centos init]#
18.33 Step 33
Change the shutdown command so it doesn't happen immediately, but rather that it waits 5 minutes to
allow everyone the time to save work and log off. First, open the file in the vi editor:

vi control-alt-delete.override
[root@centos init]# vi control-alt-delete.override

18.34 Step 34
Use vi commands to make the change to the file:

Down Arrow
Right Arrow
i
Delete x3
+5
Esc
:wq!

Before

# control-alt-delete - emergency keypress handling


#
# This task is run whenever the Control-Alt-Delete key combination is
# pressed. Usually used to shut down the machine.
#
# Do not edit this file directly. If you want to change the behaviour,
# please create a file control-alt-delete.override and put your changes there.

start on control-alt-delete

exec /sbin/shutdown -r now "Control-Alt-Delete pressed"

After

# control-alt-delete - emergency keypress handling


#
# This task is run whenever the Control-Alt-Delete key combination is
# pressed. Usually used to shut down the machine.
#
# Do not edit this file directly. If you want to change the behaviour,
# please create a file control-alt-delete.override and put your changes there.

start on control-alt-delete

exec /sbin/shutdown -r +5 "Control-Alt-Delete pressed"

By replacing now with a +5, the shutdown command will wait 5 minutes before rebooting the system.
Do not attempt to perform a control-alt-delete after finishing the previous step. This was just a
demonstration of how to create the file, not something designed to be tested in this virtual machine.

18.35 Step 35
Please use the Ubuntu image to complete the following steps. Select the Ubuntu PC by clicking on the
tab in the window on the right side of the screen.
Click on the Ubuntu PC tab and login with the username root and the password:

root
netlab123
Ubuntu 18.04.2 LTS ubuntu tty1
ubuntu login: root
Password:
Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0-45-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by


applicable law.

root@ubuntu:~#

18.36 Step 36
Execute the following command to view the contents of the /etc/init directory:
ls /etc/init.d | more
root@ubuntu:~# ls /etc/init.d | more

apparamor
console-setup.sh
cron
dbus
grub-common
hwclock.sh
irqbalance
keyboard-setup.sh
kmod
lvm2
lvm2-lvmetad
lvm2-lvmpolld
plymouth
plymouth-log
proccps
quota
quotarpc
rsync
rsyslog
ssh
udev
ufw
uuid

18.37 Step 37
Recall that the configuration files in the /etc/init.d directory determine which services are started at
different run levels. For example, execute the following command to see which runlevels
the ssh service starts:

grep runlevel /etc/init.d/ssh


root@ubuntu:~# grep runlevel /etc/init.d/ssh
([ "$previous" ] && [ "$runlevel" ]) || [ "$runlevel"= S ]

Note in the output above, the string "$runlevel"= S indicates that the runlevel is single user mode
18.38 Step 38
While Ubuntu mostly uses Upstart, there are a few traditional init scripts that you can see in
the /etc/init.ddirectory:

ls /etc/init.d
root@ubuntu:~# ls /etc/init.d
apparmor grub-common kmod plymouth quotarpc udev
console-setup.sh hwclock.sh lvm2 plymouth-log rsync ufw
cron irqbalance lvm2-lvmetad procps rsyslog uuid
dbus keyboard-setup.sh lvm2-lvmpolld quota ssh

Most of these init scripts are for backward compatibility for older services. An example would be
the ssh service functionality even though it is configured as an Upstart service.

18.39 Step 39
Execute the following command to restart the ssh service:

/etc/init.d/ssh restart
root@ubuntu:~# /etc/init.d/ssh restart
[ ok ] Restarting ssh (via systemctl): ssh.service.

You might also like