Hardware Reference
In-Depth Information
Step 6: runlevel
The last step of the initialization involves changing from the non-run-level
N
to the run
level
2
, which was declared by the
initdefault
entry. The Raspbian
inittab
declares
that the
/etc/init.d/rc
script is run with a run-level argument for each of these run-
level changes:
l0:0:wait:/etc/init.d/rc 0
l1:1:wait:/etc/init.d/rc 1
l2:2:wait:/etc/init.d/rc 2
l3:3:wait:/etc/init.d/rc 3
l4:4:wait:/etc/init.d/rc 4
l5:5:wait:/etc/init.d/rc 5
l6:6:wait:/etc/init.d/rc 6
The first part of starting a new run level is to run the stop (kill) scripts at the
new
run
level, provided that there was a previous run level. At boot time, there is no current level
(it is
N
). So at startup, these scripts are ignored.
If, however, the system had been in single-user mode (for example) and the system
was changed to run level
2
, these kill scripts would be invoked:
$ ls −lL /etc/rc2.d/K
∗
−rwxr−xr−x 1 root root 2610 Jul 25 2011 /etc/rc2.d/K01lightdm
−rwxr−xr−x 1 root root 6491 Jul 21 2012 /etc/rc2.d/K05nfs−common
−rwxr−xr−x 1 root root 2344 Jun 15 2012 /etc/rc2.d/K05rpcbind
The script
/etc/init.d/rc
first iterates through these kill scripts (in sort order).
When the current level has a stop (kill) script, the following logic applies:
1.
If the previous run level
did
have a matching stop (kill)
script, and
2.
If the previous level
didn't
have a start script,
3.
Then there is no need to execute the stop (kill) script.
Otherwise, the corresponding kill script is necessary and is performed.
At startup, or after a run-level change, the startup scripts for the new run level (
2
in
this example) are performed. When the current level has a start script, then the following
logic applies:
1.
If the previous run level
also
has a matching start script, and
2.
The current level
doesn't
have a stop (kill) script,
3.
Then there is no need to stop and restart the script
.
Otherwise, the start script is invoked.