The following explanation is “borrowed” from tksysv (an inspiration for KSysV):
System V init is fast becoming the standard in the Linux® world to control the startup of software at boot time. This is because it is arguably easier to use and more powerful and flexible than the traditional BSD init.
I won't go into the history here (mainly because I don't know it :-).
The init binary is located in /sbin
and
not /etc
. This is important as one might
try and upgrade a machine to System V init without re-installing and
reformatting. The Linux® kernel looks in /etc
for its init first, so you must make sure and
delete your old init from there if any.
SysV init also differs from BSD init in that
the config files are in a subfolder of /etc
instead of residing directly in
/etc
. This folder is called
rc.d
. In there you will find
rc.sysinit
and the following folders:
init.d/
rc0.d/
rc1.d/
rc2.d/
rc3.d/
rc4.d/
rc5.d/
rc6.d
init.d
contains a bunch of
scripts. Basically, you need one script for each service you may need to
start at boot time or when entering another runlevel. Services include
things like networking, NFS, sendmail®, httpd,etc.
Services do not include things like setserial that
must only be run once and then exited. Things like that should go in
the file rc.local
.
rc.local
should be in /etc/rc.d
if you want one. Most systems
include one even though it doesn't do much. You can also include an
rc.serial
in /etc/rc.d
if you need to do serial port
specific things at boot time.
The chain of events is as follows:
The kernel looks in several places for init and runs the first one it finds.
init runs /etc/rc.d/rc.sysinit
.
rc.sysinit
does a bunch of necessary things and then runs
rc.serial
(if it exists)
init runs rc.local
init runs all the scripts for the default runlevel
The default runlevel is decided in
/etc/inittab
. You should have a line close to the
top like:
id:3:initdefault:
From this, you'd look in the second column and see that the default
runlevel is 3, as should be the case for most systems. If you want to
change it, you can edit /etc/inittab
by hand and
change the 3. Be very careful when you are messing with the inittab. If
you do mess up, you can get in to fix it by rebooting and doing:
LILO boot:
linux single
This should allow you to boot into single user mode so you can fix it.
Now, how does it run all the right scripts? If you do an
ls
on
-l
rc3.d
, you might see something
like:
lrwxrwxrwx 1 root root 13 13:11 S10network -> ../init.d/network lrwxrwxrwx 1 root root 16 13:11 S30syslog -> ../init.d/syslog lrwxrwxrwx 1 root root 14 13:32 S40cron -> ../init.d/cron lrwxrwxrwx 1 root root 14 13:11 S50inet -> ../init.d/inet lrwxrwxrwx 1 root root 13 13:11 S60nfs -> ../init.d/nfs lrwxrwxrwx 1 root root 15 13:11 S70nfsfs -> ../init.d/nfsfs lrwxrwxrwx 1 root root 18 13:11 S75keytable -> ../init.d/keytable lrwxrwxrwx 1 root root 23 13:11 S80sendmail -> ../init.d/sendmail.init lrwxrwxrwx 1 root root 18 13:11 S90lpd -> ../init.d/lpd.init lrwxrwxrwx 1 root root 11 13:11 S99local -> ../rc.local
What you'll notice is that there are no real files in the folder.
Everything there is a link to one of the scripts in the init.d
folder.
The links also have an S
and a number at the
beginning. The S
means to start this particular
script and a K
would mean to stop it. The number is
just there for ordering purposes. Init will start all the services based
on the order they appear. You can duplicate numbers, but it will only
confuse you somewhat. You just need to use a two digit number only,
along with an upper case S
or K
to
start or stop the services you need to.
How does it start and stop services? Simple. Each of the scripts is
written to accept an argument which can be start
and
stop
. You can execute those scripts by hand in fact
with a command like:
/etc/rc.d/init.d/httpd.init stop
To stop the httpd server. Init just reads the name and if it has a
K
, it calls the script with the stop
argument. If it has an S
it calls the script with a
start
argument.