🌐 🇵🇱 Polski · 🇬🇧 EN
At system startup, the system boots into a default runlevel defined in the # /etc/inittab file. Depending on the defined default level, the system decides which services should be started or stopped during boot. There are 6 runlevels, each of which also has its own # /etc/rc.d/rcX.d directory, where X represents the number of the given level (from 0 to 6). These directories contain scripts that specify which services should be started or stopped for that specific level.
Types of runlevels:
0 - Halted
1 - Single-User-Mode
2 - Multiuser with partial services
3 - Full multiuser mode with networking, text mode
4 - Unused
5 - Full multiuser mode in graphical mode
6 - Reboot
Modes 0 and 6 are the easiest to understand. These two levels are triggered by the same command from different inputs. In level 0, the system is powered off. In level 6, the system is rebooted. The first level allows entering single-user mode, used when there are environment issues or for configuring parameters; it is also useful for recovering a forgotten root password. In the case of levels 2, 3, and 5, various services are started. There is also the unused level 4. The best way to understand this topic is to get a feel for which services are started at a given level, which can be seen in the directory for that level: # /etc/rc.d/rcX.d. This directory contains files defining which services are started at which level. One should also not forget the existence of the # /etc/init/rc.conf file, which contains the names of all script sets.
rc.conf
# rc - System V runlevel compatibility
#
# This task runs the old sysv-rc runlevel scripts. It
# is usually started by the telinit compatibility wrapper.
start on runlevel [0123456]
stop on runlevel [!$RUNLEVEL]
task
export RUNLEVEL
console output
exec /etc/rc.d/rc $RUNLEVEL
Commands for managing system startup and shutdown:
- shutdown - Shut down or reboot the system
- halt - Completely shut down the system
- reboot - Reboot the system
- poweroff - Completely shut down the system, same as "halt"
- chkconfig - Manage which services are started at which level
- runlevel - Display the current runlevel
- init - Used to change the runlevel
- ntsysv - Works similarly to chkconfig, displaying a service menu for a given level
Let's start administration with the two simplest levels, 0 and 6. Managing these levels uses the "shutdown" command, which causes the environment to shut down or reboot. This command also has its own flags:
Syntax : # shutdown [options] time
Shutdown command options:
- -k - Shutdown warning (no actual shutdown)
- -h - Halt the system after shutdown
- -r - Reboot instead of shutting down
- -F - Force file system check before reboot
- -n - Kill all existing processes (not recommended)
- -t SECS - Shut down the system, specifying the time until shutdown in seconds
If there is a need to shut down or reboot the system immediately, there is an additional "now" argument that can be used with the "-h" and "-r" flags.
# shutdown -h now - Immediate system shutdown
# shutdown -r now - Immediate system reboot
# reboot - Identical effect to the previous one, i.e., system reboot
# shutdown -h 120 - System shutdown after 2 minutes
These are example commands for the root user to use with "shutdown," unless appropriate permissions are granted to a specific user. One should be careful when granting permissions for these commands to other users to ensure they do not reboot the system and cause downtime.
In older versions of RedHat, it is possible to control access to the "shutdown" command in the # /etc/shutdown.allow file. In the RHEL6 release with the new Upstart tool, this file does not exist.
The # halt command has a similar effect to the # shutdown command; it also shuts down the environment and can be used interchangeably. Halt has references to both shutting down and rebooting the system. This can be seen by listing the /sbin directory.
# cd /sbin
# ll | grep halt
-rwxr-xr-x 1 root root 16152 Jan 21 2009 halt
lrwxrwxrwx 1 root root 4 Jul 22 2010 poweroff -> halt
lrwxrwxrwx 1 root root 4 Jul 22 2010 reboot -> halt
The difference lies in using the appropriate flag.
To check which runlevel is currently in use, run the command: # runlevel or similar information can be seen by running the command # who -r.
If you want to change your current runlevel, run the command: # init N where N is the number of the appropriate level (from 0 to 6).
For better assimilation, it is worth switching between levels and checking which level you are currently in each time.
Repairing and recovering runlevels.
Sometimes, when something goes wrong with the system, the currently used runlevel may not start or function properly. In such a situation, to solve the problem, you can always try to use a lower runlevel. For example, if something is wrong in graphical mode (runlevel 5), you should look for a solution in text mode (runlevel 3), and if something is wrong there too, you can save the system by switching to level 1 (single-user-mode) using the # init command. If, despite this, we cannot use lower modes in a running system, we are left with rebooting the environment, entering GRUB, and entering level 1 (single-user-mode) from there. RHCSA exams may include tasks such as:
- Resetting and changing the "root" user password
- Adjusting system files or partitions that are normally locked while the system is in use
- Repairing the file system by replacing incorrect ones with those found on the RedHat system installation media.
After finishing the changes and repair work, you should reboot the environment, which should return to normal operation. If something is still wrong, you can always return to the repair runlevel and try again. If nothing yields results, you will have to reinstall the system.
Comments