System Initialization and Services
◾
453
regular workstation but instead logged into remotely by system and server administrators).
The actual runlevel definitions differ from distribution to distribution but this is the most
common usage.
11.4.2 Executing rcS.conf and rc.sysinit
After inittab executes, the init process continues to invoke other startup scripts. These
scripts are located in /etc/init (not to be confused with the init process, called /sbin/init).
The
next script up is
rcS.conf
. It contains the following for loop:
for t in $(cat /proc/cmdline); do
case $t in
emergency)
start
rcS-emergency
break
;;
esac
done
The command
$(cat/proc/cmdline)
iterates through every word found in /
proc/
cmdline
. This file stores the kernel’s startup command. If any word is emergency, then
the script invokes the
rcS-emergency
script. The break statement forces the for loop
to exit as there is no need to continue searching through the command line once emer-
gency is found. The rcS-emergency.conf invokes the script /
etc/sysconfig/init
and
then executes two processes as necessary,
plymouth
and /
sbin/sulogin
. Plymouth
is a
bootsplash
program; it displays graphically information about the boot process. It is
interactive in that the user can provide input in spite of Linux not
yet enabling things such
as terminal windows. The sulogin program provides the user with the following prompting
message:
Give root password for system maintenance
(or type Control-D for normal startup):
This allows the user to enter single user system administrator mode (runlevel 1) or con-
tinue with the boot process normally.
If rcS-emergency does not execute, or if the user continues with the normal boot pro-
cess, rcS.conf then executes the /
etc/rc.d/rc.sysinit
script. This script is in charge of
initializing hardware, loading kernel modules, mounting special file systems (e.g., /proc, /
sys), and establishing numerous environment variables. It is also responsible for determin-
ing the status of SELinux. The rc.sysinit script contains a series of if-then statements to
start up processes to establish further environment variables.
For instance, you will find
if [ -f/etc/sysconfig/network ]; then
./etc/sysconfig/network
fi
454
◾
Linux with Operating System Concepts
This statement tests to see if the network script exists and if so, executes it. The net-
work script will establish additional environment variables (e.g., NETWORKING
=
yes,
HOSTNAME).
Other if-then statements determine whether to mount some other file systems. For
instance, you will find the following code:
if [ ! –e /proc/mount ]; then
mount –n –t proc/proc/proc
mount –n –t sysfs/sys/sys
>
/dev/null 2
>
&1
fi
This statement tests to see if /proc/mount does not yet exist and if not, it performs
the two mount operations mounting the /proc directory and the /sys directory. In the
case of /sys,
the notation
2
>
&1
refers to redirecting standard error (2) to the same loca-
tion that standard output (1) is pointing to. In essence, this discards (sends to /dev/null)
error messages that arise from the mount command so that they are not reported to the
console.
Next, the script /
etc/init.d/functions
is run. In this script, the system’s PATH
variable is established and exported. The primarily role of this script though is to define
functions that can be invoked from other script files yet to be run.
There are a variety of functions defined here, including functions to check the PID of a
process, output the PID of a process that is already running, set the PID of a new process,
kill a running process,
start a new process, and a group of functions that will be used to
interpret the information in /etc/fstab so that they can be initially mounted.
Returning to rc.sysinit, it next deals with either establishing or disabling SELinux. At
this point, rc.sysinit is in charge of initializing hardware and identifying plug-and-play
devices. User-defined and system-defined modules can be loaded using modprobe and
kernel parameters can be altered using sysctl. The file system is mounted, calling upon
functions defined in the functions script, and establishing the file /etc/mtab.
During mounting, disk quotas are checked and the quotaon process is started if any of
the file systems have established disk quotas.
Additionally, mounted file systems are estab-
lished as read-only or readable and writable, encryption is established (if called for), and
if a file system is determined to have corruption, fsck is suggested to the user. A number
of other bookkeeping activities are performed, including cleaning up log files under /var/
log, creating new log files to report on the most recent system initialization, and
dmesg
is called to report on the latest kernel initialization (dmesg is described at the end of this
section).
11.4.3 rc.conf and rc Scripts
The script /
etc/init/rc.conf
is
now executed, which then executes the script /
etc/
rc.d/rc
passing it the established runlevel. The rc script is responsible for establishing
the services needed for the given runlevel. This script contains the following two loops
(excerpted here):
System Initialization and Services
◾
455
for i in /etc/rc$runlevel.d/K*; do
$i stop
and
for i in /etc/rc$runlevel.d/S*; do
$i start
The variable
runlevel.d
stores the runlevel as provided by rc.conf, which was estab-
lished back in inittab. If, for instance, the runlevel is 5, then $runlevel is 5 and we have the
for loop
for i in/etc/rc5.d/K*; do
An examination of /etc shows that there are directories named rc0.d, rc1.d, rc2.d,
through rc6.d These seven directories contain symbolic links to service control scripts, all
of which are stored in /etc/init.d.
These symbolic links use the following
form for their names where
Do'stlaringiz bilan baham: