Table of Content

Weight: 3

Description: Candidates should be able to manage the SysVinit runlevel or systemd boot target of the system. This objective includes changing to single user mode, shutdown or rebooting the system. Candidates should be able to alert users before switching runlevels / boot targets and properly terminate processes. This objective also includes setting the default SysVinit runlevel or systemd boot target. It also includes awareness of Upstart as an alternative to SysVinit or systemd.

Key Knowledge Areas:

Set the default runlevel or boot target
Change between runlevels / boot targets including single user mode
Shutdown and reboot from the command line
Alert users before switching runlevels / boot targets or other major system events
Properly terminate processes

Terms and Utilities:

/etc/inittab
shutdown
init
/etc/init.d/
telinit
systemd
systemctl
/etc/systemd/
/usr/lib/systemd/
wall

+++ runlevels

0 = halt/shutdown
1 = s or S, Single user mode
2 = Debian/ubuntu full multi mode with X/gui
3 = Redhat full multi text mode
4 = undefined
5 = Redhat same as 3 with GUI
6 = reboot

+++ identify service in runlevel

SysV

/etc/inittab

id:runlevels:action:process
l0:wait:/etc/init.d/rc 0

+++ manage runlevel service

SysV only

chkconfig –list
chkconfig –list nfs-common
chkconfig –level 23 nfs-common on
chkconfig –add nfs-common

+++ check current runlevel

grep initdefault /etc/inittab
id:2:initdefault:

runlevel

root@dclab-u1504s:/var/log# runlevel
N 5

root@dclab-u1504s:/var/log# who -r
run-level 5 2015-10-30 08:39

+++ change runlevel

telinit – same as init, take q or Q to reread /etc/inittab to update change

root@dclab-u1504s:/lib/systemd/system# ls -l $(which telinit)
lrwxrwxrwx 1 root root 14 Jun 2 16:29 /sbin/telinit -> /bin/systemctl

root@dclab-u1504s:/lib/systemd/system# ls -l $(which init)
lrwxrwxrwx 1 root root 20 Jun 2 16:29 /sbin/init -> /lib/systemd/systemd

+++ shutdown

shutdown -r now
shutdown -k msg # not reboot only waring msg
shutdown -h “now|

halt
reboot
poweroff

root@dclab-u1504s:/var/log# ls -l /sbin/halt
lrwxrwxrwx 1 root root 14 Jun 2 16:29 /sbin/halt -> /bin/systemctl
root@dclab-u1504s:/var/log# ls -l /sbin/reboot
lrwxrwxrwx 1 root root 14 Jun 2 16:29 /sbin/reboot -> /bin/systemctl
root@dclab-u1504s:/var/log# ls -l /sbin/poweroff
lrwxrwxrwx 1 root root 14 Jun 2 16:29 /sbin/poweroff -> /bin/systemctl
root@dclab-u1504s:/var/log# ls -l /sbin/shutdown
lrwxrwxrwx 1 root root 14 Jun 2 16:29 /sbin/shutdown -> /bin/systemctl

+++ Upstart
concept of jobs
support hotplug hardware
/etc/init own scripts
/etc/init/serivcename.conf

root@dclab-u1504s:/etc/init# cat dmesg.conf
# dmesg – save kernel messages
#
# This task saves the initial kernel message log.

description “save kernel messages”

start on runlevel [2345]

task
script
savelog -q -p -c 5 /var/log/dmesg
dmesg -s 524288 > /var/log/dmesg
chgrp adm /var/log/dmesg
end script

initctl list
initctl status job
initctl reload job

+++ Systemd
– in order to gain speed and enhance parallelism in system startup, systemd creates sockets at startup, but only starts associated task when a connection request for services on that sockets is received
– systemd uses autofs to define mount points, the actual mount may be delayed until some process attempts to open a file on the file system or otherwise use it
– units control group, target units group other unit together, providing a single control unit for multi other units

using units to define what things started, mapping jobs or units to System V runlevel
root@dclab-u1504s:/lib/systemd/system# pwd
/lib/systemd/system
root@dclab-u1504s:/lib/systemd/system# ls -l runlevel*.target
lrwxrwxrwx 1 root root 15 Jun 2 16:29 runlevel0.target -> poweroff.target
lrwxrwxrwx 1 root root 13 Jun 2 16:29 runlevel1.target -> rescue.target
lrwxrwxrwx 1 root root 17 Jun 2 16:29 runlevel2.target -> multi-user.target
lrwxrwxrwx 1 root root 17 Jun 2 16:29 runlevel3.target -> multi-user.target
lrwxrwxrwx 1 root root 17 Jun 2 16:29 runlevel4.target -> multi-user.target
lrwxrwxrwx 1 root root 16 Jun 2 16:29 runlevel5.target -> graphical.target
lrwxrwxrwx 1 root root 13 Jun 2 16:29 runlevel6.target -> reboot.target

[root@dclab-centos7 system]# systemctl get-default
multi-user.target

systemctl set-default .target
systemctl set-default runlevel6.target

systemctl list-units|grep -i

systemctl list-units |grep ssh
systemctl status ssh.service

pkg-config systemd –variable=systemdsystemconfdir

systemctl –no-pager