What are targets in Systemd? How is it mapped to runlevels in System V?

We have talked about runlevels in Linux in our old articles and since runlevels were kind of concepts in init systems. We are going to revisit the concept of targets in systemd which are used in most of the Linux distribution. If you not read the runlevel article you can read it on below link.

What are targets?

Targets are actually the definition of the state that your system has to sync with or achieve.

Service and other unit files can be tied to a target and multiple targets can be active at the same time

What are targets in Systemd? How is it mapped to runlevels in System V?

How runlevels from System V map to targets in Systemd

Runlevels are mapped to target through runlevel target files present in /lib/systemd/system/. You can have a look at runlevel target using the below ls command.

ls /lib/systemd/system/run*.target

Let’s list down these files.

/lib/systemd/system/runlevel0.target
/lib/systemd/system/runlevel1.target
/lib/systemd/system/runlevel2.target
/lib/systemd/system/runlevel3.target
/lib/systemd/system/runlevel4.target
/lib/systemd/system/runlevel5.target
/lib/systemd/system/runlevel6.target

If you look into any of the runlevel. Let’s start with runlevel0.target The content of the file is something like this.


[Unit]
Description=Power-Off
Documentation=man:systemd.special(7)
DefaultDependencies=no
Requires=systemd-poweroff.service
After=systemd-poweroff.service
AllowIsolate=yes
JobTimeoutSec=30min
JobTimeoutAction=poweroff-force

[Install]
Alias=ctrl-alt-del.target

So this is actually shutdown the system as runlevel 0 used to do. So this is a direct mapping of runlevel0. You can also see the file for systemd power-off target also present. Let’s have a look at the content of that file.

[Unit]
Description=Power-Off
Documentation=man:systemd.special(7)
DefaultDependencies=no
Requires=systemd-poweroff.service
After=systemd-poweroff.service
AllowIsolate=yes
JobTimeoutSec=30min
JobTimeoutAction=poweroff-force

[Install]
Alias=ctrl-alt-del.target

If you can see this is exactly the same content as runlevel0.target. So runlevel0 is changed to poweroff.target. This is because the runlevel0.target is a link to poweroff.target.

Let’s look at the other mappings.

Runlevel 0 [runlevel0.target] –> poweroff.target
Runlevel 1 [runlevel1.target] –> rescue.target
Runlevel 2 [runlevel2.target] –> multi-user.target
Runlevel 3 [runlevel3.target] –> multi-user.target
Runlevel 4 [runlevel4.target] –> multi-user.target
Runlevel 5 [runlevel5.target] –> graphical.target
Runlevel 6 [runlevel6.target] –> reboot.target

You can trigger this runlevel using systemctl poweroff

With systemd you can have a custom target and can launch your system with that target.

We will write more on how you can create a custom target and then boot into that in the next articles. If you like the article please share and subscribe.


Gaurav Yadav

Gaurav is cloud infrastructure engineer and a full stack web developer and blogger. Sportsperson by heart and loves football. Scale is something he loves to work for and always keen to learn new tech. Experienced with CI/CD, distributed cloud infrastructure, build systems and lot of SRE Stuff.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.