Development

Linux Init Levels Explained

Captain Salem 2 min read

Linux Init Levels Explained

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.

This tutorial provides an overview of these init levels, their purposes, and how to interact with them.

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:

Runlevel Purpose
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 runlevel command:

runlevel

The output will show the previous and current runlevel.

Changing Runlevels

To change the runlevel, you use the init command followed by the desired runlevel. For example, to switch to single-user mode:

init 1

To shut down the system:

init 0

And to reboot:

init 6

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 /etc/rc3.d/.

Changing the Default Runlevel

The default runlevel is specified in the /etc/inittab file with an entry like:

id:5:initdefault:

In this example, the default runlevel is set to 5. To change it, edit the inittab file with your preferred editor (like nano or vim) and modify the number to the desired default runlevel.

Systemd

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 → poweroff.target
  • Runlevel 1 → rescue.target
  • Runlevel 3 → multi-user.target
  • Runlevel 5 → graphical.target
  • Runlevel 6 → reboot.target

You can switch between these targets using the systemctl command. For example:

systemctl isolate multi-user.target

Conclusion

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.

Share
Comments
More from Cloudenv

Cloudenv

Developer Tips, Tricks and Tutorials.

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to Cloudenv.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.