39.1 Run Levels

The runlevel is an identifier for each of the different states in which the GNU/Linux operating system can be running, such as in single user mode, multi-user mode, and halt and reboot modes. Generally a GNU/Linux system is running in multi-user mode.

The first script run by init, after booting into GNU/Linux, is /etc/init.d/rcS. The initialisation files for the default run level (usually 2) are then run. This is specified in /etc/inittab with the line:

  l2:2:wait:/etc/init.d/rc 2

This runs /etc/init.d/rc with the parameter 2. The /etc/init.d/rc script in turn runs the scripts in /etc/rc2.d/ (since the parameter 2 indicates rc2 as opposed to rc3, etc).

The default runlevel is runlevel 2, unless you change it in /etc/inittab:

  # The default runlevel. 
  id:2:initdefault:

In general the runlevels 2, 3, 4, and 5 are all multi-user run levels and Debian sets them up to be the same.

  # Runlevel 0 is halt. 
  # Runlevel 1 is single-user. 
  # Runlevels 2-5 are multi-user. 
  # Runlevel 6 is reboot. 

  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

Thus, when the system enters a runlevel it executes the scripts in /etc/rc.n where n is the runlevel in question. These scripts are in fact symbolic links (symlinks) to scripts in /etc/init.d/. A script starting with S starts a service. One starting with K stops a service. The number after the S' orK’ specifies the order in which the scripts are run. For example, S25xdm will start before S35xdm.

To stop xdm, for example, from starting up by default on boot, simply remove the symbolic link of the corresponding S' script from/etc/rc?.d/S*xdm`.

See the man page for init for an extensive discussion.

The init script is run with “start” on changing runlevel (S) and runlevels 0 (the halt runlevel) and 6 (the reboot runlevel).

To remove something (e.g., gdm) from the init scripts:

  # update-rc.d -f gdm remove


Your donation will support ongoing availability and give you access to the PDF version of this book. Desktop Survival Guides include Data Science, GNU/Linux, and MLHub. Books available on Amazon include Data Mining with Rattle and Essentials of Data Science. Popular open source software includes rattle, wajig, and mlhub. Hosted by Togaware, a pioneer of free and open source software since 1984. Copyright © 1995-2022 Graham.Williams@togaware.com Creative Commons Attribution-ShareAlike 4.0