Skip to content
Search

Runlevel

lastmod 2023-02-20created 2018-08-177 edits

A runlevel is a mode of operation in the computer operating systems that implement Unix System V-style initialization. Conventionally, seven runlevels exist, numbered from zero to six; though up to ten, from zero to nine, may be used. S is sometimes used as a synonym for one of the levels. Only one runlevel is executed on startup; run levels are not executed one after another, i.e. either the runlevel 2, 3 or 4 is executed, not more of them sequentially or in any other order.

Levels

0 - halt (DO NOT set initdefault to this)
Means system shutdown. In other words, issuing a command to change to runlevel 0 shuts down the system.
1 - Single user mode
Also called system recovery mode; by default you get a shell with administrator privileges.
Mainly used to check the file system or change the administrator password.
2 - Multiuser mode, without NFS (The same as 3, if you do ot have networking)
Multi-user mode without NFS (Network File System) support.
You could call it a text user mode without networking.
3 - Full muliuser mode
Multi-user mode with an ordinary shell-based interface.
Simply put, it is a 'text user mode', not a graphical user mode.
4 - unused
Level 4 is not used. It is unused by default, but it is a level you can define and use as you like.
5 - X11
Basically the same as level 3. The difference is that it is a 'graphical user mode'!!!
6 - reboot (DO NOT set initdefault to this)
Means system reboot. Issuing a command to change to runlevel 6 reboots the system.

Run-Level

Description

init Run-Level

systemd Run-Level

0

Halt (shutdown mode)

runlevel0.target

poweroff.target

1

Single-user (single-user mode)

runlevel1.target

rescue.target

2

Multi-user (multi-user mode)

runlevel2.target

multi-user.target

3

Full Multi-user

runlevel3.target

4

unused

runlevel4.target

5

Graphic-user (graphical user mode)

runlevel5.target

graphical.target

6

Reboot (restart)

runlevel6.target

reboot.target

Run Command

Once the Init process decides the runlevel, it must run the services for that runlevel. The directory paths of the services to run for each runlevel are as follows.

  • Level S - /etc/rcS.d
  • Level 0 - /etc/rc0.d
  • Level 1 - /etc/rc1.d
  • Level 2 - /etc/rc2.d
  • Level 3 - /etc/rc3.d
  • Level 4 - /etc/rc4.d
  • Level 5 - /etc/rc5.d
  • Level 6 - /etc/rc6.d

Here rc is said to stand for Run Command.

Check run level in script

Unix System V-style implement conventionally 7 runlevels. This runlevel implementation vary across many Linux distribution. Usually runlevel 0, 1 and 6 are the same.

  • 0 - halt
  • 1 - single mode
  • 6 - reboot

Debian distribution has it runlevel 2-5 dedicated to full multi-user with graphical managers and console login whereas Redhat/Fedora has two separate runlevels for each mode. To check the runlevel of you system you can use runlevel command with no arguments:

$ runlevel

another way to check your runlevel is to use:

$ who -r

Bash script:

if [[ $(runlevel | awk '{print $2}') != 1 ]]; then
    echo 'The runlevel must be 1'
    echo ' sudo init 1'
    exit 1
fi

See also

Favorite site

author Zer0 sitemap