Generally, two things happen when you change runlevels. First, stop scripts of the current runlevel are launched, closing down some programs essential for the current runlevel. Then start scripts of the new runlevel are started. Here, in most cases, a number of programs are started. For example, the following occurs when changing from runlevel 3 to 5:
The administrator (root) tells init to change to a different runlevel by entering init 5.
init now consults its configuration file (/etc/inittab) and realizes it should start /etc/init.d/rc with the new runlevel as a parameter.
Now rc calls all the stop scripts of the current runlevel, but only for those where there is no start script in the selected new runlevel. In our example, these are all the scripts that reside in /etc/init.d/rc3.d (old runlevel was 3) and start with a K. The number following K guarantees a certain order to start, as there are some dependencies to consider.
Important | |
---|---|
The names of the stop scripts always begin with K for kill. Start scripts begin with S for start. |
The last things to start are the start scripts of the new runlevel. These are (in our example) in /etc/init.d/rc5.d and begin with an S. The same procedure regarding the order in which they are started is applied here.
When changing into the same runlevel as the current runlevel, init only checks /etc/inittab for changes and starts the appropriate steps (e.g., for starting a getty on another interface).