systemd – tutorial

The new init tool systemd is already several distributions as an alternative to Upstart or dusty Sysvinit at. Some Sysvinit- and Upstart distributions familiar commands and tricks to work through compatibility measures under systemd. To use the capabilities of systemd correctly, the administrator should know, however, also tools and parameters of systemd.

The most important tool to interact with systemd's command line program systemctl. For changes to the configuration or restarting of background services it requires root privileges; some diagnostic calls can also perform simple user. Who calls the program without any parameters, receives a list of “Units”, do the at startup used tasks. In addition to the integration and testing of volumes includes the start background services or setting up hardware.

In a default installation of Fedora 16 lists Systemctl hundred sixty active units in ten different varieties. Among the most important service units. They take care of background services, a Sysvinit distribution typically starts about init scripts. Mount- and automount Units bind a file systems. Socket-Units legen Sockets an; they start indirect dependencies one other Unit, is accessed when the socket. (A detailed explanation of the Unit concept, see the first part of the article.)

you can instruct Systemctl A parameter, list only units of a particular type, about all service units:

systemctl --type=service

Systemctl automatically directs its output further to less; Use the arrow keys can be not only high- and scroll down, but also to the right, because there sometimes hide further information.

The startup does Systemd with Units. The come in different varieties, the Systemctl can list separately. VergrößernIn the first column of output we find the unit name. The second column indicates, whether systemd could invite the Unit-Definition, the third, whether the unit is active. Inactive - installed, but not to start envisaged - Units are the program only with the switch -a out; The same applies to units, which was unable to load the init system about because of an error in the unit file.

Column four gives the current status. “exited” shows, that the process has completed without error. This is for example the case for services, the running in the background - for example in the service unit, the known Sysvinit file performs compatibility reasons /etc/rc.local at system startup. “running” stands for services, running in the background: cron, dbus, sshd, udev and other.

The fifth column is a description of Unit. If you with “LSB” or “SYSV” starts, Systemd generated the unit automatically, work off a traditional init script.

For services, which could not be started or have crashed later, is in the fourth column “failed” - Highlighted in red, provided that the console colored output controls. The status-Command of sytemctl is the time of the cancellation and the returned error code of the program, for example

systemctl status NetworkManager.service

The status command of Systemctl supplies cutoff time and error code crashed services. In a freshly installed Fedora 16 lists Systemctl the 60 Service units on. Among them are the login processes for textconsole (agetty), because unlike Sysvinit Systemd handles this via service units as a normal background service.

Units …

The configuration files for generating Units, the systemd brings, liegen in / lib / systemd / system /; a same file in / etc / systemd / system / but takes precedence.

Unit definition are usually much shorter than the classic Sys V init scripts. A unit file for the service for network time synchronization via NTP is only a few lines long:

Description=Network Time Service

ExecStart=/usr/bin/ntpd -n -u ntp:ntp -g


All unit files contained by a [Unit] introduced section with general settings, including a short description. In section [Service] follow service-specific information; with NTP that is only the command, to start the service. If a special command to exit is necessary, this can be a ExecStop-define statement. In the NTP daemon that is unnecessary, because it can be terminated in good Unix tradition by a SIGTERM signal; sending systemd to end, when no other command is specified.

The section [Install] includes instructions, the systemd in (From-)interpreted installation; , the entry in the NTP Example, that the time synchronization with the driving of the target “Multi-User” to be called.

… and targets

The target units offer a concept, resembling runlevels Sysvinit; For reasons of compatibility is understood Systemd even runlevels names to control equivalent targets. As before you can therefore at Fedora 16 the kernel in the boot loader parameter single give to; Systemd then controls an, the minimal, the single-user mode corresponding area offers.

Also 3 is working, to control the multi-user mode without graphical login manager. Represents is this mode in systemd by the target unit multi-user. a to become the standard, submits Links:

ln -sf /lib/systemd/system/ /etc/systemd/system/

If the graphical login manager later but start by default again, you can in the same way raise the standard target; it is the equivalent of runlevel 5 Fedora and OpenSuse. As an alternative to the old runlevel designations can give to the kernel, the name of the starting target unit:

In order to drive a different target unit in operation, serves the isolate-Command of Systemctl:

systemctl isolate

The change in the Rescue Target's interesting for administration tasks, because it ended Systemd all user logins and background services, leaving only system services run - as those for monitoring Logical Volumes (lvm2-monitor). Sometimes they have to be shut down for renovations, what with the emergency mode succeed; here only run the kernel threads.


The show-Command of Systemctl delivers some of the internals to the current units and the work carried out on them. It can be used also spend, calls which Units systemd in driving the multi-user targets:

systemctl show -p Wants

In issue other targets can be found - when about This in turn depends on from, the local-fs.targetpresupposes. These three targets care about the basic setup of the system; these include the integration of the file system and the start of Udev. To specify the function of the Basic Target Unit contains the configuration file following information:

By After-Indication learns Systemd, that it not only call the target, but must wait for its full launch. Next Requires there is also the weaker Wants. In specified Units calls systemd to also, sets the start but also continued, if one of them does not start.

This type of function can also links to unit files specify, that are created in a directory, whose name composed of the name of the target unit and an attached .wants, about



Who wants to disable NTPD Service Unit, so that the system at boot time is not synchronized via NTP, can do the following command:

systemctl disable ntpd.service

Here Systemctl does nothing, to remove as the link to the service unit file in the directories Wants; when activating a service with enablethe tool will create a link. Both can be done manually, to Units to (from)check box to enable.

If a service is not of a Unit, but started a traditional init script, passes Systemctl prompted to activate the program chkconfig continue. In the Fedora is the case, if you installed Apache and activated via Systemctl.

The (From)Activate a service takes effect only after the next start or stop the system. The following command starts a service unique immediately:

systemctl start ntpd.service

The parameters stop ended the service. The command status Systemctl provides information about the unit, including its current state and the name of the file specifying them. In addition, the program gives, whether and how long does the service already and which processes belong to him; the main process has Systemctl thereby explicitly from.

About the group membership can be seen, to which service has a process.
Belonging to the scale of systemd Control Groups can be quite easy to find, the processes used and from which service to start. The scale of systemd cgroup hierarchy gives the command systemd-cgls out; alternatively shows ps the group membership to:ps crude -eour pid,args,cgroup


If problems during startup problems, where systemd seems directly or indirectly involved, you should give to the kernel, the following parameters in the boot loader:

systemd.log_target=kmsg systemd.log_level=debug

Systemd then writes detailed debugging information on the console and in the buffer of the kernel messages, to you later dmesg can read.

For systemd include the command line tools poweroff, halt and reboot; alternatively, you can shut down the system via the homonymous Systemctl commands or restart. A restart is also achieved with the command

systemctl kexec

The tool “systemd-cgls” , the Control Groups and their associated processes Show.
After stopping all services has Systemd the running kernel at, directly to start a previously configured Linux kernel - without BIOS self-test and boot loader. If no Kexec kernel configured, carried out a normal restart.


In common administration tasks to get only with the service- and target units in direct contact; the other units are particularly important for special features of systemd or do at startup all those things, around which at Sysvinit- have looked after and Upstart distributions distribution specific scripts. Among them is the inclusion of in / etc / fstab file systems specified, Enabling swap space or the occasional cleaning up the / tmp directory.

For some of these works systemd brings an automount function, the pseudo-mount may invest for in / etc / fstab configured file systems; actually involved they are, however, only on the first access. Adding “comment=systemd.automount” in / etc / fstab turns any mount point in a car mount point. This can speed up the startup process and is useful for example for network shares, if the network connection through the Network Manager is only set up when logging in a user.

cause research

About Systemctl can systemd for transmitting a signal calling, without knowing the process ID of the service. The following command offset Rsyslogd in debug mode; This is terminated, if one invokes the command a second time:

systemctl kill --signal=USR1 rsyslogd.service

If you omit the indication of the signal to be transmitted, sends Systemctl a normal term signal, whereupon all processes should end, belonging to a service.

Systemd brings a program with, to visualize the startup process; the dark red areas, the starting phase of services from. Vergrößern
The command systemd-analyze outputs, how long the startup took and how much time it at the cost of kernel, omitted Initramfs and setting up the userland by systemd. The command systemd-analyze blame are the start times of the individual units of. For a more detailed consideration of the boot process, the program can create an SVG file, die the Start where Units visualized:

systemd-analyze plot > plot.svg

Sometimes you get so Units on the track, the strong pull the startup in the length. Some notes regarding the correct interpretation of these results provides the seventh part of the blog series “Systemd for Administrators”. The previous twelve-stranded series also includes many other tips and hints for practical use by systemd:

  1. Verifying Bootup
  2. Which Service Owns Which Processes?
  3. How Do I Convert A SysV Init Script Into A systemd Service File?
  4. Killing Services
  5. The Three Levels of “Off”
  6. Changing Roots
  7. The Blame Game
  8. The New Configuration Files
  9. On /etc/sysconfig and /etc/default
  10. Instantiated Services
  11. Converting inetd Services
  12. Securing Your Services

About the Homepage Lennart Poettering also found numerous other articles with backgrounds for init system. Im third “Systemd Status Update” Poettering has also listed some of the innovations recently, which were incorporated in the last eighteen months in systemd.



Leave a Reply

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