When any Linux system boots, init is the first process to kick in which is responsible for running other processes/start scripts. These processes then take care of initialization of the hardware, networking etc.
Init process looks for the default run level in the /etc/inittab file and start scripts corresponding to the default run level.
0 – System halt state
1 – Single user text mode
2 – Multiple users, no NFS (network filesystem)
3 – Multiple users, command line (i.e., all-text mode) interface; the standard runlevel for most Linux-based server hardware.
4 – User-definable, not used much
5 – Multiple users, GUI (graphical user interface); the standard runlevel for most Linux-based desktop systems.
6 – Reboot; used when restarting the system.
Content of /etc/inittab file will look like below :
# cat /etc/inittab
# inittab is only used by upstart for the default runlevel.
#
# ADDING OTHER CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR SYSTEM.
#
# System initialization is started by /etc/init/rcS.conf
#
# Individual runlevels are started by /etc/init/rc.conf
#
# Ctrl-Alt-Delete is handled by /etc/init/control-alt-delete.conf
#
# Terminal gettys are handled by /etc/init/tty.conf and /etc/init/serial.conf,
# with configuration in /etc/sysconfig/init.
#
# For information on how to write upstart event handlers, or how
# upstart works, see init(5), init(8), and initctl(8).
#
# Default runlevel. The runlevels used are:
# 0 – halt (Do NOT set initdefault to this)
# 1 – Single user mode
# 2 – Multiuser, without NFS (The same as 3, if you do not have networking)
# 3 – Full multiuser mode
# 4 – unused
# 5 – X11
# 6 – reboot (Do NOT set initdefault to this)
#
id:3:initdefault:
Here last line “id:3:initdefault:” shows that the default/current run level is 3 i.e. Multiuser mode
Startup scripts are defined under /etc/rc.d directory. Each Run-level has it’s own startup script :-
root [ /etc/rc.d ]# ls -l
drwxr-xr-x 2 root root 4096 Apr 16 12:51 init.d
drwxr-xr-x 2 root root 4096 Mar 29 2018 rc0.d ========= Run level 0
drwxr-xr-x 2 root root 4096 Mar 29 2018 rc1.d ========= Run level 1
drwxr-xr-x 2 root root 4096 Jun 5 00:19 rc2.d ========= Run level 2
drwxr-xr-x 2 root root 4096 Jun 5 00:19 rc3.d ========= Run level 3
drwxr-xr-x 2 root root 4096 Jun 5 00:19 rc4.d ========= Run level 4
drwxr-xr-x 2 root root 4096 Jun 5 00:19 rc5.d ========= Run level 5
drwxr-xr-x 2 root root 4096 Mar 29 2018 rc6.d ========= Run level 6
To find the current run-level use below command :
# echo $RUNLEVEL
Linux systems that are using Systemd as default service manager, you can find the current run-level/target by below command :
# systemctl get-default
multi-user.target