systemd vs sysvinit part 2

Tags: systemctl, linux, systemd
Publish Date: 2016-05-15

For a quick and dirty cheatsheet, see my other post

Differences between systemd and sysvinit (a.k.a init) - Part 2

In part 1 of this article, I have provided an overview of how sysvinit boots up and manages services. Here in part 2, I will show how this has changed with systemd.


Systemd - Boot Process

While in sysvinit there is a concept of runlevels, systemd is based on targets.

The idea behind a target is that a collection of units have to be activated when the system reaches a certain target. You can see the activation of units like dependencies for targets.

A target could be something like the old runlevels (e.g., but it could also be something like hardware or network detection (e.g. A unit could be something like a service, mount, socket etc., but a target itself is also a unit.

So you can interpret this as: "Make sure that certain services, mounts, sockets etc are activated when my system reaches a certain state."

For a list of units in systemd see systemctl -t help

[root@10 system]# systemctl -t help
Available unit types:

During the boot process, the first process (pid 1) is (/lib/systemd/)systemd. In fact, you will see that the old /sbin/init is a symlink to /lib/systemd/systemd

[root@10 system]# ls -l /sbin/ | grep systemd
lrwxrwxrwx. 1 root root       22 Jul 14  2015 init -> ../lib/systemd/systemd

Since systemd is no longer based on runlevels, it has gotten rid of the /etc/inittab file, where the default runlevel used to be defined. Instead, systemd finds its default target through /etc/systemd/system/

[root@10 system]# ls -l /etc/systemd/system
total 4
drwxr-xr-x. 2 root root   54 Jul 14  2015
lrwxrwxrwx. 1 root root   41 Jul 14  2015 dbus-org.fedoraproject.FirewallD1.service -> /usr/lib/systemd/system/firewalld.service
lrwxrwxrwx. 1 root root   46 Jul 14  2015 dbus-org.freedesktop.NetworkManager.service -> /usr/lib/systemd/system/NetworkManager.service
lrwxrwxrwx. 1 root root   57 Jul 14  2015 dbus-org.freedesktop.nm-dispatcher.service -> /usr/lib/systemd/system/NetworkManager-dispatcher.service
lrwxrwxrwx  1 root root   41 May 13 11:21 -> /usr/lib/systemd/system/
drwxr-xr-x. 2 root root   85 Jul 14  2015
drwxr-xr-x. 2 root root   31 Jul 14  2015
drwxr-xr-x. 2 root root 4096 Apr  6 09:45
drwxr-xr-x. 2 root root   49 Jul 14  2015
drwxr-xr-x. 2 root root   59 Jul 14  2015
drwxr-xr-x. 2 root root   43 Jul 14  2015

As you can see, my is symlinked to Which is a bit comparable to the old runlevel 3.

We can get and set the default runlevel with systemctl set-default and systemctl get-default

[root@10 system]# systemctl get-default
[root@10 system]# systemctl set-default
rm '/etc/systemd/system/'
ln -s '/usr/lib/systemd/system/' '/etc/systemd/system/'

For simplicity's sake, let's assume that I have set my default target back to If we take a look at the file, we will see the following:

[root@10 system]# cat /usr/lib/systemd/system/

Description=Multi-User System
Conflicts=rescue.service rescue.service

[Install] means that all units within the directories (more on the .wants directories later) must be activated first before the current unit ( can be activated. So for now, the control is handed over to, which in its turn requires

In, there is no Requires= directive specified, but it does have a Wants= directive.

The Wants= directive lists the units that the current unit will try to activate. However, if these units fail to be activated, it won't stop the current unit (in this case from being activated.

What systemd will do at this point, is to look for .wants directories under /etc/systemd/system/ and (/usr)/lib/systemd/system/ (more on their differences later) with the name of the the specified target. In this case, it finds /usr/lib/systemd/system/ and activates the units within that directory.

From that point, the control is passed back up the chain again. First back to and activates units within in both /etc/systemd/system and (/usr)/lib/systemd/system directories, then the same for and finally back to A great way to visualize how control has been passed from one target to another and which units have been activated in the process, is to use systemctl list-dependencies <>

It is important to note that services in systemd are activated in a parallel manner, whereas in sysvinit was done sequentially (by the number of K- and S- scripts in runlevel directories).

Another note of importance is that there is a difference between the .wants directories in /etc/systemd/system/ and (/usr)/lib/systemd/system/. While the .wants directories in the former is setup by the system and should never be touched by users, the .wants directories in the latter allow the user to manage his own dependencies. This becomes obvious when you enable / disable services to be run upon boot.

Systemd - Enable service at startup

When you install a service (such as nginx in this example), your package manager will create a .service file in the /usr/lib/systemd/system/ directory.

[root@10 vagrant]# ls /usr/lib/systemd/system | grep nginx

To make sure that a service is enabled upon boot, you can use the systemctl enable command:

[root@10 vagrant]# systemctl enable nginx
ln -s '/usr/lib/systemd/system/nginx.service' '/etc/systemd/system/'

What we can see above, is that the systemctl enable command actually creates a symlink from the .wants directory of our default target (in our case multi-user.wants) to /usr/lib/systemd/system/ for our service. In a way a bit comparable to how the scripts in runlevel directories (/etc/rc{number}.d/) in sysvinint were symlinked to scripts in /etc/init.d/.

You can also use systemctl disable <service> to disable a service. In that case, the previously created symlink will be removed.

Systemd - start / stop services

In sysvinit, there were different commands for managing services at startup (chkconfig) and for running/stopping services (service). In systemd, that is all controlled by the systemctl command.

To start a service, use systemctl start <service>

[root@10 vagrant]# systemctl start nginx
[root@10 vagrant]# systemctl status nginx
nginx.service - nginx - high performance web server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled)
   Active: active (running) since Sun 2016-05-15 14:35:07 UTC; 2s ago
  Process: 2735 ExecStop=/bin/kill -s QUIT $MAINPID (code=exited, status=0/SUCCESS)
  Process: 2744 ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
  Process: 2743 ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf (code=exited, status=0/SUCCESS)
 Main PID: 2747 (nginx)
   CGroup: /system.slice/nginx.service
           ├─2747 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
           └─2748 nginx: worker process

Systemd - Change targets

In sysvinit, a sys-admin might have to change runlevel to perform administrative tasks. In systemd, since there are no runlevels anymore, you will have to change target:

[root@10 system]# systemctl isolate
[root@10 system]# who -r
[root@10 system]# runlevel
3 1 # indicates that the current runlevel is 1 and previous runlevel is 3

Ironically enough, to get the current target, you would still use the old who -r and runlevel commands.

Quick and dirty systemvinit vs systemd vs upstart cheatsheet

Tags: linux, upstart, runlevel, systemctl, service, sysvinit, systemd
Publish Date: 2016-05-13

Quick and dirty cheatsheet





Start a service

service <name> start

systemctl start <name>

service <name> start

Stop a service

service <name> stop

systemctl stop <name>

service <name> stop

Enable service at startup

chkconfig <name> on


chkconfig <name> --level 2,3

systemctl enable <name>

update-rc.d <name> enable


update-rc.d <name> enable 2 3



Disable service at startup

chkconfig <name> off

systemctl disable <name>

update-rc.d <name> disable

Set default runlevel

Edit in /etc/inittab



systemctl set-default <>

Edit in /etc/init/rc-sysinit.conf



Get default runlevel

Read from /etc/inittab



systemctl get-default

Read from


Set current runlevel

init <number>

telinit <number>

systemctl isolate <>

init <number>

telinit <number>

Get current runlevel


who -r


who -r


who -r