All files related to the 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/ |
As already stated, rc.sysinit is the first file run by the system. It is responsible for setting up the basic machine configuration: keyboard type, configuration of certain devices, file system checking, etc.
Then the rc script is run, with the desired runlevel as an 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 Mandrake Linux installation, you might therefore see that that there are six runlevels:
1: single-user mode. To be used in the event of major problems or system recovery.
2: multi-user mode, with no network.
5: like runlevel 3, but also launches the graphical login interface.
Let's take a look at the contents of the rc5.d directory:
$ 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 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 numerical order, and if two scripts have the same number, the ascending alphabetical order will apply. We can also see that each symbolic link points to a given script located in the /etc/rc.d/init.d directory (other than the local script which is responsible for controlling a specific service.)
When the system goes into a given runlevel, it starts by running the K links in order: the rc command looks at where the link is pointing, then calls up the corresponding script with a single argument: stop. It runs the S scripts using the same method, except that the scripts are called with a start parameter.
So, without dicussing all the scripts, we can see that when the system goes into runlevel 5, it first runs the K15postgresql command, (i.e. /etc/rc.d/init.d/postgresql stop). Then K20nfs, then K20rstatd, etc., until it has run the last command. Next, it runs all the S scripts: first S05apmd, which in turn calls /etc/rc.d/init.d/apmd start, and so on.
Armed with this information, you can create your own complete runlevel in a few minutes (using runlevel 4, for instance), or prevent a service from starting or stopping by deleting the corresponding symbolic link. You can also use a number of interface programs to do this, notably drakxservices (see DrakXServices: Configuring Start-Up Services in the Starter Guide) which uses a graphical program interface, or chkconfig for text-mode configuration.