In the world of Linux, the
init process serves as the progenitor of all other processes and is responsible for initializing the system once the kernel loads.
One key concept associated with the init process is the notion of
run levels or
init levels. These represent the system's various states, from a complete multi-user environment to a single-user mode to shutting down or rebooting.
The idea is to allow the system to run different services or processes based on its runlevel.
What are Init Levels?
Init levels, also known as
runlevels, are modes that define what processes and services should run on the system.
Historically, System V init was the traditional system initialization system that employed these runlevels.
However, in many modern Linux distributions,
systemd has replaced System V init, and as a result, the concept of runlevels is becoming a legacy. Still, understanding them can be essential, especially when dealing with older systems.
Here are the standard runlevels in System V init:
|0||Halt the system.|
|1||Single-user mode (useful for maintenance tasks).|
|2||Multi-user mode without networking.|
|3||Full multi-user mode with networking but without a GUI.|
|4||Undefined (can be customized).|
|5||Multi-user mode with networking and a GUI (typically used for desktop systems).|
|6||Reboot the system.|
Using Init Levels
Here's how you can interact with init levels:
Viewing the Current Runlevel
To check the current
runlevel, use the
The output will show the previous and current runlevel.
To change the runlevel, you use the
init command followed by the desired runlevel. For example, to switch to single-user mode:
To shut down the system:
And to reboot:
Configuring Services for Specific Runlevels
System V init uses symbolic links located in the
/etc/rcX.d/ directories (where
X is the runlevel) to start or stop services.
Services that should start in a particular runlevel have links that start with
S (for start), while those that should be stopped start with a
K (for kill).
For instance, to see what services start and stop in runlevel 3, you'd look in
Changing the Default Runlevel
The default runlevel is specified in the
/etc/inittab file with an entry like:
In this example, the default runlevel is set to 5. To change it, edit the
inittab file with your preferred editor (like
vim) and modify the number to the desired default runlevel.
As mentioned earlier, many modern distributions have moved to systemd, which replaces the traditional System V init system.
While systemd services and targets serve a similar purpose to services and runlevels in System V init, their implementation and management are different.
If you're on a systemd-based system, the equivalent of runlevels are known as "targets." For instance:
- Runlevel 0 →
- Runlevel 1 →
- Runlevel 3 →
- Runlevel 5 →
- Runlevel 6 →
You can switch between these targets using the
systemctl command. For example:
systemctl isolate multi-user.target
Understanding init levels can be helpful when managing Linux systems, especially older ones that still use System V init. However, as Linux evolves, new users are more likely to encounter systemd's targets.