Runlevels in Linux is a mode that defines the state of the machine after the boot process is complete. These states are represented by numbers and each number represents a different mode. It's a concept that originates from the System V Unix and is used to determine which services or processes should be running on the system. Understanding runlevels is crucial for server management, especially when configuring how your system behaves on startup.
Importance of Runlevels
Runlevels provide a straightforward way to control the behavior of a server based on its state. For example, you may want your server to boot directly into a networked state, or to boot into a single-user mode for system maintenance. Misconfiguring runlevels can lead to system boot failure or other unwanted behaviors, making it a critical aspect to grasp in Linux server management.
In Linux, there are 7 runlevels, ranging from 0 to 6, and each has a specific purpose:
- 0: Halt - Shuts down the system
- 1: Single-user mode - For administrative tasks
- 2: Multi-user mode without networking
- 3: Full multi-user mode with networking
- 4: Unused
- 5: Multi-user mode with GUI
- 6: Reboot - Reboots the system
Please note that the default runlevel for a Linux server is usually 3 (Multi-user mode with networking) or 5 (Multi-user mode with GUI), depending on the distribution.
Checking the Current Runlevel
To check the current runlevel, we use the
This command will output two characters. The first character is the previous runlevel and the second one is the current runlevel.
To change the runlevel while the system is running, we use the
init command followed by the
This command will switch the system to runlevel 1 (Single-user mode).
Setting Default Runlevel
The default runlevel is defined in the
/etc/inittab file. To change it, open the file with
a text editor, find a line that starts with
id:, and change the number to your desired runlevel:
In this example, the default runlevel is set to 3 (Multi-user mode with networking).
Understanding and managing runlevels is a fundamental skill in Linux server administration. It allows you to control the state of your machine and the services that run at boot time. Always ensure to configure the correct runlevel to avoid issues like system boot failure.