Hopefully, the way I describe the process will be clear enough for you to get a picture about runlevels.
Introduction
Runlevel is a mode of operation or level of run in a computer that uses Unix/Linux System V-style.
There 7 runlevels in Ubuntu, start from 0 to 6.
The following table summarizes it:
-
runlevel 0 = System Halt
-
runlevel 1 = Single User
-
runlevel 2 = Multi-user with GUI
-
runlevel 3 = Multi-user with GUI
-
runlevel 4 = Multi-user with GUI
-
runlevel 5 = runlevel 3 + X windows system
-
runlevel 6 = Reboot
Runlevel 1 is a single user mode. In this level, there are no daemons (services) are started. You can do rescue or trouble-shooting in this mode. Runlevel 0 for shutdown and runlevel 6 for reboot. The rest are used for running the system.
Like other Linux systems, run levels are defined by files in the file system.
All run level files are found in the /etc directory.
/etc/rc0.d/ runlevel 0
/etc/rc1.d/ runlevel 1
/etc/rc2.d/ runlevel 2
/etc/rc3.d/ runlevel 3
/etc/rc4.d/ runlevel 4
/etc/rc5.d/ runlevel 5
/etc/rc6.d/ runlevel 6
The contents of each directory determines what happens at that run level.
Check your current runlevel
taufanlubis@zyrex:~$ runlevel
N 2
taufanlubis@zyrex:~$
Ubuntu system come with id=2, which indicates that the default runlevel will be ’2′ when the multi-user state is entered, and the scripts in /etc/rc2.d/ will be run.
taufanlubis@zyrex:~$ who -r
run-level 2 2007-09-25 03:53 last=
taufanlubis@zyrex:~$
Note, taken from update-rc.d manual:
/etc/init.d/
The directory containing the actual init scripts.
/etc/rc?.d/
The directories containing the links used by init and managed by update-rc.d.
There is also another runlevel named runlevel ‘S’.
For more details, you can read the manual.
taufanlubis@zyrex:~$ man rcS
……..
……..
The configuration of rcS are placed in /etc/default/rcS or /usr/share/initscripts/default.rcS
To see the content just type:
taufanlubis@zyrex:/etc/init.d$ cat /usr/share/initscripts/default.rcS
#
# /etc/default/rcS
#
# Default settings for the scripts in /etc/rcS.d/
#
# For information about these variables see the rcS(5) manual page.
#
# This file belongs to the “initscripts” package.
TMPTIME=0
SULOGIN=no
DELAYLOGIN=no
UTC=yes
VERBOSE=no
FSCKFIX=no
Booting Process
Ubuntu boots up by executing the program init. The step of scripts to be executed are
-
/etc/init.d/rcS
-
/etc/rc.boot
-
all scripts in a directory specified by the default runlevel
-
/etc/rc0.d
-
/etc/rc1.d
-
/etc/rc2.d
-
/etc/rc3.d
-
/etc/rc4.d
-
/etc/rc5.d
-
/etc/rc6.d
Let’s check the content of /etc/init.d/rcS.
taufanlubis@zyrex:~$ cat /etc/init.d/rcS
#! /bin/sh
#
# rcS
#
# Call all S??* scripts in /etc/rcS.d/ in numerical/alphabetical order
#
exec /etc/init.d/rc S
taufanlubis@zyrex:/etc/init.d$
Mean that this script will run all of the scripts in /etc/rcS.d/.
Let’s check the content.
taufanlubis@zyrex:~$ ls -l /etc/rcS.d
total 4
-rw-r–r– 1 root root 785 2007-04-11 04:45 README
lrwxrwxrwx 1 root root 24 2007-07-31 11:15 S01mountkernfs.sh -> ../init.d/mountkernfs.sh
lrwxrwxrwx 1 root root 19 2007-07-31 11:15 S01readahead -> ../init.d/readahead
lrwxrwxrwx 1 root root 21 2007-07-31 11:15 S02hostname.sh -> ../init.d/hostname.sh
…..
…..
lrwxrwxrwx 1 root root 27 2007-07-31 11:15 S90console-screen.sh -> ../init.d/console-screen.sh
taufanlubis@zyrex:/etc/rcS.d$
How about rc1.d, rc2.d, rc3.d, rc4.d, rc5.d ando rc6.d?
taufanlubis@zyrex:~$ ls -l /etc/rc1.d
total 4
lrwxrwxrwx 1 root root 13 2007-07-31 11:15 K01gdm -> ../init.d/gdm
……
……
lrwxrwxrwx 1 root root 16 2007-07-31 11:15 S90single -> ../init.d/single
taufanlubis@zyrex:~$ ls -l /etc/rc2.d
total 4
-rw-r–r– 1 root root 556 2007-04-11 04:46 README
lrwxrwxrwx 1 root root 16 2007-08-07 12:29 S01lokkit -> ../init.d/lokkit
….
….
lrwxrwxrwx 1 root root 24 2007-07-31 11:15 S99stop-readahead -> ../init.d/stop-readahead
taufanlubis@zyrex:~$ ls -l /etc/rc3.d
total 4
-rw-r–r– 1 root root 556 2007-04-11 04:46 README
lrwxrwxrwx 1 root root 16 2007-08-07 12:29 S01lokkit -> ../init.d/lokkit
…..
…..
lrwxrwxrwx 1 root root 19 2007-07-31 11:15 S99rmnologin -> ../init.d/rmnologin
taufanlubis@zyrex:~$ ls -l /etc/rc4.d
total 4
-rw-r–r– 1 root root 556 2007-04-11 04:46 README
lrwxrwxrwx 1 root root 16 2007-08-07 12:29 S01lokkit -> ../init.d/lokkit
……
……
lrwxrwxrwx 1 root root 19 2007-07-31 11:15 S99rmnologin -> ../init.d/rmnologin
taufanlubis@zyrex:~$
taufanlubis@zyrex:~$ ls -l /etc/rc5.d
total 4
-rw-r–r– 1 root root 556 2007-04-11 04:46 README
lrwxrwxrwx 1 root root 16 2007-08-07 12:29 S01lokkit -> ../init.d/lokkit
…..
…..
lrwxrwxrwx 1 root root 19 2007-07-31 11:15 S99rmnologin -> ../init.d/rmnologin
taufanlubis@zyrex:~$ ls -l /etc/rc6.d
total 4
lrwxrwxrwx 1 root root 13 2007-07-31 11:15 K01gdm -> ../init.d/gdm
……
……
lrwxrwxrwx 1 root root 18 2007-07-31 11:15 S40umountfs -> ../init.d/umountfs
lrwxrwxrwx 1 root root 20 2007-07-31 11:15 S60umountroot -> ../init.d/umountroot
lrwxrwxrwx 1 root root 16 2007-07-31 11:15 S90reboot -> ../init.d/reboot
taufanlubis@zyrex:~$ ls -l /etc/init.d/
total 460
….
….
-rwxr-xr-x 1 root root 864 2007-04-14 02:51 stop-readahead
….
….
-rwxr-xr-x 1 root root 3477 2007-04-11 04:45 umountfs
-rwxr-xr-x 1 root root 1833 2007-04-11 04:45 umountnfs.sh
-rwxr-xr-x 1 root root 1105 2007-04-11 04:45 umountroot
….
….
Now you see that, actually, all the scripts above are just symbolic links back to to scripts in /etc/init.d/.
These scripts are used to perform initialization such as to check and to mount file systems, to load modules, to start network services, to set the clock and to perform other initialization.
Specifically, before entering any runlevel, all the scripts beginning with ‘K’ are run; these scripts kill services. Then all the scripts beginning with ‘S’ are run; these scripts start services.
The two-digit number following the ‘K’ or ‘S’ indicates the order in which the script is run. Lower numbered scripts are executed first.
The scripts in /etc/init.d/ can be either:
-
start
-
stop
-
reload
-
restart
-
force-reload
These scripts can be used even after a system has been booted, to control various processes.
Now, let’s try with restart with the networking.
taufanlubis@zyrex:~$ sudo /etc/init.d/networking restart
Password:
* Reconfiguring network interfaces… RTNETLINK answers: No such process
There is already a pid file /var/run/dhclient.eth0.pid with pid 5659
killed old client process, removed PID file
Internet Systems Consortium DHCP Client V3.0.4
Copyright 2004-2006 Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/sw/dhcp/
Listening on LPF/eth0/00:90:f5:36:9a:eb
Sending on LPF/eth0/00:90:f5:36:9a:eb
……
……
Argument ‘restart‘ at “taufanlubis@zyrex:~$ sudo /etc/init.d/networking restart” will send networking daemon a signal to reread its configuration file.





pass any arguments the app init to the script dependind on the folder there are???
I think that because all files in /etc/rc2.d/ and /etc/rc6.s/ are symbolic links to /etc/init.d. To the same file. Where is the diferent between executing the symlink in rc2 and rc6? I think in the arguments star for rc2 and stop for rc6