12.2. 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 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 S05apmd, 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 DrakXServices and chkconfig; the former is a graphical program).


Tux on Star from MandrakeSoft Linux is a registered trademark of Linus Torvalds. All other trademarks and copyrights are the property of their respective owners.
Unless otherwise stated, all the content of these pages and all images are Copyright MandrakeSoft S.A. and MandrakeSoft Inc. 2000.
http://www.linux-mandrake.com/