The Init Processes

 < Day Day Up > 



The init program is responsible for starting up all the system processes configured in the /etc/rc.d directory and its subdirectories. Until this point, the boot process is pretty much the same in all the different Linux distributions. The init program configuration is also conceptually the same, but the structure of /etc/rc.d directory and its contents may have slight differences among the different Linux distributions. To keep the discussion simple, the init program configuration is discussed for two popular Linux distributions, Red Hat and SuSE, as outlined in the first chapter. It is important to keep in mind that the init program is a process initiator, and hence for the system processes to run successfully, the basic system should be up and running with its root file system, which is ensured by the kernel before it kicks off the init program. Figure 2.4 displays the sequence of events that take place while booting a computer that has both Windows and Linux installed.

click to expand
Figure 2.4: Booting events in a dual boot configuration of Linux and Windows.

Red Hat Linux Init Process

The init program interacts with several scripts located mainly in the /etc/rc.d directory and its subdirectories. The /etc/rc.d directory contains a set of subdirectories and scripts designed to enable the init program to start up the Linux system with different configurations. The directories are named rc0, rc1, rc2, rc3, rc4, rc5, rc6 and init.d. In addition, there are initiation scripts such as rc, rc.sysinit, and rc.local.

Each of the files in the /etc/rc.d/init.d directory is an executable script and usually accepts a simple parameter such as start, stop, status, restart, and reload. Each of the directories named rcN (where N takes value 0 through 6) represents a specific run level that the system is booted to, and contains links to a subset of scripts from the /etc/rc.d/init.d directory to be executed at that run level. The links established in these directories start with K or S followed by a two-digit integer and the name of the script for which the link is established. The letter K indicates that the process identified by the link should be killed (or stopped), and the letter S indicates that the process should be started. The two-digit integer indicates the sequence in which the script must be executed (either for starting or for stopping), 00 being the highest priority and 99 being the lowest priority. Listing 2.1 displays a typical list of the links defined in run level 5 of a Red Hat Linux 8.0/9.0 system.

Listing 2.1

start example
lrwxrwxrwx 1 root root 19 Oct 12 16:44 K05saslauthd ->  ../init.d/saslauthd lrwxrwxrwx 1 root root 16 Oct 12 16:44 K12mysqld -> ../init.d/mysqld lrwxrwxrwx 1 root root 15 Oct 12 16:44 K15httpd -> ../init.d/httpd lrwxrwxrwx 1 root root 20 Oct 12 16:44 K15postgresql ->      ../init.d/postgresql lrwxrwxrwx 1 root root 13 Oct 12 16:44 K20nfs -> ../init.d/nfs lrwxrwxrwx 1 root root 14 Oct 12 16:44 K24irda -> ../init.d/irda lrwxrwxrwx 1 root root 15 Oct 12 16:44 K25squid -> ../init.d/squid lrwxrwxrwx 1 root root 19 Oct 12 16:44 K34yppasswdd ->      ../init.d/yppasswdd lrwxrwxrwx 1 root root 17 Oct 12 16:44 K35winbind -> ../init.d/winbind lrwxrwxrwx 1 root root 15 Oct 12 16:44 K45named -> ../init.d/named lrwxrwxrwx 1 root root 15 Oct 12 16:44 K50snmpd -> ../init.d/snmpd lrwxrwxrwx 1 root root 19 Oct 12 16:44 K50snmptrapd ->      ../init.d/snmptrapd lrwxrwxrwx 1 root root 13 Oct 12 16:44 K50tux -> ../init.d/tux lrwxrwxrwx 1 root root 13 Oct 12 16:44 K54pxe -> ../init.d/pxe lrwxrwxrwx 1 root root 17 Oct 12 16:44 K70aep1000 -> ../init.d/aep1000 lrwxrwxrwx 1 root root 17 Oct 12 16:44 K70bcm5820 -> ../init.d/bcm5820 lrwxrwxrwx 1 root root 14 Oct 12 16:44 K74ntpd -> ../init.d/ntpd lrwxrwxrwx 1 root root 16 Oct 12 16:44 K74ypserv -> ../init.d/ypserv lrwxrwxrwx 1 root root 16 Oct 12 16:44 K74ypxfrd -> ../init.d/ypxfrd lrwxrwxrwx 1 root root 19 Oct 12 16:44 K95firstboot ->      ../init.d/firstboot lrwxrwxrwx 1 root root 15 Oct 12 16:44 S05kudzu -> ../init.d/kudzu lrwxrwxrwx 1 root root 18 Oct 12 16:44 S08iptables ->      ../init.d/iptables lrwxrwxrwx 1 root root 14 Oct 12 16:44 S09isdn -> ../init.d/isdn lrwxrwxrwx 1 root root 17 Oct 12 16:44 S10network -> ../init.d/network lrwxrwxrwx 1 root root 16 Oct 12 16:44 S12syslog -> ../init.d/syslog lrwxrwxrwx 1 root root 17 Oct 12 16:44 S13portmap -> ../init.d/portmap lrwxrwxrwx 1 root root 17 Oct 12 16:44 S14nfslock -> ../init.d/nfslock lrwxrwxrwx 1 root root 18 Oct 12 16:44 S17keytable ->      ../init.d/keytable lrwxrwxrwx 1 root root 16 Oct 12 16:44 S20random -> ../init.d/random lrwxrwxrwx 1 root root 16 Oct 12 16:44 S24pcmcia -> ../init.d/pcmcia lrwxrwxrwx 1 root root 15 Oct 12 16:44 S25netfs -> ../init.d/netfs lrwxrwxrwx 1 root root 14 Oct 12 16:44 S26apmd -> ../init.d/apmd lrwxrwxrwx 1 root root 16 Oct 12 16:44 S28autofs -> ../init.d/autofs lrwxrwxrwx 1 root root 14 Oct 12 16:44 S55sshd -> ../init.d/sshd lrwxrwxrwx 1 root root 20 Oct 12 16:44 S56rawdevices ->      ../init.d/rawdevices lrwxrwxrwx 1 root root 16 Oct 12 16:44 S56xinetd -> ../init.d/xinetd lrwxrwxrwx 1 root root 13 Oct 12 16:44 S60lpd -> ../init.d/lpd lrwxrwxrwx 1 root root 18 Oct 12 16:44 S80sendmail ->      ../init.d/sendmail lrwxrwxrwx 1 root root 13 Oct 12 16:44 S85gpm -> ../init.d/gpm lrwxrwxrwx 1 root root 15 Oct 12 16:44 S90crond -> ../init.d/crond lrwxrwxrwx 1 root root 13 Oct 12 16:44 S90xfs -> ../init.d/xfs lrwxrwxrwx 1 root root 17 Oct 12 16:44 S95anacron -> ../init.d/anacron lrwxrwxrwx 1 root root 13 Oct 12 16:44 S95atd -> ../init.d/atd lrwxrwxrwx 1 root root 15 Oct 12 16:44 S97rhnsd -> ../init.d/rhnsd lrwxrwxrwx 1 root root 11 Oct  9 15:55 S99local -> ../rc.local
end example

A run level identifies what processes should be started or stopped while booting the system and also determines how the user can interact with the system. For example, run level 1 indicates single-user mode, run level 3 indicates multiuser mode without graphical desktop, run level 5 indicates multiuser mode with graphical desktop, and so on. The /etc/inittab file is used to describe how the system should be set up in different run levels, and it also contains a line describing the default run level. The current and previous releases (9.0 and 8.0) of Red Hat Linux are set to the default run level of 5, while some of the older releases are set to boot to run level 3. By setting the default run level to 5, the current release enables the graphical desktop to be displayed for user login after the system is booted. (Even in the older releases where the text mode terminals were displayed, the graphical desktop could be used by manually starting the X-server and the desktop program.)

In Red Hat Linux, the init program first runs the /etc/rc.d/rc.sysinit script as the first startup script and begins the initiation process. The main purpose of this script is to set the environment path, checking whether the system was properly shut down in the previous session (and hence checking file system integrity), loading the default keyboard, and initializing the system clock and so on. The next step performed by the init program is to start/stop the processes based on the settings in the /etc/inittab file. Based on the run level the system is booting at a particular time, the init program starts the processes defined for that run level (and kills the processes that should not run in that run level). The /etc/rc.d/rc script is generic and is used to start processes in any run level. The script takes a parameter that identifies the run level. Finally, the init program executes the rc.local script, thus permitting your own customized initiation tasks tailored for your system.

SuSE Linux Init Process

As mentioned earlier, conceptually the init program performs the same job without regard to the specific distribution of Linux. There may be minor differences in the directory structures and the contents across the different distributions. For example, in SuSE Linux 8.1 and 8.2, the set of rcN (N ranging from 0 through 6) directories are subdirectories within /etc/init.d directory. In fact the /etc/rc.d directory is a link to /etc/init.d directory. The /etc/inittab file and its configuration entries are very much similar to those in Red Hat Linux. The /etc/init.d/boot script is first executed by init, which in turn executes the /etc/init.d/boot.local script in order to provide an opportunity to the user-preferred tasks before entering a particular run level. Therefore, if you desire to run any specific scripts or services before entering a specific run level, you could define them in the boot.local script. By default, this script is created without any contents. Next, the /etc/init.d/boot script executes services as defined in the /etc/init.d/boot.d directory. After the successful execution of /etc/init.d/boot script, the init program executes the services defined for the particular run level, in a way very similar to Red Hat Linux.

As you have noticed here, each distribution has its own way of executing the system initiation processes, and the product manuals of the respective distributions should be consulted for more details. Also, a specific vendor usually tries to keep the system booting and process initiation uniform across successive releases, although at times some changes might be introduced in order to improve the overall process. Therefore, the process discussed in this section might also be applicable to the earlier releases of the respective vendors.



 < Day Day Up > 



Linux Application Development For The Enterprise
Linux Application Development For The Enterprise (Charles River Media Programming)
ISBN: 1584502533
EAN: 2147483647
Year: 2002
Pages: 86

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net