What steps are involved in Linux startup? This article details the roles of different runlevels during the boot process.
For advanced users coming from DOS/Win9x/NT platforms, Linux can seem like a strange beast. There’s no config.sys, no autoexec.bat, and it’s not immediately clear where to start with personalized machine configurations.
It’s worth noting that many people consider Linux a clone of Unix, but that characterization is unfair to Linux. Linux is more open than Unix and more powerful. We should call it GNU/Linux.
When Linux boots, it runs a program called init, which then launches subsequent tasks, including multi-user environments and networking.
So, what exactly is a runlevel? Simply put, a runlevel is the functional level at which the operating system is currently running. These levels range from 1 to 6 and have different functions. These levels are specified in the /etc/inittab file. This file is the primary file that the init program looks for, and the first services to run are those scripts located in the /etc/rc.d directory.
In most Linux distributions, the startup scripts reside in /etc/rc.d/init.d. These scripts are linked via the ln command to the /etc/rc.d/rcn.d directories. (Here, n represents runlevels 0-6).
For example, S10network under /etc/rc.d/rc2.d is linked to the network script in /etc/rc.d/init.d.
Therefore, we know that the files under rc2.d are related to runlevel 2.
The S at the beginning of a filename stands for Start, meaning to start the service, and the number following it, like 10, indicates the startup order. For instance, in the same directory, you might also see a file called S80postfix; 80 means its order comes after 10, because starting postfix without the network being up would be pointless.
Now, looking at /etc/rc.d/rc3.d, you can see the file S60nfslock, but this file does not exist under the /etc/rc.d/rc2.d directory. NFS uses this file, typically in multi-user environments, hence it’s placed in the rc3.d directory.
Additionally, in /etc/rc.d/rc2.d, you can also see files starting with K, for example
/etc/rc.d/rc2.d/K45named. The K stands for Kill.
The standard Linux runlevels are 3 or 5. If it’s 3, the system is in multi-user state. If it’s 5, it is running the X Window System. If you are currently at runlevel 3 or 5 and lower the runlevel to 2, init will execute the K45named script.
The definitions of different runlevels are as follows: (You can refer to /etc/inittab in Red Hat Linux)
# Default runlevel. The runlevels used by RHS are:
# 0 – halt (Do NOT set initdefault to this)
# 1 – Single user mode
# 2 – Multiuser, without NFS
# 3 – Full multiuser mode
# 4 – unused
# 5 – X11
# 6 – reboot (Do NOT set initdefault to this)
#
Detailed explanations for each runlevel:
0 is halt; the machine shuts down.
1 is single-user mode, similar to Safe Mode in Win9x.
2 is multi-user mode, but without NFS support.
3 is full multi-user mode, the standard runlevel.
4 is generally unused, but can