# [[#Using_Units|Enable services]] with {{ic|systemctl enable ''service''}}. systemd services replace the daemons from {{ic|/etc/rc.conf}}. For a translation of the daemons from {{ic|/etc/rc.conf}} to systemd services, see: [[Daemon#List_of_Daemons|List of Deamons]] and [[Systemd/Services|Services]]

+

# [[#Using_Units|Enable services]] with {{ic|systemctl enable ''service''}}. systemd services replace the daemons from {{ic|/etc/rc.conf}}. For a translation of the daemons from {{ic|/etc/rc.conf}} to systemd services, see: [[Daemon#List_of_Daemons|List of Daemons]] and [[Systemd/Services|Services]]

"systemd is a system and service manager for Linux, compatible with SysV and LSB init scripts. systemd provides aggressive parallelization capabilities, uses socket and D-Bus activation for starting services, offers on-demand starting of daemons, keeps track of processes using Linux control groups, supports snapshotting and restoring of the system state, maintains mount and automount points and implements an elaborate transactional dependency-based service control logic. It can work as a drop-in replacement for sysvinit."

Note: For a detailed explanation as to why Arch is switching to systemd, see: this forum post.

Things to consider before you switch

It is highly recommended to switch to the new initscripts configuration system described in the rc.conf article. Once you have this configuration established, you will have done most of the work needed to make the switch to systemd.

Note the fact that systemd has a journal system that replaces syslog, although the two can co-exist. See the section on the journal below.

Do not worry about systemd's plans to replace the functionality of cron, acpid, or xinetd. These are not things you need to worry about just yet. For now, you can continue to use your traditional daemons for these tasks.

Installation

systemd can be installed side-by-side with the regular Arch Linux initscripts package, and they can be toggled by adding/removing the init=/bin/systemdkernel parameter.

A pure systemd installation

Enable services with systemctl enable service. systemd services replace the daemons from /etc/rc.conf. For a translation of the daemons from /etc/rc.conf to systemd services, see: List of Daemons and Services

A mixed systemd installation

We recommend that you use native systemd configuration files instead of Arch's classic configuration files. You can still use /etc/rc.conf to configure a few variables if the native configuration files do not exist, but support will be dropped in the future.

If you want to keep using syslog log files alongside the systemd journal, follow the instructions described in the section on the journal, below.

Supplementary information

Tip: If you have quiet in your kernel parameters, you should remove it for your first couple of systemd boots, to assist with identifying any issues during boot.

Warning:/usr must be mounted and available at bootup (this is not particular to systemd). If your /usr is on a separate partition, you will need to make accommodations to mount it from the initramfs and unmount it from a pivoted root on shutdown. See the mkinitcpio wiki page and freedesktop.org#separate-usr-is-broken.

Native systemd configuration files

Note: You may need to create these files.

systemd will use /etc/rc.conf if these files are absent. Note this is temporary and not a long-term solution. It is strongly advised to use the systemd configuration files on any system.

Locale

Time zone

Note: This file does not obviate the need for /etc/localtime, which is a symbolic link to the desired time zone's zoneinfo file in /usr/share/zoneinfo/.

Hardware clock time

Systemd will use UTC for the hardware clock by default and this is recommended. Dealing with daylight saving time is messy. If the DST changes when your computer is off, your clock will be wrong on next boot (there is a lot more to it). Recent kernels set the system time from the RTC directly on boot without using hwclock, the kernel will always assume that the RTC is in UTC. This means that if the RTC is in local time, then the system time will first be set up wrongly and then corrected shortly afterwards on every boot. This is possibly the reason for certain weird bugs (time going backwards is rarely a good thing).

The reason for allowing the RTC to be in local time is to allow dual boot with Windows (which uses localtime). Windows is able to deal with the RTC being in UTC with a simple registry fix. If you run into issues on dual boot with Windows, you can set the hardware clock to local time. Contrary to popular belief, systemd supports this:

Kernel modules loaded during boot

systemd uses /etc/modules-load.d/ to configure kernel modules to load during boot in a static list. Each configuration file is named in the style of /etc/modules-load.d/<program>.conf. The configuration files should simply contain a list of kernel module names to load, separated by newlines. Empty lines and lines whose first non-whitespace character is # or ; are ignored. Example:

Kernel modules blacklist

Temporary files

Systemd-tmpfiles uses the configuration files in /usr/lib/tmpfiles.d/ and /etc/tmpfiles.d/ to describe the creation, cleaning and removal of volatile and temporary files and directories which usually reside in directories such as /run or /tmp. Each configuration file is named in the style of /etc/tmpfiles.d/<program>.conf. This will also override any files in /usr/lib/tmpfiles.d/ with the same name.

tmpfiles are usually provided together with service files to create directories which are expected to exist by certain daemons. For example the Samba daemon expects the directory /var/run/samba to exist and to have the correct permissions. The corresponding tmpfile looks like this:

/usr/lib/tmpfiles.d/samba.conf

D /var/run/samba 0755 root root

However, tmpfiles may also be used to write values into certain files on boot. For example, if you use /etc/rc.local to disable wakeup from USB devices with echo USBE > /proc/acpi/wakeup, you may use the following tmpfile instead:

/etc/tmpfiles.d/disable-usb-wake.conf

w /proc/acpi/wakeup - - - - USBE

The tmpfiles method is recommended in this case since systemd doesn't actually support /etc/rc.local.

See man tmpfiles.d for details.

Remote filesystem mounts

systemd automatically makes sure that remote filesystem mounts like NFS or Samba are only started after the network has been set up. Therefore remote filesystem mounts specified in /etc/fstab should work out of the box.

You may however want to use Automount for remote filesystem mounts to mount them only upon access. Furthermore you can use the x-systemd.device-timeout=# option in /etc/fstab to specify a timeout in case the network resource is not available.

See man systemd.mount for details.

Replacing acpid with systemd

systemd can handle some power-related ACPI events. This is configured via the following options in /etc/systemd/logind.conf:

HandlePowerKey: Power off the system when the power button is pressed

HandleSleepKey: Suspend the system when the sleep key is pressed

HandleLidSwitch: Suspend the system when the laptop lid is closed

Depending on the value of these options, these events may for example only be triggered when no user is logged in (no-session) or when only a single user session is active (any-session). See man logind.conf for details.

These options should not be used on desktop environments like GNOME and Xfce since these handle ACPI events by themselves. However, on systems which run no graphical setup or only a simple window manager like i3 or awesome, this may replace the acpid daemon which is usually used to react to these ACPI events.

Sleep hooks

Systemd does not use pm-utils to put the machine to sleep when using systemctl suspend or systemctl hibernate, therefore pm-utils hooks including any custom hooks created will not be run. However, systemd provides a similar mechanism to run custom scripts on these events. Systemd runs all executables in /usr/lib/systemd/system-sleep/ and passes two arguments to each of them:

Argument 1: either pre or post, depending on whether the machine is going to sleep or waking up

Argument 2: either suspend or hibernate, depending on what has been invoked

In contrast to pm-utils, systemd will run these scripts in parallel and not one after another.

The output of your script will be logged by systemd-suspend.service or systemd-hibernate.service so you can see its output in the journal.

Note that you can also use sleep.target, suspend.target or hibernate.target to hook units into the sleep state logic instead of using scripts.

See man systemd.special and man systemd-sleep for more information.

Example

Unit

A unit configuration file encodes information about a service, a socket, a device, a mount point, an automount point, a swap file or partition, a start-up target, a file system path or a timer controlled and supervised by systemd. The syntax is inspired by XDG Desktop Entry Specification .desktop files, which are in turn inspired by Microsoft Windows .ini files. See man systemd.unit for more info.

Systemd commands

systemctl: used to introspect and control the state of the systemd system and service manager.

systemd-cgls: recursively shows the contents of the selected Linux control group hierarchy in a tree

systemadm: a graphical frontend for the systemd system and service manager that allows introspection and control of systemd (available via the systemd-ui-gitAUR package from the AUR).

View the man pages for more details.

Tip: You can use all of the following systemctl commands with the -H <user>@<host> switch to control a systemd instance on a remote machine. This will use SSH to connect to the remote systemd instance.

Analyzing the system state

List running units:

$ systemctl

or:

$ systemctl list-units

List failed units:

$ systemctl --failed

The available unit files can be seen in /usr/lib/systemd/system/ and /etc/systemd/system/ (the latter takes precedence). You can see list installed unit files by:

$ systemctl list-unit-files

Using Units

Units can be, for example, services (.service), mount points (.mount), devices (.device) or sockets (.socket).
When using systemctl, you generally have to specify the complete name of the unit file, including its suffix, for example sshd.socket. There are however a few shortforms when specifying the unit in the following systemctl commands:

If you don't specify the suffix, systemctl will assume .service. For example, netcfg and netcfg.service are treated equivalent.

Note: This currently does not work with the commands enable and disable.

Mount points will automatically be translated into the appropriate .mount unit. For example, specifying /home is equivalent to home.mount.

Similiar to mount points, devices are automatically translated into the appropriate .device unit, therefore specifying /dev/sda2 is equivalent to dev-sda2.device.

See man systemd.unit for details.

Activate a unit immediately:

# systemctl start <unit>

Deactivate a unit immediately:

# systemctl stop <unit>

Restart a unit:

# systemctl restart <unit>

Ask a unit to reload its configuration:

# systemctl reload <unit>

Show the status of a unit, including whether it is running or not:

$ systemctl status <unit>

Check whether a unit is already enabled or not:

$ systemctl is-enabled <unit>

Enable a unit to be started on bootup:

# systemctl enable <unit>

Note: If services do not have an Install section, it usually means they are called automatically by other services. But if you need to install them manually, use the following command, replacing foo with the name of the service.

Show the manual page associated with a unit (this has to be supported by the unit file):

$ systemctl help <unit>

Power Management

If you are in a local ConsoleKit user session and no other session is active, the following commands will work without root privileges. If not (for example, because another user is logged into a tty), systemd will automatically ask you for the root password.

Shut down and reboot the system:

$ systemctl reboot

Shut down and power-off the system:

$ systemctl poweroff

Shut down and halt the system:

$ systemctl halt

Suspend the system:

$ systemctl suspend

Hibernate the system:

$ systemctl hibernate

Runlevels/targets

Runlevels is a legacy concept in systemd. Systemd uses targets which serve a similar purpose as runlevels but act a little different. Each target is named instead of numbered and is intended to serve a specific purpose with the possibility of having multiple ones active at the same time. Some targets are implemented by inheriting all of the services of another target and adding additional services to it. There are systemd targets that mimic the common SystemVinit runlevels so you can still switch targets using the familiar telinit RUNLEVEL command.

Get current runlevel/targets

The following should be used under systemd instead of runlevel:

# systemctl list-units --type=target

Create custom target

The runlevels that are assigned a specific purpose on vanilla Fedora installs; 0, 1, 3, 5, and 6; have a 1:1 mapping with a specific systemd target. Unfortunately, there is no good way to do the same for the user-defined runlevels like 2 and 4. If you make use of those it is suggested that you make a new named systemd target as /etc/systemd/system/<your target> that takes one of the existing runlevels as a base (you can look at /usr/lib/systemd/system/graphical.target as an example), make a directory /etc/systemd/system/<your target>.wants, and then symlink the additional services from /usr/lib/systemd/system/ that you wish to enable.

Targets table

SysV Runlevel

Systemd Target

Notes

0

runlevel0.target, poweroff.target

Halt the system.

1, s, single

runlevel1.target, rescue.target

Single user mode.

2, 4

runlevel2.target, runlevel4.target, multi-user.target

User-defined/Site-specific runlevels. By default, identical to 3.

3

runlevel3.target, multi-user.target

Multi-user, non-graphical. Users can usually login via multiple consoles or via the network.

5

runlevel5.target, graphical.target

Multi-user, graphical. Usually has all the services of runlevel 3 plus a graphical login.

6

runlevel6.target, reboot.target

Reboot

emergency

emergency.target

Emergency shell

Change current runlevels

In systemd runlevels are exposed via "target units". You can change them like this:

# systemctl isolate graphical.target

This will only change the current runlevel, and has no effect on the next boot. This is equivalent to commands such as telinit 3 or telinit 5 in Sysvinit.

Change default runlevel/target to boot into

The standard target is default.target, which is aliased by default to graphical.target (which roughly corresponds to the old runlevel 5). To change the default target at boot-time, append one of the following kernel parameters to your bootloader:

systemd.unit=multi-user.target (which roughly corresponds to the old runlevel 3),

systemd.unit=rescue.target (which roughly corresponds to the old runlevel 1).

Alternatively, you may leave the bootloader alone and change default.target. This can be done using systemctl:

# systemctl enable multi-user.target

The effect of this command is outputted by systemctl; a symlink to the new default target is made at /etc/systemd/system/default.target. This works if, and only if:

[Install]
Alias=default.target

is in the target's configuration file. Currently, multi-user.target and graphical.target both have it.

Simply delete the symlink and systemd will use its stock default.target (i.e. graphical.target).

# rm /etc/systemd/system/default.target

Using service file

Note: Using this method there will be no PAM session created for your user. Therefore ConsoleKit (which gives you access to shutdown/reboot, audio devices etc.) will not work properly. For the recommended way, see: Automatic_login_to_virtual_console#With_systemd.

If you are only looking for a simple way to start X directly without a display manager, you can create a service file similar to this:

Systemd Journal

By default, running a syslog daemon is no longer required. To read the log, use:

# journalctl

The journal writes to /run/systemd/journal, meaning logs will be lost on reboot. For non-volatile logs, create /var/log/journal/:

# mkdir /var/log/journal/

Filtering output

journalctl allows you to filter the output by specific fields.

Examples:

Show all messages by a specific executable:

# journalctl /usr/lib/systemd/systemd

Show all messages by a specific process:

# journalctl _PID=1

Show all messages by a specific unit:

# journalctl _SYSTEMD_UNIT=netcfg.service

See man journalctl and systemd.journal-fields for details.

Journal size limit

If the journal is made non-volatile, its size limit is set to a default value of 10% of the size of the respective file system. E.g. with /var/log/journal located on a 50 GiB root partition this would lead to 5 GiB of journal data. The maximum size of the persistent journal can be controlled by SystemMaxUse in /etc/systemd/journald.conf, so to limit it for example to 50 MiB uncomment and edit the corresponding line to:

SystemMaxUse=50M

Refer to man journald.conf for more info.

Journald in conjunction with a classic syslog daemon

Compatibility with classic syslog implementations is provided via a
socket /run/systemd/journal/syslog, to which all messages are forwarded.
To make the syslog daemon work with the journal, it has to bind to this socket instead of /dev/log (official announcement). For syslog-ng, change the source src section in /etc/syslog-ng/syslog-ng.conf to:

For legacy purposes, the DAEMONS section in /etc/rc.conf is still compatible with systemd and can be used to start services at boot, even with a "pure" systemd service management. Alternatively, you may remove the /etc/rc.conf file entirely and enable services in systemd. For each <service_name> in the DAEMONS array in /etc/rc.conf, type:

# systemctl enable <service_name>.service

Tip: For a list of commonly used daemons with their initscripts and systemd equivalents, see this table.

If <service_name>.service does not exist:

the service file may not be available for systemd. In that case, you'll need to keep rc.conf to start the service during boot up.

systemd may name services differently, e.g. cronie.service replaces crond init daemon; alsa-store.service and alsa-restore.service replace the alsa init daemon. Another important instance is the network daemon, which is replaced with another set of service files (see #Network for more details.)

Tip: You may look inside a package that contains daemon start scripts for service names. For instance:

some services do not need to be explicitly enabled by the user. For instance, dbus.service will automatically be enabled when dbus-core is installed. Check the list of available services and their state using the systemctl command.

Writing custom .service files

Handling dependencies

With systemd dependencies can be resolved by designing the unit files correctly. The most typical case is that the unit A requires the unit B to be running before A is started. In that case add Requires=B and After=B to the [Unit] section of A. If the dependency is optional, add Wants=B and After=B instead. Note that Wants= and Requires= do not imply After=, meaning that if After= is not specified, the two units will be started in parallel.

Dependencies are typically placed on services and not on targets. For example, network.target is pulled in by whatever service configures your network interfaces, therefore ordering your custom unit after it is sufficient since network.target is started anyway.

Type

There are several different start-up types to consider when writing a custom service file. This is set with the Type= parameter in the [Service] section. See man systemd.service for a more detailed explanation.

Type=simple: systemd considers the daemon to be started up immediately. The process must not fork. Do not use this type if other services need to be ordered on this service, unless it is socket activated.

Type=forking: systemd considers the daemon started up once the process forks and the parent has exited. For classic daemons use this type unless you know that it is not necessary, as most daemons use double-forking to signal that they are ready. You should specify PIDFile= as well so systemd can keep track of the main process.

Type=oneshot: This is useful for scripts that do a single job and then exit. You may want to set RemainAfterExit= as well so that systemd still considers the service as active after the process has exited.

Type=notify: Identical to Type=simple, but with the stipulation that the daemon will send a signal to systemd when it is ready. This requires systemd-specific code provided by libsystemd-daemon.so.

Type=dbus: The daemon is considered ready when the specified BusName appears on DBus's system bus.

Replacing provided unit files

The unit files in /etc/systemd/system/ take precedence over the ones in /usr/lib/systemd/system/.
To make your own version of a unit (which will not be destroyed by an upgrade), copy the old unit file from /usr/lib/ to /etc/ and make your changes there. Alternatively you can use .include to parse an existing service file and then override or add new options. For example, if you simply want to add an additional dependency to a service file, you may use:

FAQ

Optimization

systemd-analyze

Systemd provides a tool called systemd-analyze that allows you to analyze your boot process so you can see which unit files are causing your boot process to slow down. You can then optimize your system accordingly. You have to install python2-dbus and python2-cairo to use it.

To see how much time was spent in kernel-/userspace on boot, simply use:

$ systemd-analyze

Tip: If you add the timestamp hook to your HOOKS array in /etc/mkinitcpio.conf and rebuild your initramfs, systemd-analyze will also be able to show you how much time was spent in the initramfs.

To list the started unit files, sorted by the time each of them took to start up:

$ systemd-analyze blame

You can also create a SVG file which describes your boot process grapically, similiar to Bootchart:

$ systemd-analyze plot > plot.svg

Enabling bootchart in conjunction with systemd

You can use a version of bootchart to visualize the boot sequence.
Since you are not able to put a second init into the kernel command line you won't be able to use any of the standard bootchart setups. However the bootchart2AUR package from AUR comes with an undocumented systemd service. After you've installed bootchart2 do:

Shell Shortcuts

systemd daemon management requires a bit more text entry to accomplish tasks such as start, stopped, enabling, checking status, etc. The following functions can be added to one's ~/.bashrc file to help streamline interactions with systemd and to improve the overall experience.

Less output

Change verbose to quiet on the bootloader's kernel line. For some systems, particularly those with an SSD, the slow performance of the TTY is actually a bottleneck, and so less output means faster booting.

Early start

One central feature of systemd is D-Bus and socket activation, this causes services to be started when they are first accessed, and is generally a good thing. However, if you know that a service (like ConsoleKit) will always be started during boot, then the overall boot time might be reduced by starting it as early as possible. This can be achieved (if the service file is set up for it, which in most cases it is) by issuing:

# systemctl enable console-kit-daemon.service

This will cause systemd to start ConsoleKit as soon as possible, without causing races with the socket or D-Bus activation.

Automount

The default setup will fsck and mount all filesystems before starting most daemons and services. If you have a large /home partition, it might be better to allow services that do not depend on /home to start while /home is being fsck'ed. This can be achieved by adding the following options to the fstab entry of your /home partition:

noauto,x-systemd.automount

This will fsck and mount /home when it is first accessed, and the kernel will buffer all file access to /home until it is ready.

If you have encrypted filesystems with keyfiles, you can also add the noauto parameter to the corresponding entries in /etc/crypttab. systemd will then not open the encrypted device on boot, but instead wait until it is actually accessed and then automatically open it with the specified keyfile before mounting it. This might save a few seconds on boot if you are using an encrypted RAID device for example, because systemd doesn't have to wait for the device to become available. For example:

/etc/crypttab

data /dev/md0 /root/key noauto

Readahead

systemd comes with its own readahead implementation, this should in principle improve boot time. However, depending on your kernel version and the type of your hard drive, your mileage may vary (i.e. it might be slower). To enable, do:

Further, you can replace ConsoleKit's functionality with systemd. To do this, polkit needs to be rebuilt from ABS with systemd enabled (--enable-systemd), and stuff like USB automounting will work without consolekit. DBus supports systemd since version 1.6.0, so there's no longer need to build it from Git.

Troubleshooting

Shutdown/Reboot takes terribly long

If the shutdown process takes a very long time (or seems to freeze) most likely a service not exiting is to blame. systemd waits some time for each service to exit before trying to kill it.
To find out if you are affected see this article.

SLiM and xfce-session

One setup that can produce a shutdown freeze is Xfce in conjunction with SLiM: Shutting down/rebooting using xfce-session will cause slim.service to hang for half a minute until systemd kills it the hard way.
One workaround is to create a modified slim.service:

If the CUPS service isn't starting on demand

I found on my machine, even after running "systemctl enable cups.service", cups would never work until I manually issued "systemctl start cups.service". To remedy this you can manually symlink the cups service so it is automatically started at boot:

I found that "systemctl enable cupsd.service" fails with a complaint about not finding the file. I'm guessing this is because it is a symlink to cups.service. Apparently systemctl doesn't like symlinks. I'm not sure if this is user error (I wasn't meant to use the symlink for this purpose) or a bug but either way, specifying cups.service seemed to work although I haven't tested it yet.

If some services are failing to start

If your /var/tmp is a symbolic link to /tmp, expect some services to fail when started via systemd. In these cases, the failure status of the processes (via systemctl status <service>) will be "226/NAMESPACE". To overcome this blocker, simply remove your /var/tmp symlink and reinstall the filesystem package.

Disable warning bell

Add command xset -b to the .xinitrc file.
Discussion on this forum topic.