Print current runlevel
Output previous and current runlevel
- Ubuntu default runlevel 2
- Oracle Linux 5 & 6 default runlevel 5 (X)
- Arch Linux default runlevel 3
SysV Style init (Debian, Ubuntu and Fedora/Red Hat, except Gentoo)
The /etc/init.d directory contains the scripts executed by init at boot time and when the init state (or "runlevel") is changed (see init(8)).
These scripts are referenced by symbolic links in the /etc/rcn.d directories. When changing runlevels, init looks in the directory /etc/rcn.d for the scripts it should execute, where n is the runlevel that is being changed to, or S for the boot-up scripts.
The names of the links all have the form Smmscript or Kmmscript where mm is a two-digit number and script is the name of the script (this should be the same as the name of the actual script in /etc/init.d).
When init changes runlevel first the targets of the links whose names start with a K are executed, each with the single argument stop, followed by the scripts prefixed with an S, each with the single argument start. (The links are those in the /etc/rcn.d directory corresponding to the new runlevel.) The K links are responsible for killing services and the S link for starting services upon entering the runlevel.
For example, if we are changing from runlevel 2 to runlevel 3, init will first execute all of the K prefixed scripts it finds in /etc/rc3.d, and then all of the S prefixed scripts in that directory. The links starting with K will cause the referred-to file to be executed with an argument of stop, and the S links with an argument of start.
The two-digit number mm is used to determine the order in which to run the scripts: low-numbered links have their scripts run first. For example, the K20 scripts will be executed before the K30 scripts. This is used when a certain service must be started before another. For example, the name server bind might need to be started before the news server inn so that inn can set up its access lists. In this case, the script that starts bind would have a lower number than the script that starts inn so that it runs first:
The two runlevels 0 (halt) and 6 (reboot) are slightly different. In these runlevels, the links with an S prefix are still called after those with a K prefix, but they too are called with the single argument stop.
Install and remove System-V style init script links
update-rc.d updates the System V style init script links /etc/rcrun?level.d/NNname whose target is the script /etc/init.d/name.
Debian based distribution (Ubuntu, Mint)
Run-level configuration for SysV like init script links
Arch Linux just look into /etc/rc.d and do the manual labor...
BSD Style init (Arch Linux and Slackware)
Everything is under /etc/rc.d KISS.
/etc/rc.local is in fact triggered by /etc/init.d/rc.local script, for more information, look into its contents.
rc.local is the local multi-user startup script. Empty by default, it is a good place to put any last-minute commands the system should run at the very end of the boot process. Most common system configuration tasks (like loading modules, changing the console font, or setting up devices) usually have a dedicated place where they belong. To avoid confusion, ensure that whatever one intends to add to rc.local is not already residing in /etc/profile.d, or any other existing configuration location instead.
When editing this file, keep in mind that it is run after the basic setup (modules/daemons), as the root user, and whether or not X starts. Here is an example which just un-mutes the ALSA sound settings:
Another common usage for rc.local is to apply various hacks when one cannot make the ordinary initialization work correctly.