When the system boots up, it queries for the default runlevel, which is defined in the /etc/inittab file. When that default runlevel is located, the system boots into that particular runlevel. The different runlevels are essentially “states,” which allow services to be started or stopped depending on the runlevel you are in.
There are six runlevels in total, which are shown in the /etc/inittab file. Each runlevel also has a directory called /etc/rc.d/rc#.d, where # is the runlevel (from 0 to 6). These different directories contain scripts to tell the system which services should be started or stopped at the particular runlevel. Let’s look at the different runlevels (/ect/inittab):
If you want to change default runlevel, just edit the /etc/inittab file. For instance, id:5:initdefault: - default runlevel is changed to 5. Besides, to change runlevel instantly, you can use init command.
# runlevel -- Show your current runlevel
# init 6 -- You just reboot your machine!
The best way to get a feel for what is started in each of these runlevels is to look in the /etc/rc.d/rc#.d directory for each runlevel. These directories contain files that define whichservices should be started or stopped. These files are actually soft links to the service init scripts on the system.
Runlevel Utilities
Let’s now look at the many system utilities that help you manage the system in different runlevels. These management commands include the following:
shutdown Brings the system to a powered-off state or can reboot the system
halt Powers down the system
reboot Reboots the system
poweroff Works the same as the halt command
chkconfig Manages what runlevels services start and stop at
runlevel Displays the current and previous runlevels
init Changes runlevels
ntsysv Menu-driven service management utility
Let’s look at some examples for a better understanding of how this works. Suppose you just want to turn off the system. You could then do the following:
# shutdown -h now
This time instead of a complete power off, reboot the system as follows:
# shutdown -r now
You could also use the reboot command to achieve the same effect:
# reboot
As a final example, delay the shutdown by 2 minutes:
# shutdown -h 120
Have fun!