Kahibaro
Discord Login Register

Boot targets

Understanding systemd Boot Targets

Boot targets in systemd define what the system should look like after boot: which services are started, which are stopped, and which “mode” the machine is in (graphical, multi-user, rescue, etc.). They replace the old SysV “runlevels.”

This chapter focuses on:

You should already be familiar with basic systemctl usage from the parent chapter.


Common systemd Targets

Targets are unit files with the suffix .target. They group other units (mostly services) and may “pull in” each other.

Some of the most important system targets you will see on typical desktop/server distributions:

`rescue.target`

Use cases:

`multi-user.target`

Use cases:

`graphical.target`

Use cases:

`emergency.target`

Use cases:

Other notable targets

Depending on your distribution, you may also encounter:

Inspecting Boot Targets

You interact with targets using systemctl just like with services.

List all targets

systemctl list-units --type=target

To also see inactive targets:

systemctl list-unit-files --type=target

This shows available targets and whether they’re enabled (i.e., may be reached automatically during boot).

Show information about a specific target

Example for multi-user.target:

systemctl status multi-user.target

To see what the target pulls in:

systemctl show -p Wants,Requires multi-user.target

You may also view the unit file itself:

systemctl cat multi-user.target

This reveals:

Default Boot Target

The default boot target is what the system tries to reach during a normal boot. On many desktops this is graphical.target; on servers it’s often multi-user.target.

default.target is usually a symbolic link to the actual target:

ls -l /etc/systemd/system/default.target

Example output:

/etc/systemd/system/default.target -> /lib/systemd/system/graphical.target

Show the current default target

systemctl get-default

Example:

$ systemctl get-default
graphical.target

Change the default boot target

Use set-default to change what the system enters on next boot:

  sudo systemctl set-default multi-user.target
  sudo systemctl set-default graphical.target

This command changes the default.target symlink; it doesn’t immediately switch the current session (that’s covered next).


Switching Targets at Runtime

You can move between targets on a running system without rebooting, as long as your current state allows it.

Isolating a target

systemctl isolate starts the specified target and stops units that are not part of it.

Examples:

  sudo systemctl isolate multi-user.target

This will stop the display manager and graphical session.

  sudo systemctl isolate graphical.target

Considerations:

Temporarily entering rescue mode

To switch to rescue mode from a running system:

sudo systemctl rescue

This is effectively an alias for:

sudo systemctl isolate rescue.target

You’ll usually be asked for the root password (depending on distribution and configuration). Most services will stop, and you’ll get a root shell on the console.

To return to normal multi-user operation:

sudo systemctl isolate multi-user.target

Or, if you normally use the graphical interface:

sudo systemctl isolate graphical.target

Using Boot Targets from the Boot Loader

You can choose targets at boot time without changing the default target permanently. This is especially useful for troubleshooting.

The details depend on your bootloader (often GRUB2), but the general idea is:

  1. At the GRUB menu, highlight your normal boot entry.
  2. Edit the kernel command line (usually by pressing e).
  3. Find the line starting with linux (or linuxefi).
  4. Append one of the following options:
    • systemd.unit=rescue.target
    • systemd.unit=multi-user.target
    • systemd.unit=graphical.target
    • systemd.unit=emergency.target
  5. Boot with the modified line (usually Ctrl+x or F10).

Example kernel line snippet:

linux /boot/vmlinuz-... root=/dev/sda2 ro quiet splash systemd.unit=multi-user.target

This affects only the current boot; the default target set with systemctl set-default is unchanged.


Rescue and Emergency Targets in Practice

When systems fail to boot correctly, rescue and emergency targets are crucial tools.

`rescue.target` behavior

Characteristics:

Typical workflows:

Enter rescue mode from the running system:

sudo systemctl rescue

Or boot directly into it using the kernel parameter:

systemd.unit=rescue.target

`emergency.target` behavior

Characteristics:

You typically use it when:

From a running system:

sudo systemctl emergency

Or at boot with:

systemd.unit=emergency.target

You may need to remount the root filesystem read-write before editing files:

mount -o remount,rw /

Be extremely careful: in this state, there are almost no safety nets.


Custom and Specialized Targets

You can create your own targets to represent custom system states.

Creating a simple custom target

Example: maintenance.target which starts only a subset of services for administrative tasks.

  1. Create a unit file:
   sudo nano /etc/systemd/system/maintenance.target

With contents:

   [Unit]
   Description=Maintenance mode (no graphical login)
   [Install]
   WantedBy=multi-user.target
  1. Enable it (so it appears as a bootable option or dependency):
   sudo systemctl enable maintenance.target
  1. Decide which services maintenance.target should pull in by adding WantedBy=maintenance.target in the relevant .service units, or by creating drop-in config files.

Then you can:

  sudo systemctl isolate maintenance.target
  sudo systemctl set-default maintenance.target

Custom targets are useful when you want a repeatable “profile” of which services run (e.g. backup-only mode, lab mode, etc.).


Summary

Views: 28

Comments

Please login to add a comment.

Don't have an account? Register now!