The system init files (or, "Where is the autoexec.bat file ?")

The system init files (or, "Where is the autoexec.bat file ?")

(this section is true only for systems with SysV init, as Debian GNU/Linux and RedHat Linux, not Slackware).

When the system boots, it reads some files to setup itself. After the kernel has booted, it starts a process called init, with PID 1. Init reads it's main configuration file called /etc/inittab to get the default runlevel, and a few other settings.

runlevels

A linux system has a few different runlevels, each configured for a specific task. A Debian system normally goes into runlevel 2 when it boots, starting up daemons and more to make the system accessible in different ways and by several users at once. If you start the system in runlevel 1, you'll get a singleuser system for maintainance. Setting the runlevel to 0 will do a system halt, and runlevel 6 will reboot the machine after taking down daemons, umounting file systems and other important things before a shutdown. The runlevels I give here as example are specific for a Debian system, a RedHat or Slackware of whatever distribution have different runlevels for the different modes of operation.

Runlevel specific files

For each of the runlevels, there are files that specify what to do when entering that runlevel. Or, to be more exact, the files are links to files in another directory, this way you won't have 6 copies of each file when the file is used in 6 runlevels.

The files have names that start with either S or K, then a number, and after that a descriptive word. The S or K stands for Start or Kill, the number stands for when the file is executed, and the rest of the filename is there for uniqeness and completeness. Take the following file list for example, it's from my /etc/rc2.d, ie files to execute for runlevel 2.

S10sysklogd     S20gpm          S20ssh          S30netstd_misc  S99xdm
S12kerneld      S20iplogger     S20timecount    S89atd          
S13dhcpc        S20lpd          S20xfs          S89cron         
S15netstd_init  S20ppp          S25netstd_nfs   S91apache       
S18netbase      S20sendmail     S26firewall     S99rmnologin    

The file S10syslogd will be executed first, and the file S99xdm will be executed as the last of the files for runlevel 2. This way you may decide when in the boot process something is done.

On a Debian system, the files are located in /etc/rc?.d, where the '?' stands for the runlevel. The symbolic links mostly points to files in the directory /etc/init.d. Those files are scripts that take start or stop as arguments, some of them have reload too. When init reads in the /etc/rc2.d and finds the S10syslogd, it will see that's a symbolic link to /etc/init.d/sysklogd and execute /etc/init.d/sysklogd with the argument start. After that it will do the same thing with S12kerneld and so on.. If the filename is K10sysklogd, it will execute /etc/init.d/sysklogd with argument stop instead. You get it ? Me to :) RedHat has it's files in /etc/rc.d/rc?.d and /etc/rc.d/init.d, AFAIK !