Linux – Connection Between /etc/init.d and /etc/rcX.d Directories

init-scriptlinuxsysvinit

I am learning command line from a book called "Linux Command Line and Shell Scripting Bible, Second Edition." The book states this:

Some Linux implementations contain a table of processes to start
automatically on bootup. On Linux systems, this table is usually
located in the special file /etc/inittabs.

Other systems (such as the popular Ubuntu Linux distribution) utilize
the /etc/init.d folder, which contains scripts for starting and
stopping individual applications at boot time. The scripts are started
via entries under the /etc/rcX.d folders, where X is a run level.

Probably because I am new to linux, I did not understand what the second paragraph quoted meant. Can someone explain the same in a much plainer language?

Best Answer

Let's forget init.d or rcx.d and keep things very simple. Imagine you were programming a program whose sole responsibility is to run or kill other scripts one by one.

However your next problem is to make sure they run in order. How would you perform that?

And lets imagine this program looked inside a scripts folder for running the scripts. To order the priority of scripts you would name them in lets say numerical order. This order is what dictates the relation between init.d and rc

In other words init.d contains the scripts to run and the rcX.d contains their order to run.

The X value in rcX.d is the run level. This could be loosely translated to the OS current state.

If you dig inside the rcX.d scripts you will find this formatting:

Xxxabcd
  • X is replaced with K or S, which stands for whether the script should be killed or started in the current run level
  • xx is the order number
  • abcd is the script name (the name is irrelevant however where it points is the script this will run)