10.5 Every distribution seems to have a different boot-up method. Tell me about Debian's.
Like all Unices, Debian boots up by executing the program init. The configuration file for init (which is /etc/inittab) specifies that the first script to be executed should be /etc/init.d/rcS. This script runs all of the scripts in /etc/rcS.d/ by sourcing or forking subprocess depending on their file extension to perform initialization such as to check and to mount file systems, to load modules, to start the network services, to set the clock, and to perform other initialization. Then, for compatibility, it runs the files (except those with a `.'in the filename) in /etc/rc.boot/ too. Any scripts in the latter directory are usually reserved for system administrator use, and using them in packages is deprecated.
After completing the boot process, init executes all start scripts in a directory specified by the default runlevel (this runlevel is given by the entry for id in /etc/inittab). Like most System V compatible Unices, Linux has 7 runlevels:
- 2 through 5 (various multi-user modes)
Debian systems come with id=2, which indicates that the default runlevel will be '2' when the multi-user state is entered, and the scripts in /etc/rc2.d/ will be run.
In fact, the scripts in any of the directories, /etc/rcN.d/ are just symbolic links back to scripts in /etc/init.d/. However, the names of the files in each of the /etc/rcN.d/ directories are selected to indicate the way the scripts in /etc/init.d/ will be run. Specifically, before entering any runlevel, all the scripts beginning with 'K' are run; these scripts kill services. Then all the scripts beginning with 'S' are run; these scripts start services. The two-digit number following the 'K' or 'S' indicates the order in which the script is run. Lower numbered scripts are executed first.
This approach works because the scripts in /etc/init.d/ all take an argument which can be either `start', `stop', `reload', `restart' or `force-reload' and will then do the task indicated by the argument. These scripts can be used even after a system has been booted, to control various processes.
For example, with the argument `reload' the command
/etc/init.d/sendmail reload
sends the sendmail daemon a signal to reread its configuration file.
10.6 It looks as if Debian does not use rc.local to customize the boot process; what facilities are provided?
Suppose a system needs to execute script foo on start-up, or on entry to a particular (System V) runlevel. Then the system administrator should:
- Enter the script foo into the directory /etc/init.d/.
- Run the Debian command update-rc.d with appropriate arguments, to set up links between the (command-line-specified) directories rc?.d and /etc/init.d/foo. Here, '?' is a number from 0 through 6 and corresponds to each of the System V runlevels[list:e921a61d98]
Reboot the system.[/list:u:e921a61d98]
The command update-rc.d will set up links between files in the directories rc?.d and the script in /etc/init.d/. Each link will begin with a 'S' or a 'K', followed by a number, followed by the name of the script. Scripts beginning with 'S' in /etc/rcN.d/ are executed when runlevel N is entered. Scripts beginning with a 'K' are executed when leaving runlevel N.
One might, for example, cause the script foo to execute at boot-up, by putting it in /etc/init.d/ and installing the links with update-rc.d foo defaults 19. The argument 'defaults' refers to the default runlevels, which are 2 through 5. The argument '19' ensures that foo is called before any scripts containing numbers 20 or larger.