Table of Contents#
- Understanding systemd Targets
- What Are Targets?
- Targets vs. Runlevels (RHEL6 Comparison)
- Targets vs. Services
- Common systemd Targets in RHEL7
- Essential systemd Target Commands
- View Current Target
- List All Targets
- Set Default Target
- Switch Targets Temporarily
- Check Target Dependencies
- View Target Unit Files
- Practical Example: Switch to Multi-User (CLI) Mode
- Troubleshooting Common Target Issues
- Conclusion
- References
1. Understanding systemd Targets#
What Are Targets?#
In systemd, a target is a unit file (.target) that defines a system state by grouping other units (services, sockets, mount points, etc.). Think of targets as “system profiles”—they determine which services start when the system boots or switches states.
For example:
graphical.targetstarts all services needed for a graphical desktop (e.g.,gdm.service,network.service).multi-user.targetstarts services for a text-only (CLI) environment (no GUI, but includes SSH, networking, etc.).
Targets vs. Runlevels (RHEL6 Comparison)#
If you’re familiar with RHEL6 or earlier, you might remember runlevels (e.g., runlevel 3 for CLI, runlevel 5 for GUI). Targets replace runlevels in systemd, but they’re more flexible:
- Runlevels were numbered (0-6) and rigidly defined.
- Targets have human-readable names (e.g.,
multi-user.target) and can be customized or extended.
Here’s how RHEL6 runlevels map to RHEL7 targets:
| RHEL6 Runlevel | Purpose | RHEL7 Equivalent Target |
|---|---|---|
| 0 | Halt the system | poweroff.target |
| 1 | Single-user mode | rescue.target |
| 2 | Multi-user (no network) | multi-user.target (custom) |
| 3 | Multi-user (CLI, network) | multi-user.target |
| 4 | Unused | N/A (custom targets possible) |
| 5 | Graphical (GUI) mode | graphical.target |
| 6 | Reboot | reboot.target |
Targets vs. Services#
Targets are not services—they are groups of services. For example:
sshd.serviceis a service that starts the SSH daemon.multi-user.targetincludessshd.service(along withnetwork.service,crond.service, etc.) to define a CLI environment.
2. Common systemd Targets in RHEL7#
Here are the most frequently used targets in RHEL7, with their purposes and runlevel equivalents:
| Target Name | Description | Equivalent Runlevel | Use Case |
|---|---|---|---|
multi-user.target | Default CLI mode: starts network, SSH, cron, and other non-GUI services. | Runlevel 3 | Server environments (no GUI needed). |
graphical.target | GUI mode: includes multi-user.target + graphical services (e.g., gdm). | Runlevel 5 | Desktop/laptop with a GUI. |
rescue.target | Single-user rescue mode: minimal system with root shell (no networking). | Runlevel 1 | Troubleshooting (e.g., password recovery). |
emergency.target | Minimal emergency mode: only root shell (no services/mounts). | N/A | Critical system failures (e.g., broken fstab). |
poweroff.target | Shuts down the system. | Runlevel 0 | Graceful shutdown. |
reboot.target | Reboots the system. | Runlevel 6 | Restart the system. |
default.target | Symlink to the system’s default boot target (e.g., multi-user or graphical). | N/A | Defines the default boot state. |
3. Essential systemd Target Commands#
All systemd target management is done with the systemctl command. Below are key commands to view, configure, and switch targets.
View Current Target#
To check which target the system is currently running:
systemctl get-default Example Output:
multi-user.target # System boots to CLI by default
List All Targets#
To list all targets (active and inactive), use:
systemctl list-targets Example Output (truncated):
UNIT LOAD ACTIVE SUB DESCRIPTION
basic.target loaded active active Basic System
cryptsetup.target loaded active active Local Encrypted Volumes
getty.target loaded active active Login Prompts
graphical.target loaded active active Graphical Interface # Active if GUI is running
multi-user.target loaded active active Multi-User System
network.target loaded active active Network
...
Set Default Target#
The default target determines the system’s state at boot. To set a new default (persistent across reboots):
sudo systemctl set-default <target-name> Examples:
- Set default to CLI (multi-user):
sudo systemctl set-default multi-user.target - Set default to GUI (graphical):
sudo systemctl set-default graphical.target
Switch Targets Temporarily#
To switch to a target immediately (without rebooting), use isolate (temporarily activates the target and stops conflicting units):
sudo systemctl isolate <target-name> Examples:
- Switch to GUI mode temporarily:
sudo systemctl isolate graphical.target - Switch to rescue mode (single-user):
sudo systemctl isolate rescue.target
Check Target Dependencies#
To see which services/targets a target depends on (e.g., what graphical.target includes):
systemctl list-dependencies <target-name> Example:
systemctl list-dependencies graphical.target Output (truncated):
graphical.target
├─accounts-daemon.service
├─gdm.service # Gnome Display Manager (GUI)
├─rtkit-daemon.service
├─systemd-update-utmp-runlevel.service
└─multi-user.target # Includes all services from multi-user
├─auditd.service
├─crond.service
├─network.service
└─sshd.service # SSH daemon
View Target Unit File#
To inspect the raw configuration of a target (e.g., multi-user.target):
systemctl cat <target-name> Example:
systemctl cat multi-user.target Output:
# /usr/lib/systemd/system/multi-user.target
[Unit]
Description=Multi-User System
Documentation=man:systemd.special(7)
Requires=basic.target
Conflicts=rescue.service rescue.target
After=basic.target rescue.service rescue.target
AllowIsolate=yes
4. Practical Example: Switch to Multi-User (CLI) Mode#
Let’s walk through a common scenario: A RHEL7 desktop is booting to GUI (graphical.target), but you want to switch to CLI (multi-user.target) as the default.
Step 1: Check Current Default Target#
systemctl get-default Output:
graphical.target # Currently boots to GUI
Step 2: Switch Temporarily to CLI#
To test CLI mode without changing the default:
sudo systemctl isolate multi-user.target The GUI will close, and you’ll land at a text-based login prompt.
Step 3: Set CLI as Default (Persistent)#
To make CLI the default boot target:
sudo systemctl set-default multi-user.target Output:
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/multi-user.target.
Step 4: Verify the Change#
Reboot to confirm the system now boots to CLI:
sudo reboot After reboot, you’ll see a text-based login prompt (no GUI).
5. Troubleshooting Common Target Issues#
Default Target Not Persisting#
If set-default doesn’t save your default target, check the default.target symlink:
ls -l /etc/systemd/system/default.target Expected Output:
lrwxrwxrwx. 1 root root 37 Jun 10 14:22 /etc/systemd/system/default.target -> /usr/lib/systemd/system/multi-user.target
If the symlink is missing/corrupted, recreate it manually:
sudo ln -sf /usr/lib/systemd/system/multi-user.target /etc/systemd/system/default.target Target Fails to Activate#
If switching to a target (e.g., rescue.target) fails, check the system logs with journalctl:
journalctl -u <target-name> # e.g., journalctl -u rescue.target Look for errors like “Failed to start Rescue Mode” to diagnose issues (e.g., missing dependencies).
Stuck in Emergency Mode#
If the system boots to emergency.target, it’s likely due to critical errors (e.g., invalid /etc/fstab entries). To fix:
- Enter the root password when prompted.
- Run
journalctl -xeto check logs for failures. - Fix the issue (e.g., edit
/etc/fstabwithvi /etc/fstab). - Reboot:
systemctl reboot.
6. Conclusion#
systemd targets are the backbone of system state management in RHEL7. By mastering targets, you can control your system’s boot behavior, switch between CLI/GUI modes, and troubleshoot boot issues with confidence.
Start with the basics: Use systemctl get-default to check your current target, set-default to configure boot behavior, and isolate to switch states temporarily. Refer to the common targets table for quick reference, and don’t hesitate to inspect dependencies with list-dependencies.