How to Change Systemd Boot Target on Linux

Many Linux distros, such as RHEL/CentOS 7, Fedora, Ubuntu 16, are now using systemd instead of init as the init system. It is common for Linux users to set Linux to boot to “GUI” or “Text” mode. The old way of changing ‘/etc/inittab’ for choosing Linux runlevels is not working for sytemd. This post will introduce the way for systemd systems to select the “runlevels”.

For systemd, the concept of runlevels is replaced by the term “targets”. For those that are familiar with the init runlevels, there is a “mapping” between the init runlevels and systemd targets:

   ┌─────────┬───────────────────┐
   │Runlevel │ Target            │
   ├─────────┼───────────────────┤
   │0        │ poweroff.target   │
   ├─────────┼───────────────────┤
   │1        │ rescue.target     │
   ├─────────┼───────────────────┤
   │2, 3, 4  │ multi-user.target │
   ├─────────┼───────────────────┤
   │5        │ graphical.target  │
   ├─────────┼───────────────────┤
   │6        │ reboot.target     │
   └─────────┴───────────────────┘

2 common targets are the most common ones:

  • multi-user.target: analogous to runlevel 3, Text mode
  • graphical.target: analogous to runlevel 5, GUI mode with X server

systemd-components

Change the “runlevels”/targets after booting

Even after the Linux system is booted to a target, you can change it to another target/runlevel. For example, to change Linux to “multi-user” target:

# systemctl isolate multi-user.target

The command used is isolate. It starts the unit specified on the command line and its dependencies and stop all others.

This is similar to changing the runlevel in a traditional init system using init 3.

Change the boot “runlevels”/targets

This changes the default boot target.

For example, to make “multi-user.target” the default “runlevel”, you can do:

# systemctl enable multi-user.target
# systemctl set-default multi-user.target

Next time you reboot, the default target booted to will be “multi-user”.

Bonus: the manual way

This is not suggested way for changing the boot target. The command using systemctl is the best way. Just for those who are curious.

The default target is controlled by /etc/systemd/system/default.target which is a symbolic to the real .target file.

To set a default target, change the symbolic to point to the target you want.

For example, to change the runlevel to ‘multi-user’ (3):

# rm -f /etc/systemd/system/default.target; 
# ln -s /lib/systemd/system/multi-user.target /etc/systemd/system/default.target

Eric Zhiqiang Ma

Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *