Amblem
Furkan Baytekin

Linux Session Targets and Run Levels: Systemd vs. System V

Master Linux run levels & systemd targets for better system administration

Linux Session Targets and Run Levels: Systemd vs. System V
63
3 minutes

Linux is widely appreciated for its robust and flexible architecture, with process and service management being core components. Two critical concepts in this domain are session targets in systemd and run levels in System V init. While they share similar goals, their implementations differ significantly. This blog post dives into these concepts, highlighting their roles, differences, and how they interact with Linux systems.


What Are Run Levels in System V Init?

In the traditional System V init system, run levels define the state of the machine, specifying which services and processes should be running. These run levels are numbered from 0 to 6:

You can check the current run level using the runlevel command, which outputs the previous and current levels (e.g., N 3). To change the run level, the init command is used (e.g., sudo init 5).


Systemd Session Targets

Systemd, the modern initialization system replacing System V init in most Linux distributions, introduces the concept of targets. Targets serve the same purpose as run levels: they define the state of the system. However, systemd’s design is more flexible and granular.

Common targets include:

Systemd also introduces special targets like default.target, which is a symlink to the default session target. You can view or set the default target using:

bash
systemctl get-default systemctl set-default graphical.target

To switch targets temporarily, use:

bash
sudo systemctl isolate multi-user.target

Differences Between Run Levels and Targets

  1. Flexibility:

    • Run levels are numeric and limited to predefined states.
    • Targets are named, descriptive, and allow custom states via additional targets.
  2. Dependencies:

    • Run levels have fixed service mappings.
    • Targets support dependency trees, enabling complex service relationships and fine-grained control.
  3. Parallelization:

    • Systemd targets enable parallel service startup, improving boot times.
    • System V init services start sequentially, making it slower.

Migrating from System V Init to Systemd

For users transitioning to systemd, the mapping between run levels and targets simplifies the process:

Run Level System V State systemd Target
0 Halt poweroff.target
1 Single-user mode rescue.target
2, 3 Multi-user mode multi-user.target
5 Graphical interface graphical.target
6 Reboot reboot.target

Systemd also offers legacy compatibility. Commands like runlevel and telinit still work under systemd, ensuring a smoother transition.


Conclusion

Whether you’re managing services with System V init or systemd, understanding run levels and targets is essential for Linux system administration. While System V init offers simplicity, systemd’s targets bring powerful features like parallel service startup, dependencies, and customization, making it the preferred choice for modern Linux systems. Knowing these fundamentals will help you optimize and troubleshoot your system with confidence.

Suggested Blog Posts