Linux-Mandrake:
User Guide and
Reference Manual

MandrakeSoft

 
 
January 2000
http://www.linux-mandrake.com


Next : Filesystems and mount points
Previous : Auto Install
Up

(Back to the table of contents)

Chapter 9 : The startup files: init "System V"


In the Unix tradition, there are two system startup schemes: the BSD scheme and the "System V" scheme, both named after the Unix system which implemented them first (resp. Berkeley Software Distribution and AT&T Unix System V). The BSD scheme is the simplest, but the System V scheme, although less easy to understand (which is what this chapter is for), is markedly more flexible to use.

In the beginning was init

When the system starts, after the kernel has configured everything and mounted the root filesystem, it starts the /sbin/init program[18]. init is the father of all processes of the system, and it is responsible for taking the system to the desired runlevel. We will look at runlevels in the next section.

The init configuration file is /etc/inittab. This file has its own manual page (man inittab), but here we will describe only a few of the instructions.

The first line which should focus the attention is this one:

si::sysinit:/etc/rc.d/rc.sysinit

This instruction tells init that /etc/rc.d/rc.sysinit is to be run on initialisation of the system before anything else. To determine the default runlevel, init then looks for the line containing the initdefault keyword:

id:5:initdefault:

In this case, therefore, init knows that the default runlevel is 5. It also knows that to enter level 5, it must run the following command:

l5:5:wait:/etc/rc.d/rc 5

As you can see, the syntax for each runlevel is similar.

init is also responsible for restarting (respawn) certain programs which only it is capable of restarting. This is the case, for example, for all login programs which run in each of the 6 virtual terminals[19]. For the second virtual console, this gives:

2:2345:respawn:/sbin/mingetty tty2

Runlevels

All the files relating to system startup are located in the /etc/rc.d directory. Here is the list of the files:

$ ls /etc/rc.d
init.d/  rc.local*    rc0.d/  rc2.d/  rc4.d/  rc6.d/
rc*      rc.sysinit*  rc1.d/  rc3.d/  rc5.d/

To begin with, as we have seen, the rc.sysinit file is run. This is the file responsible for setting up the basic machine configuration: keyboard type, configuration of certain devices, filesystem checking, etc.

Then the rc script is run, with runlevel as its argument. As we have seen, the runlevel is a simple integer, and for each runlevel <x> defined, there must be a corresponding rc<x>.d directory. In a typical Linux-Mandrake installation, you might therefore see that 6 runlevels are defined:

Let us look, for example, at the contents of directory rc5.d:

$ ls rc5.d
K15postgresql@  K60atd@      S15netfs@   S60lpd@        S90xfs@
K20nfs@         K96pcmcia@   S20random@  S60nfs@        S99linuxconf@
K20rstatd@      S05apmd@     S30syslog@  S66yppasswdd@  S99local@
K20rusersd@     S10network@  S40crond@   S75keytable@
K20rwhod@       S11portmap@  S50inet@    S85gpm@
K30sendmail@    S12ypserv@   S55named@   S85httpd@
K35smb@         S13ypbind@   S55routed@  S85sound@

As you can see, all the files in this directory are symbolic links and and they all have a very specific form. Their general form is <S|K><order><service_name>. The S means Start service, and K means Kill, stop service. The scripts are run in ascending number order, and if two scripts have the same number, alphabetical order applies. We can also see that each symbolic link points to scripts located in /etc/rc.d/init.d (apart from local), scripts which are responsible for controlling a specific service.

When the system goes into a given runlevel, it starts by running the K links in order: rc looks where the link is pointing, then calls up the corresponding script with the single argument stop. Then it runs the S scripts, still using the same method, apart from the fact that the script is called with the argument start.

Thus, without mentioning all the scripts, we can see that when the system goes into runlevel 5, it first runs K15postgresql, i.e. /etc/rc.d/init.d/postgresql stop. Then K20nfs, then K20rstatd, until the last one; next, it runs all the S scripts: first S05ampd, which then calls /etc/rc.d/init.d/apmd start, and so on.

Armed with all this, you can create your own entire runlevel in a few minutes, or prevent a service starting or stopping by deleting the corresponding symbolic link (there are also interface programs for doing this, notably tksysv and chkconfig. The former is a graphical program).


Next : Filesystems and mount points
Previous : Auto Install
Up

Copyright � 2000 MandrakeSoft