
58 Chapter 3. Boot Process, Init, and Shutdown
3.2.2. Init
The kernel finds /sbin/init and executes it. It is the init command which coordinates the rest of
the boot process.
When init starts, it becomes the parent or grandparent of all of the processes that start up automati-
cally on a Red Hat Linux system. First, it runs the /etc/rc.d/rc.sysinit script, which sets your
environment path, starts swap, checks the filesystems, and so on. Basically, rc.sysinit takes care
of everything that your system needs to have done at system initialization. Most systems use a clock,
so on them rc.sysinit uses the /etc/sysconfig/clock file to initialize the clock. If you have
special serial port processes that need to be initialized, rc.sysinit may also run rc.serial.
Then, init runs the /etc/inittab script, which describes how the system should be set up in each
runlevel and sets the default runlevel. (See Section 3.4 for more information on init runlevels.) This
file states, among other things, that /sbin/update should be run whenever a runlevel starts. The
update program is used to flush dirty buffers back to disk.
Whenever the runlevel changes, init uses the scripts in the /etc/rc.d/init.d/ directory to start
and stop various services, such as a Web server, DNS server, and so on. First, init sets the source
function library for the system (commonly /etc/rc.d/init.d/functions), which spells out how
to start or kill a program and how to find out the PID of a program. Then, init determines the current
and the previous runlevel.
Next, init starts all of the background processes necessary for the system to run by looking in the
appropriate rc directory for that runlevel (/etc/rc.d/rc
X .d/, where the X is a numerical
value between 0 and 6). The init command then runs each of the kill scripts (their file name starts
with a K) with a stop parameter. Then, init runs all of the start scripts (their file names start with an
S) in the appropriate runlevel directory with a start so that all services and applications are started
correctly. In fact, after the system is finished booting you can log in as root and execute these same
scripts manually with the command /etc/rc.d/init.d/httpd stop or /sbin/service httpd
stop. This will stop the httpd server.
None of the scripts that actually start and stop the services are located in the /etc/rc.d/rc X .d/
directory. Rather, all of the files in /etc/rc.d/rc
X .d/ are symbolic links that point to actual
scripts located in the /etc/rc.d/init.d/ directory. A symbolic link is nothing more than a file
that points to another file, and they are used in this case because they can be created and deleted
without affecting the actual script that kills or starts the service. The symbolic links to the various
scripts are numbered in a particular order so that they start in that order. You can change the order in
which the services start up or are killed by changing the name of the symbolic link that refers to the
script that actually starts or kills the service. You can give symbolic links the same number as other
symbolic links if you want that service start or stop right before or after another service.
For example, for runlevel 5, init looks into the /etc/rc.d/rc5.d/ directory and might finds the
following (your system and configuration may vary):
K01pppoe -> ../init.d/pppoe
K05innd -> ../init.d/innd
K10ntpd -> ../init.d/ntpd
K15httpd -> ../init.d/httpd
K15mysqld -> ../init.d/mysqld
K15pvmd -> ../init.d/pvmd
K16rarpd -> ../init.d/rarpd
K20bootparamd -> ../init.d/bootparamd
K20nfs -> ../init.d/nfs
K20rstatd -> ../init.d/rstatd
K20rusersd -> ../init.d/rusersd
K20rwalld -> ../init.d/rwalld
K20rwhod -> ../init.d/rwhod
K25squid -> ../init.d/squid
K28amd -> ../init.d/amd
Commenti su questo manuale