How does runlevels and targets work internally in Linux?

In Linux, runlevels and targets are integral to the management of system startup and services. Runlevels are a traditional concept primarily used in SysVinit systems, while targets are a more modern approach utilized by systemd, which is now the default init system for many Linux distributions.

Runlevels

Runlevels in SysVinit define the state of the machine. Each runlevel corresponds to a different mode of operation, such as single-user mode (runlevel 1), multi-user mode with no networking (runlevel 2), or multi-user mode with networking (runlevel 5).

Targets

Targets are used in systemd to replace runlevels. Each target represents a group of services and their desired state. For instance, the 'graphical.target' serves a similar purpose to what runlevel 5 provided in traditional SysVinit systems.

Systemctl and Runlevels

With the transition to systemd, the command systemctl is used to manage targets. You can set the default target using:

sudo systemctl set-default graphical.target

Switching Targets

You can switch between targets dynamically using:

sudo systemctl isolate multi-user.target

This command will transition the system to the specified target immediately.


Linux runlevels targets systemd SysVinit systemctl services management