How to Change runlevels/targets using systemd in Ubuntu

Ubuntu can be booted into one of several target levels. The default target to which the system is configured to boot will, in turn, dictate which systemd units are started. The targets that relate specifically to system startup and shutdown can be summarized as follows:

  • poweroff.target – This is the target in which the system shuts down. For obvious reasons it is unlikely you would want this as your default target.
  • rescue.target – Causes the system to start up in a single user mode under which only the root user can log in. In this mode the system does not start any networking, graphical user interface or multi-user services. This run level is ideal for system administrators to perform system maintenance or repair activities.
  • multi-user.target – Boots the system into a multi-user mode with text based console login capability.
  • graphical.target – Boots the system into a networked, multi-user state with X Window System capability. By default the graphical desktop environment will start at the end of the boot process. This is the most common run level for desktop or workstation use.
  • reboot.target – Reboots the system. Another target that, for obvious reasons, you are unlikely to want as your default.

Changing runlevels/targets

1. To set a default runlevel/target in systemd, use the following syntax:

# systemctl set-default [desired].target

2. If the server is in rescue mode or in a chrooted environment, the default target can be set with the following command syntax:

# ln -sf /lib/systemd/system/[desired].target /etc/systemd/system/default.target

3. To change runlevels on the fly:

# systemctl isolate [multi-user.target | graphical.target]
Related Post