Skip to Content

Understanding Targets in RHEL (Red Hat Enterprise Linux)

In Red Hat Enterprise Linux (RHEL), the concept of targets plays a pivotal role in system initialization and systemd, the default system and service manager.

A target in RHEL refers to a specific system state that determines which services, processes, and resources should be active or inactive during system boot-up or runtime.

Targets are part of systemd’s system management structure, where they define a goal or state for the system, essentially grouping units (services, sockets, mounts, etc.) that should be activated together to achieve that state.

This article delves into the concept of targets, their significance in RHEL, and how they are managed.

Get Your Free Linux training!

Join our free Linux training and discover the power of open-source technology. Enhance your skills and boost your career! Learn Linux for Free!

What is systemd?

Before we dive deeper into targets, it’s essential to understand the role of systemd in RHEL. Systemd is a system and service manager that is responsible for booting and managing the system’s services and resources. It replaced the older SysVinit system and provides a more efficient way to handle service startup, shutdown, and resource management.

Systemd works with units, which represent various system resources and services. A unit can be of various types, such as:

  • Service Units (*.service): Represent services or daemons.
  • Target Units (*.target): Define system states or stages in the boot process.
  • Mount Units (*.mount): Represent file system mounts.
  • Socket Units (*.socket): Handle inter-process communication.
  • Device Units (*.device): Represent devices on the system.

Among these, targets are used to group related units together and control the system’s runlevels, much like the traditional runlevels in older Linux systems.

What are Targets?

In systemd, a target is a special type of unit used to group other units together. The goal of a target is to represent a system state, and it controls which services, resources, and processes are active at any given time. Targets are similar to runlevels in older Linux distributions, but they are more flexible and allow finer control over the system’s state.

Targets can be thought of as milestones in the boot process, each corresponding to a different system state. A target typically includes various services that need to be started or stopped to achieve that particular state.

Key Types of Targets in RHEL

  1. default.target:
    • This is the default target that is used by the system when booting. It determines the “default” system state. In many systems, default.target is often a symlink to another target, such as graphical.target or multi-user.target.
    • You can change the default target using the systemctl set-default command.
  2. graphical.target:
    • This target is used when the system boots into a full graphical environment, typically with a graphical login manager (like GDM or SDDM) and other graphical services.
    • It is equivalent to the traditional runlevel 5 in older Linux systems.
    • This target is suitable for systems that require a GUI (Graphical User Interface) for user interaction.
  3. multi-user.target:
    • This target is similar to the traditional runlevel 3. It boots the system into a multi-user state, but without a graphical interface. It is intended for systems that run as servers or systems where a GUI is not needed.
    • This target starts networking, logging, and other essential services but does not launch a graphical user interface.
  4. rescue.target:
    • This is a minimal target that boots the system into a rescue mode or single-user mode, where only basic system services are running. It is used for system recovery or troubleshooting.
    • It typically only starts essential services, making it a useful environment for diagnosing problems without other distractions.
  5. emergency.target:
    • Even more minimal than rescue.target, this target provides a very limited environment with the root filesystem mounted in a read-only state.
    • It is typically used in cases where the system needs to be repaired from a very basic shell, with minimal services running.
  6. network.target:
    • This target is used for systems where networking services are critical. It indicates that network-related services should be started, but it does not imply that the system is fully multi-user or in a graphical environment.
  7. shutdown.target:
    • As the name implies, this target is used when the system is shutting down. It makes sure that all the services and resources are cleanly stopped before the system powers off or reboots.
  8. poweroff.target:
    • This target is triggered when the system is powered off, initiating the process of stopping all services and shutting down the system.
  9. halt.target:
    • Similar to poweroff.target, but instead of shutting down, it halts the system. It doesn’t perform a clean shutdown of services, and the system may require a manual power off afterward.
  10. reboot.target:
  • This target is used to reboot the system. It is triggered when you perform a reboot operation, ensuring that the system goes through the necessary steps to restart cleanly.

Managing Targets in RHEL

You can also check the current default target with:
systemctl get-default

Changing Targets

You can change the current target of a running system using the systemctl command. To switch to a specific target, use the following command:

sudo systemctl isolate <target_name>

For example, to switch to the multi-user target, you would run:

sudo systemctl isolate multi-user.target

This command will switch the system to the target specified by <target_name> and stop any services or units that are not needed for that target.

Setting the Default Target

You can specify the default target (the target the system boots into by default) using the systemctl set-default command. For instance, to set the default target to graphical mode, you would run:

sudo systemctl set-default graphical.target

To revert back to a multi-user state, you would execute:

sudo systemctl set-default multi-user.target

Listing Available Targets

You can list all available targets on your system with the following command:

systemctl list-units --type=target

This command will display a list of all currently available targets along with their statuses.

Target Dependencies

Targets in systemd have dependencies, meaning certain targets may require other targets to be active before they can be reached. For example, the graphical.target typically depends on multi-user.target because a system in multi-user mode must be running before switching to graphical mode.

You can view the dependencies of a specific target using the following command:

systemctl list-dependencies <target_name>

For example:

systemctl list-dependencies graphical.target

This will show all the units that must be active for the graphical.target to be reached.

Why Use Targets?

Targets offer several advantages over traditional runlevels in RHEL:

  1. Flexibility: Targets provide more granular control over the boot process and system state. You can tailor the system’s behavior by enabling or disabling specific targets based on the needs of the environment.
  2. Parallelization: Systemd and targets are designed to boot the system in parallel, leading to faster startup times compared to older init systems.
  3. Service Grouping: Targets group services and units together based on the system state, making it easier to manage multiple services that need to run together.
  4. Ease of Management: System administrators can change the target to control system behavior without needing to modify the system’s configuration files directly.

Conclusion

In Red Hat Enterprise Linux (RHEL), targets are a fundamental part of the systemd framework, providing a structured way to manage system states and service groups. Whether you’re running a server with minimal services or a desktop with a full graphical environment, targets help ensure that the right services are active at the right time. Understanding how to work with targets gives system administrators more power and flexibility in managing the system’s state, and makes troubleshooting, recovery, and customization much easier.