	How to use the /etc/init.d scripts and configure run levels
	===========================================================


The actual init program is only half the story (if that). Most of the work
is performed by a set of scripts which are invoked by init at various times.
You can use these scripts to control exactly which services are currently
running on your system and to alter the configuration of the various run
levels. This document describes the scripts and how to make them work for
you. For details of init and inittab read the relevent manual pages :-).


Overview of the boot process
============================

When init first starts up it executes the /etc/bcheckrc script and waits
for it to complete. Bcheckrc is responsible for initialising any hardware
necessary and ensuring the system is in a useable state.

  The first thing that happens is that /etc/default/swap is searched for
entries which are in /dev. These swap devices (or files) are immediately
mkswap'ed and attached for use. If you are short on memory you *need*
to have a swap partition (or a swap file in /dev) and you *need* to get
it up as soon as possible.

  Once basic swap has been attached the system time and timezone are
initialised (if the clock program can be found). Check /etc/default/clock
for how to set things up to use either GMT CMOS time or local CMOS time.
Next the system hostname is set to the contents of /etc/default/hostname.

  If the file /fastboot does not exist (created by shutdown -f, fastboot
or fasthalt) the root filesystem is then checked. Note that this check
occurs before any syncs are done. Nothing should attempt to write to the
root filesystem before the check is done or alterations made by fsck may
be silently reversed!

  The final action of bcheckrc is to ask the kernel to signal init when
ctrl-alt-del is pressed. Init will sync and close down the system cleanly
before rebooting when signalled.

  Once bcheckrc has been executed init enters the default run level. If this
is not configured in an initdefault entry in inittab, init will come up
in single user mode which by default invokes /etc/sulogin. Sulogin is part
of the shadow password suite. You may or may not have it :-)

  When init first enters a multi-user state it runs the script /etc/brc
and waits for it to complete. Brc prepares the system for multi-user
use by cleaning temporary directories, removing uucp lock files etc.

  On entering a new run level init will execute the script /etc/rc, passing
it the new run level on the command line and wait for it to complete.
Rc is responsible for configuring the system services for that run level.
It looks in the directory /etc/rc?.d (where ? is the run level passed on
the command line) first for files whose name starts with Knn and then for
files whose name starts with Snn. In both cases nn are a pair of digits
which are used to determine the order in which the files are processed.
The Knn files are executed with an argument of 'stop' and are used to stop
services which are not required at the new run level. The Snn files are
executed with an argument of 'start' and are used to start services which
are required at the new run level.

  The Knn and Snn files in the rc?.d directories are all links to files
in /etc/init.d which are executable scripts which the super user may use
to start and stop services by hand. For instance the script /etc/init.d/tcp
may be used to stop TCP/IP services simply by executing /etc/init.d/tcp stop
from a shell.

  In order to add a new service a script should be added to the /etc/init.d
directory (using the existing scripts as models). It should then be linked
into the rc?.d directories as required to configure the service in each
run level. For instance to have the service started as the last step in
changing to run level 3 the init.d script would be linked to the file
/etc/rc3.d/S99service and to have it stopped as the first step in changing
to run level 2 the init.d script would be linked to the  file
/etc/rc2.d/K00service.
