Linux Runlevels explained
Category : Knowledge
A Linux runlevel dictates the state that the machine is currently operating, and what applications or services should be running at that time. The runlevel is specified as a number between 0 and 6 inclusive.
As your system starts up, it will move up through the runlevels until it reaches it’s desired state. Generally headless installs will be considered fully started at 2 or 3, and desktop GUIs usually at 4 or 5. The following details what each of the default runlevels represent. These are the standard definitions which may be slightly different depending on your Linux distribution.
- 0 – is described as Halt. your machine will halt when the runlevel is set to 0.
- 1 – is single-user Mode which is used for administrative tasks before the non-essential services are started.
- 2 – is the first multi-user mode runlevel and will start some non-essential services. This may, or may not contain networking depending on your Linux distribution.
- 3 – is a multi-user mode which headless servers usually run at. All essential and non-essential services such as Apache HTTP Server should be running.
- 4 – is a multi-user mode runlevel which is not used by the default operating system and can be used for user defined purposes.
- 5 – is when GUI desktops are loaded such as Gnome or KDE.
- 6 – is the reboot runlevel. the operating system will reboot when runlevel 6 is issued.
You can check your current runlevel with the runlevel command. the below example shows a runlevel of 2.
runlevel N 2
You can also change the current runlevel manually using the the init command. As an example, your machine will restart if you set the runlevel to 6. Use the following init command to set the runlevel to 6.
init 6
Each available runlevel has it’s own directory under /etc staring with rc. Inside the folder is a file, or symlink which controls the respective service. When you add a new service to your operating system startup you are simply adding the services control file to one or more of the runlevel folders.
/etc/rc0.d /etc/rc1.d /etc/rc2.d /etc/rc3.d /etc/rc4.d /etc/rc5.d
2 Comments
Ron
8-Aug-2015 at 7:07 amDoes single user mode imply one user irrespective of remote/direct?
muggle
8-Nov-2015 at 12:00 pmDoes this mean if you specify runlevel 6 for a script, then said script will run when the system begins to shut down?