# Once completed you may enable any desired services via the use of {{ic|systemctl enable ''service_name''}} (this roughly equates to what you included in the {{ic|DAEMONS}} array. New names can be found in [[Daemons List]]).

# Once completed you may enable any desired services via the use of {{ic|systemctl enable ''service_name''}} (this roughly equates to what you included in the {{ic|DAEMONS}} array. New names can be found in [[Daemons List]]).

# Reboot your system and verify that ''systemd'' is currently active by issuing the following command: {{ic|cat /proc/1/comm}}. This should return the string {{ic|systemd}}.

# Reboot your system and verify that ''systemd'' is currently active by issuing the following command: {{ic|cat /proc/1/comm}}. This should return the string {{ic|systemd}}.

−

# Make sure your hostname is set correctly under ''systemd'': {{ic|hostnamectl set-hostname ''myhostname''}}.

+

# Make sure your hostname is set correctly under ''systemd'': {{ic|hostnamectl set-hostname ''myhostname''}} or {{ic|/etc/hostname}}.

# Proceed to remove ''initscripts'' and ''sysvinit'' from your system and install {{Pkg|systemd-sysvcompat}}.

# Proceed to remove ''initscripts'' and ''sysvinit'' from your system and install {{Pkg|systemd-sysvcompat}}.

−

# Optionally, remove the {{ic|1=init=/usr/lib/systemd/systemd}} parameter as it is no longer needed. {{Pkg|systemd-sysvcompat}} provides the default init.

+

# Optionally, remove the {{ic|1=init=/usr/lib/systemd/systemd}} parameter. It is no longer needed since {{Pkg|systemd-sysvcompat}} provides a symlink to ''systemd'''s init where ''sysvinit'' used to be.

=== Supplementary information ===

=== Supplementary information ===

Line 58:

Line 60:

* See the [[Network Configuration]] article for how to set up networking targets.

* See the [[Network Configuration]] article for how to set up networking targets.

−

−

== Native configuration ==

−

−

{{Note|You may need to create these files. All files should have {{ic|644}} permissions and {{ic|root:root}} ownership.}}

The virtual console (keyboard mapping, console font and console map) is configured in {{ic|/etc/vconsole.conf}} or by using the ''localectl'' tool.

−

−

For more information, see [[Fonts#Console fonts|console fonts]] and [[KEYMAP|keymaps]].

−

−

=== Hardware clock ===

−

{{Merge|Time|This section was added here before systemd became the default init system. Delete it after merging.|section=Duplication of content in Native configuration section}}

−

−

''systemd'' will use UTC for the hardware clock by default.

−

−

{{Tip|It is advised to have the [[Network Time Protocol daemon]] running to keep the system time synchronized with Internet time and the hardware clock.}}

−

−

==== Hardware clock in localtime ====

−

−

If you want to change the hardware clock to use local time ('''strongly discouraged''') do:

−

−

# timedatectl set-local-rtc true

−

−

If you want to revert to the hardware clock being in UTC, do:

−

−

# timedatectl set-local-rtc false

−

−

Be warned that, if the hardware clock is set to localtime, dealing with daylight saving time is messy. If the DST changes when your computer is off, your clock will be wrong on next boot ([http://www.cl.cam.ac.uk/~mgk25/mswish/ut-rtc.html there is a lot more to it]). Recent kernels set the system time from the RTC directly on boot, assuming 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 the root of certain weird bugs (time going backwards is rarely a good thing).

−

−

One reason for allowing the RTC to be in local time is to allow dual boot with Windows ([http://blogs.msdn.com/b/oldnewthing/archive/2004/09/02/224672.aspx which uses localtime]). However, Windows is able to deal with the RTC being in UTC with a simple [[Time#UTC in Windows|registry fix]]. It is recommended to configure Windows to use UTC, rather than Linux to use localtime. If you make Windows use UTC, also remember to disable the "Internet Time Update" Windows feature, so that Windows does not mess with the hardware clock, trying to sync it with internet time. You should instead leave touching the RTC and syncing it to internet time to Linux, by enabling an [[NTP]] daemon, as suggested previously.

{{Merge|File Systems|This section was added here before systemd became the default init system. Delete it after merging.|section=Duplication of content in Native configuration section}}

−

−

The default setup will automatically fsck and mount filesystems before starting services that need them to be mounted. For example, systemd automatically makes sure that remote filesystem mounts like [[NFS]] or [[Samba]] are only started after the network has been set up. Therefore, local and remote filesystem mounts specified in {{ic|/etc/fstab}} should work out of the box.

−

−

See {{ic|man 5 systemd.mount}} for details.

−

−

==== Automount ====

−

{{Merge|fstab|This section was added here before systemd became the default init system. Delete it after merging.|section=Duplication of content in Native configuration section}}

−

−

If you have a large {{ic|/home}} partition, it might be better to allow services that do not depend on {{ic|/home}} to start while {{ic|/home}} is checked by ''fsck''. This can be achieved by adding the following options to the {{ic|/etc/fstab}} entry of your {{ic|/home}} partition:

−

−

noauto,x-systemd.automount

−

−

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

−

−

{{Note|This will make your {{ic|/home}} filesystem type {{ic|autofs}}, which is ignored by [[mlocate]] by default. The speedup of automounting {{ic|/home}} may not be more than a second or two, depending on your system, so this trick may not be worth it.}}

−

−

The same applies to remote filesystem mounts. If you want them to be mounted only upon access, you will need to use the {{ic|noauto,x-systemd.automount}} parameters. In addition, you can use the {{ic|1=x-systemd.device-timeout=#}} option to specify a timeout in case the network resource is not available.

−

−

If you have encrypted filesystems with keyfiles, you can also add the {{ic|noauto}} parameter to the corresponding entries in {{ic|/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 does not have to wait for the device to become available. For example:

−

−

{{hc|/etc/crypttab|

−

data /dev/md0 /root/key noauto}}

−

−

==== LVM ====

−

{{Merge|LVM|This section was added here before systemd became the default init system. Delete it after merging.|section=Duplication of content in Native configuration section}}

−

−

If you have [[LVM]] volumes not activated via the [[Mkinitcpio|initramfs]], [[Systemd#Using_units|enable]] the '''lvm-monitoring''' service, which is provided by the {{pkg|lvm2}} package.

−

−

=== ACPI power management ===

−

{{Merge|Power Management|This section was added here before systemd became the default init system. Delete it after merging. [[Power Management]] is mainly used to link to other articles at the moment, but since systemd is default on Arch now, this section could stay there.|section=Duplication of content in Native configuration section}}

−

−

''systemd'' handles some power-related [[Wikipedia:Advanced_Configuration_and_Power_Interface|ACPI]] events. They can be configured via the following options from {{ic|/etc/systemd/logind.conf}}:

−

−

* {{ic|HandlePowerKey}}: specifies which action is invoked when the power key is pressed.

−

* {{ic|HandleSuspendKey}}: specifies which action is invoked when the suspend key is pressed.

−

* {{ic|HandleHibernateKey}}: specifies which action is invoked when the hibernate key is pressed.

−

* {{ic|HandleLidSwitch}}: specifies which action is invoked when the lid is closed.

−

−

The specified action can be one of {{ic|ignore}}, {{ic|poweroff}}, {{ic|reboot}}, {{ic|halt}}, {{ic|suspend}}, {{ic|hibernate}}, {{ic|hybrid-sleep}}, {{ic|lock}} or {{ic|kexec}}.

−

−

If these options are not configured, ''systemd'' will use its defaults: {{ic|1=HandlePowerKey=poweroff}}, {{ic|1=HandleSuspendKey=suspend}}, {{ic|1=HandleHibernateKey=hibernate}}, and {{ic|1=HandleLidSwitch=suspend}}.

−

−

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.

−

−

{{Note|

−

* Run {{ic|systemctl restart systemd-logind}} for your changes to take effect.

−

* ''systemd'' cannot handle AC and Battery ACPI events, so if you use [[Laptop Mode Tools]] or other similar tools [[acpid]] is still required.

−

}}

−

−

In the current version of ''systemd'', the {{ic|Handle*}} options will apply throughout the system unless they are "inhibited" (temporarily turned off) by a program, such as a power manager inside a desktop environment. If these inhibits are not taken, you can end up with a situation where ''systemd'' suspends your system, then when it wakes up the other power manager suspends it again.

−

−

{{Warning|Currently, the power managers in the newest versions of [[KDE]] and [[GNOME]] are the only ones that issue the necessary "inhibited" commands. Until the others do, you will need to set the {{ic|Handle}} options to {{ic|ignore}} if you want your ACPI events to be handled by [[Xfce]], [[acpid]] or other programs.}}

−

−

{{Note|''systemd'' can also use other suspend backends (such as [[Uswsusp]] or [[TuxOnIce]]), in addition to the default ''kernel'' backend, in order to put the computer to sleep or hibernate.}}

−

−

For {{ic|systemctl hibernate}} to work on your system you need to follow the instructions at [[Pm-utils#Hibernation (suspend2disk)]] and possibly at [[Pm-utils#Mkinitcpio Resume Hook]] (''pm-utils'' does ''not'' need to be installed).

−

−

==== Sleep hooks ====

−

−

''systemd'' does not use [[pm-utils]] to put the machine to sleep when using {{ic|systemctl suspend}}, {{ic|systemctl hibernate}} or {{ic|systemctl hybrid-sleep}}; ''pm-utils'' hooks, including any [[Pm-utils#Creating_your_own_hooks|custom hooks]], will not be run. However, ''systemd'' provides two similar mechanisms to run custom scripts on these events.

−

−

===== Suspend/resume service files =====

−

−

Service files can be hooked into ''suspend.target'', ''hibernate.target'' and ''sleep.target'' to execute actions before or after suspend/hibernate. Separate files should be created for user actions and root/system actions. To activate the user service files run {{ic|systemctl enable suspend@''user'' && systemctl enable resume@''user''}}. Examples:

A couple of handy hints about these service files (more in {{ic|man systemd.service}}):

−

* If {{ic|1=<nowiki>Type=OneShot</nowiki>}} then you can use multiple {{ic|1=<nowiki>ExecStart=</nowiki>}} lines. Otherwise only one {{ic|ExecStart}} line is allowed. You can add more commands with either {{ic|ExecStartPre}} or by separating commands with a semicolon (see the first example above; note the spaces before and after the semicolon, as they are ''required'').

−

* A command prefixed with {{ic|-}} will cause a non-zero exit status to be ignored and treated as a successful command.

−

* The best place to find errors when troubleshooting these service files is of course with [[Systemd#Journal|journalctl]].

−

−

===== Combined Suspend/resume service file =====

−

−

With the combined suspend/resume service file, a single hook does all the work for different phases (sleep/resume) and for different targets (suspend/hibernate/hybrid-sleep).

−

−

Example and explanation:

−

−

{{hc|/etc/systemd/system/wicd-sleep.service|2=<nowiki>

−

[Unit]

−

Description=Wicd sleep hook

−

Before=sleep.target

−

StopWhenUnneeded=yes

−

−

[Service]

−

Type=oneshot

−

RemainAfterExit=yes

−

ExecStart=-/usr/share/wicd/daemon/suspend.py

−

ExecStop=-/usr/share/wicd/daemon/autoconnect.py

−

−

[Install]

−

WantedBy=sleep.target</nowiki>}}

−

−

* {{ic|1=<nowiki>RemainAfterExit=yes</nowiki>}}: After started, the service is considered active until it is explicitly stopped.

−

* {{ic|1=<nowiki>StopWhenUnneeded=yes</nowiki>}}: When active, the service will be stopped if no other active service requires it. In this specific example, it will be stopped after ''sleep.target'' is stopped.

−

* Because ''sleep.target'' is pulled in by ''suspend.target'', ''hibernate.target'' and ''hybrid-sleep.target'' and ''sleep.target'' itself is a ''StopWhenUnneeded'' service, the hook is guaranteed to start/stop properly for different tasks.

−

−

===== Hooks in /usr/lib/systemd/system-sleep =====

−

−

''systemd'' runs all executables in {{ic|/usr/lib/systemd/system-sleep/}}, passing two arguments to each of them:

−

−

* Argument 1: either {{ic|pre}} or {{ic|post}}, depending on whether the machine is going to sleep or waking up

−

* Argument 2: {{ic|suspend}}, {{ic|hibernate}} or {{ic|hybrid-sleep}}, depending on which is being invoked

−

−

In contrast to [[pm-utils]], ''systemd'' will run these scripts concurrently and not one after another.

−

−

The output of any custom script will be logged by ''systemd-suspend.service'', ''systemd-hibernate.service'' or ''systemd-hybrid-sleep.service''. You can see its output in ''systemd''<nowiki>'</nowiki>s [[systemd#Journal|journal]]:

−

# journalctl -b -u systemd-suspend

−

−

{{Note|You can also use ''sleep.target'', ''suspend.target'', ''hibernate.target'' or ''hybrid-sleep.target'' to hook units into the sleep state logic instead of using custom scripts.}}

−

−

An example of a custom sleep script:

−

−

{{hc|/usr/lib/systemd/system-sleep/example.sh|

−

#!/bin/sh

−

case $1/$2 in

−

pre/*)

−

echo "Going to $2..."

−

;;

−

post/*)

−

echo "Waking up from $2..."

−

;;

−

esac}}

−

−

Do not forget to make your script executable:

−

# chmod a+x /usr/lib/systemd/system-sleep/example.sh

−

−

See {{ic|man 7 systemd.special}} and {{ic|man 8 systemd-sleep}} for more details.

−

−

=== Temporary files ===

−

{{Moveto|Systemd#|Trying to remove the [[#Native configuration]] section entirely, this section can easily become a top-level one like [[#Journal]].|section=Duplication of content in Native configuration section}}

−

−

'''systemd-tmpfiles''' uses configuration files in {{ic|/usr/lib/tmpfiles.d/}} and {{ic|/etc/tmpfiles.d/}} to describe the creation, cleaning and removal of volatile and temporary files and directories which usually reside in directories such as {{ic|/run}} or {{ic|/tmp}}. Each configuration file is named in the style of {{ic|/etc/tmpfiles.d/<program>.conf}}. This will also override any files in {{ic|/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 {{ic|/run/samba}} to exist and to have the correct permissions. The corresponding tmpfile looks like this:

−

−

{{hc|/usr/lib/tmpfiles.d/samba.conf|

−

D /run/samba 0755 root root}}

−

−

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

−

−

{{hc|/etc/tmpfiles.d/disable-usb-wake.conf|

−

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

−

−

See {{ic|man 5 tmpfiles.d}} for details.

−

{{note|This method may not work to set options in {{ic|/sys}} since the {{ic|systemd-tmpfiles-setup}} service may run before the appropriate device modules is loaded. In this case you could check whether the module has a parameter for the option you want to set with {{ic|modinfo <module>}} and set this option with a [[Modprobe.d#Configuration|config file in {{ic|/etc/modprobe.d}}]]. Otherwise you will have to write a [[Udev#About_udev_rules|udev rule]] to set the appropriate attribute as soon as the device appears.}}

−

−

=== Units ===

−

{{Merge|#Writing custom .service files|This section was added here before systemd became the default init system. Delete it after merging.|section=Duplication of content in Native configuration section}}

−

−

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 {{ic|man 5 systemd.unit}} for details.

== Basic systemctl usage ==

== Basic systemctl usage ==

−

The main command used to introspect and control systemd is {{ic|systemctl}}. Some of its uses are examining the system state and managing the system and services. See {{ic|man 1 systemctl}} for more details.

+

The main command used to introspect and control ''systemd'' is '''systemctl'''. Some of its uses are examining the system state and managing the system and services. See {{ic|man 1 systemctl}} for more details.

−

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

+

{{Tip|You can use all of the following ''systemctl'' commands with the {{ic|-H ''user''@''host''}} switch to control a ''systemd'' instance on a remote machine. This will use [[SSH]] to connect to the remote ''systemd'' instance.}}

−

{{Note|{{ic|systemadm}} is the official graphical frontend for {{ic|systemctl}}. It is provided by the {{AUR|systemd-ui-git}} package from the [[AUR]].}}

+

{{Note|''systemadm'' is the official graphical frontend for ''systemctl''. It is provided by the {{AUR|systemd-ui-git}} package from the [[AUR]].}}

=== Analyzing the system state ===

=== Analyzing the system state ===

Line 329:

Line 83:

$ systemctl --failed

$ systemctl --failed

−

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

+

The available unit files can be seen in {{ic|/usr/lib/systemd/system/}} and {{ic|/etc/systemd/system/}} (the latter takes precedence). You can see a list of the installed unit files with:

When using {{ic|systemctl}}, you generally have to specify the complete name of the unit file, including its suffix, for example {{ic|sshd.socket}}. There are however a few shortforms when specifying the unit in the following {{ic|systemctl}} commands:

+

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 short forms when specifying the unit in the following ''systemctl'' commands:

−

* If you do not specify the suffix, systemctl will assume {{ic|.service}}. For example, {{ic|netcfg}} and {{ic|netcfg.service}} are equivalent.

+

* If you do not specify the suffix, systemctl will assume ''.service''. For example, {{ic|netcfg}} and {{ic|netcfg.service}} are equivalent.

−

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

+

* Mount points will automatically be translated into the appropriate ''.mount'' unit. For example, specifying {{ic|/home}} is equivalent to {{ic|home.mount}}.

* Similar to mount points, devices are automatically translated into the appropriate ''.device'' unit, therefore specifying {{ic|/dev/sda2}} is equivalent to {{ic|dev-sda2.device}}.

See {{ic|man systemd.unit}} for details.

See {{ic|man systemd.unit}} for details.

Line 347:

Line 101:

Activate a unit immediately:

Activate a unit immediately:

−

# systemctl start <unit>

+

# systemctl start ''unit''

Deactivate a unit immediately:

Deactivate a unit immediately:

−

# systemctl stop <unit>

+

# systemctl stop ''unit''

Restart a unit:

Restart a unit:

−

# systemctl restart <unit>

+

# systemctl restart ''unit''

Ask a unit to reload its configuration:

Ask a unit to reload its configuration:

−

# systemctl reload <unit>

+

# systemctl reload ''unit''

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

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

−

$ systemctl status <unit>

+

$ systemctl status ''unit''

Check whether a unit is already enabled or not:

Check whether a unit is already enabled or not:

−

$ systemctl is-enabled <unit>

+

$ systemctl is-enabled ''unit''

Enable a unit to be started on bootup:

Enable a unit to be started on bootup:

−

# systemctl enable <unit>

+

# systemctl enable ''unit''

−

{{Note|Services without an {{ic|[Install]}} section are usually called automatically by other services. If you need to install them manually, use the following command, replacing {{ic|foo}} with the name of the service.

+

{{Note|Services without an {{ic|[Install]}} section are usually called automatically by other services. 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):

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

−

$ systemctl help <unit>

+

$ systemctl help ''unit''

−

Reload systemd, scanning for new or changed units:

+

Reload ''systemd'', scanning for new or changed units:

# systemctl daemon-reload

# systemctl daemon-reload

Line 391:

Line 145:

=== Power management ===

=== Power management ===

−

'''polkit''' is necessary for power management.

+

[[polkit]] is necessary for power management. If you are in a local ''systemd-logind'' 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.

−

If you are in a local '''systemd-logind''' 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:

Shut down and reboot the system:

Line 415:

Line 168:

== Running DMs under systemd ==

== Running DMs under systemd ==

+

+

{{Merge|Display Manager|We have separate article, this section should be moved there to keep things in one place.}}

{{Merge|File Systems|This section was added here before systemd became the default init system. Delete it after merging.|section=Duplication of content in Native configuration section}}

+

+

The default setup will automatically fsck and mount filesystems before starting services that need them to be mounted. For example, systemd automatically makes sure that remote filesystem mounts like [[NFS]] or [[Samba]] are only started after the network has been set up. Therefore, local and remote filesystem mounts specified in {{ic|/etc/fstab}} should work out of the box.

+

+

See {{ic|man 5 systemd.mount}} for details.

+

+

==== Automount ====

+

{{Merge|fstab|This section was added here before systemd became the default init system. Delete it after merging.|section=Duplication of content in Native configuration section}}

+

+

If you have a large {{ic|/home}} partition, it might be better to allow services that do not depend on {{ic|/home}} to start while {{ic|/home}} is checked by ''fsck''. This can be achieved by adding the following options to the {{ic|/etc/fstab}} entry of your {{ic|/home}} partition:

+

+

noauto,x-systemd.automount

+

+

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

+

+

{{Note|This will make your {{ic|/home}} filesystem type {{ic|autofs}}, which is ignored by [[mlocate]] by default. The speedup of automounting {{ic|/home}} may not be more than a second or two, depending on your system, so this trick may not be worth it.}}

+

+

The same applies to remote filesystem mounts. If you want them to be mounted only upon access, you will need to use the {{ic|noauto,x-systemd.automount}} parameters. In addition, you can use the {{ic|1=x-systemd.device-timeout=#}} option to specify a timeout in case the network resource is not available.

+

+

If you have encrypted filesystems with keyfiles, you can also add the {{ic|noauto}} parameter to the corresponding entries in {{ic|/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 does not have to wait for the device to become available. For example:

+

+

{{hc|/etc/crypttab|

+

data /dev/md0 /root/key noauto}}

+

+

==== LVM ====

+

{{Merge|LVM|This section was added here before systemd became the default init system. Delete it after merging.|section=Duplication of content in Native configuration section}}

+

+

If you have [[LVM]] volumes not activated via the [[Mkinitcpio|initramfs]], [[Systemd#Using_units|enable]] the '''lvm-monitoring''' service, which is provided by the {{pkg|lvm2}} package.

{{Moveto|Systemd#|Trying to remove the [[#Native configuration]] section entirely, this section can easily become a top-level one like [[#Journal]].|section=Duplication of content in Native configuration section}}

+

+

"'''systemd-tmpfiles''' creates, deletes and cleans up volatile and temporary files and directories." It reads configuration files in {{ic|/etc/tmpfiles.d/}} and {{ic|/usr/lib/tmpfiles.d/}} to discover which actions to perform. Configuration files in the former directory take precedence over those in the latter directory.

+

+

Configuration files are usually provided together with service files, and they are named in the style of {{ic|/usr/lib/tmpfiles.d/''program''.conf}}. For example, the [[Samba]] daemon expects the directory {{ic|/run/samba}} to exist and to have the correct permissions. Therefore, the {{Pkg|samba}} package ships with this configuration:

+

+

{{hc|/usr/lib/tmpfiles.d/samba.conf|

+

D /run/samba 0755 root root}}

+

+

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

+

+

{{hc|/etc/tmpfiles.d/disable-usb-wake.conf|

+

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

+

+

See the {{ic|systemd-tmpfiles}} and {{ic|tmpfiles.d(5)}} man pages for details.

+

+

{{Note|This method may not work to set options in {{ic|/sys}} since the ''systemd-tmpfiles-setup'' service may run before the appropriate device modules is loaded. In this case you could check whether the module has a parameter for the option you want to set with {{ic|modinfo ''module''}} and set this option with a [[Modprobe.d#Configuration|config file in /etc/modprobe.d]]. Otherwise you will have to write a [[Udev#About_udev_rules|udev rule]] to set the appropriate attribute as soon as the device appears.}}

== Writing custom .service files ==

== Writing custom .service files ==

−

''See: [[systemd/Services]]''

+

The syntax of systemd's [[#Using units|unit files]] is inspired by XDG Desktop Entry Specification .desktop files, which are in turn inspired by Microsoft Windows .ini files.

+

+

See [[systemd/Services]] for more examples.

=== Handling dependencies ===

=== Handling dependencies ===

−

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

+

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 {{ic|1=Requires=''B''}} and {{ic|1=After=''B''}} to the {{ic|[Unit]}} section of ''A''. If the dependency is optional, add {{ic|1=Wants=''B''}} and {{ic|1=After=''B''}} instead. Note that {{ic|1=Wants=}} and {{ic|1=Requires=}} do not imply {{ic|1=After=}}, meaning that if {{ic|1=After=}} is not specified, the two units will be started in parallel.

−

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

+

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 ===

=== Type ===

Line 451:

Line 276:

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

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

−

* {{ic|1=Type=simple}} (default): '''systemd''' considers the service 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.

+

* {{ic|1=Type=simple}} (default): ''systemd'' considers the service 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.

−

* {{ic|1=Type=forking}}: '''systemd''' considers the service 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. You should specify {{ic|1=PIDFile=}} as well so '''systemd''' can keep track of the main process.

+

* {{ic|1=Type=forking}}: ''systemd'' considers the service 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. You should specify {{ic|1=PIDFile=}} as well so ''systemd'' can keep track of the main process.

−

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

+

* {{ic|1=Type=oneshot}}: this is useful for scripts that do a single job and then exit. You may want to set {{ic|1=RemainAfterExit=yes}} as well so that ''systemd'' still considers the service as active after the process has exited.

−

* {{ic|1=Type=notify}}: Identical to {{ic|1=Type=simple}}, but with the stipulation that the daemon will send a signal to '''systemd''' when it is ready. The reference implementation for this notification is provided by {{ic|libsystemd-daemon.so}}.

+

* {{ic|1=Type=notify}}: identical to {{ic|1=Type=simple}}, but with the stipulation that the daemon will send a signal to ''systemd'' when it is ready. The reference implementation for this notification is provided by ''libsystemd-daemon.so''.

−

* {{ic|1=Type=dbus}}: The service is considered ready when the specified {{ic|BusName}} appears on DBus's system bus.

+

* {{ic|1=Type=dbus}}: the service is considered ready when the specified {{ic|BusName}} appears on DBus's system bus.

=== Editing provided unit files ===

=== Editing provided unit files ===

−

To edit a unit file provided by a package, you can create a directory called {{ic|/etc/systemd/system/<unit>.d/}} for example {{ic|/etc/systemd/system/httpd.service.d/}} and place {{ic|*.conf}} files in there to override or add new options. '''systemd''' will parse these {{ic|*.conf}} files and apply them on top of the original unit. For example, if you simply want to add an additional dependency to a unit, you may create the following file:

+

To edit a unit file provided by a package, you can create a directory called {{ic|/etc/systemd/system/''unit''.d/}} for example {{ic|/etc/systemd/system/httpd.service.d/}} and place ''*.conf'' files in there to override or add new options. ''systemd'' will parse these ''*.conf'' files and apply them on top of the original unit. For example, if you simply want to add an additional dependency to a unit, you may create the following file:

−

{{hc|/etc/systemd/system/<unit>.d/customdependency.conf|2=

+

{{hc|/etc/systemd/system/''unit''.d/customdependency.conf|2=

[Unit]

[Unit]

−

Requires=<new dependency>

+

Requires=''new dependency''

−

After=<new dependency>}}

+

After=''new dependency''}}

Then run the following for your changes to take effect:

Then run the following for your changes to take effect:

# systemctl daemon-reload

# systemctl daemon-reload

−

# systemctl restart <unit>

+

# systemctl restart ''unit''

+

+

Alternatively you can copy the old unit file from {{ic|/usr/lib/systemd/system/}} to {{ic|/etc/systemd/system/}} and make your changes there. A unit file in {{ic|/etc/systemd/system/}} always overrides the same unit in {{ic|/usr/lib/systemd/system/}}. Note that when the original unit in {{ic|/usr/lib/}} is changed due to a package upgrade, these changes will not automatically apply to your custom unit file in {{ic|/etc/}}. Additionally you will have to manually reenable the unit with {{ic|systemctl reenable ''unit''}}. It is therefore recommended to use the ''*.conf'' method described before instead.

−

Alternatively you can copy the old unit file from {{ic|/usr/lib/systemd/system/}} to {{ic|/etc/systemd/system/}} and make your changes there. A unit file in {{ic|/etc/systemd/system/}} always overrides the same unit in {{ic|/usr/lib/systemd/system/}}. Note that when the original unit in {{ic|/usr/lib/}} is changed due to a package upgrade, these changes will not automatically apply to your custom unit file in {{ic|/etc/}}. Additionally you will have to manually reenable the unit with {{ic|systemctl reenable <unit>}}. It is therefore recommended to use the {{ic|*.conf}} method described before instead.

+

{{Tip|You can use '''systemd-delta''' to see which unit files have been overridden and what exactly has been changed.}}

−

{{Tip|You can use '''systemd-delta''' to see which unit files have been overridden and what exactly has been changed.}} As the provided unit files will be updated from time to time, use '''systemd-delta''' for system maintenance.

+

As the provided unit files will be updated from time to time, use ''systemd-delta'' for system maintenance.

=== Syntax highlighting for units within Vim ===

=== Syntax highlighting for units within Vim ===

−

Syntax highlighting for '''systemd''' unit files within [[Vim]] can be enabled by installing {{Pkg|vim-systemd}} from the [[Official Repositories|official repositories]].

+

Syntax highlighting for ''systemd'' unit files within [[Vim]] can be enabled by installing {{Pkg|vim-systemd}} from the [[Official Repositories|official repositories]].

== Targets ==

== Targets ==

−

'''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''' ''target''s that mimic the common SystemVinit runlevels so you can still switch ''target''s using the familiar {{ic|telinit RUNLEVEL}} command.

+

''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 ''target''s are implemented by inheriting all of the services of another ''target'' and adding additional services to it. There are ''systemd'' ''target''s that mimic the common SystemVinit runlevels so you can still switch ''target''s using the familiar {{ic|telinit RUNLEVEL}} command.

=== Get current targets ===

=== Get current targets ===

−

The following should be used under '''systemd''' instead of {{ic|$ runlevel}}:

+

The following should be used under ''systemd'' instead of running {{ic|runlevel}}:

$ systemctl list-units --type=target

$ systemctl list-units --type=target

Line 491:

Line 318:

=== Create custom 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 {{ic|/etc/systemd/system/<your target>}} that takes one of the existing runlevels as a base (you can look at {{ic|/usr/lib/systemd/system/graphical.target}} as an example), make a directory {{ic|/etc/systemd/system/<your target>.wants}}, and then symlink the additional services from {{ic|/usr/lib/systemd/system/}} that you wish to enable.

+

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 {{ic|/etc/systemd/system/''your target''}} that takes one of the existing runlevels as a base (you can look at {{ic|/usr/lib/systemd/system/graphical.target}} as an example), make a directory {{ic|/etc/systemd/system/''your target''.wants}}, and then symlink the additional services from {{ic|/usr/lib/systemd/system/}} that you wish to enable.

=== Targets table ===

=== Targets table ===

Line 516:

Line 343:

=== Change current target ===

=== Change current target ===

−

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

+

In ''systemd'' targets are exposed via ''target units''. You can change them like this:

# systemctl isolate graphical.target

# systemctl isolate graphical.target

Line 524:

Line 351:

=== Change default target to boot into ===

=== Change default target to boot into ===

−

The standard target is {{ic|default.target}}, which is aliased by default to {{ic|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:

+

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:

−

{{Tip|The {{ic|.target}} extension can be left out.}}

+

{{Tip|The ''.target'' extension can be left out.}}

* {{ic|1=systemd.unit=multi-user.target}} (which roughly corresponds to the old runlevel 3),

* {{ic|1=systemd.unit=multi-user.target}} (which roughly corresponds to the old runlevel 3),

* {{ic|1=systemd.unit=rescue.target}} (which roughly corresponds to the old runlevel 1).

* {{ic|1=systemd.unit=rescue.target}} (which roughly corresponds to the old runlevel 1).

−

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

+

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

# systemctl enable multi-user.target

# systemctl enable multi-user.target

−

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

+

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

[Install]

[Install]

Alias=default.target

Alias=default.target

−

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

+

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

+

+

== Timers ==

+

+

Systemd can replace cron functionality to a great extent. For further information, please refer to [[systemd/cron functionality]].

== Journal ==

== Journal ==

−

systemd has its own logging system called the journal; therefore, running a syslog daemon is no longer required. To read the log, use:

+

''systemd'' has its own logging system called the journal; therefore, running a syslog daemon is no longer required. To read the log, use:

# journalctl

# journalctl

−

By default (when {{ic|1=Storage=}} is set to {{ic|auto}} in {{ic|/etc/systemd/journald.conf}}), the journal writes to {{ic|/var/log/journal/}}. The directory {{ic|/var/log/journal/}} is a part of the {{Pkg|systemd}} package. If you or some program delete that directory, systemd will '''not''' recreate it automatically; however, it will be recreated during the next update of the systemd package. Until then, logs will be written to {{ic|/run/systemd/journal}}, and logs will be lost on reboot.

+

As in Arch Linux the directory {{ic|/var/log/journal/}} is part of the ''systemd'' package, the journal (when {{ic|1=Storage=}} is set to {{ic|auto}} in {{ic|/etc/systemd/journald.conf}}) will write to {{ic|/var/log/journal/}}. If you or some program delete that directory, systemd will '''not''' recreate it automatically; however, it will be recreated during the next update of the systemd package. Until then, logs will be written to {{ic|/run/systemd/journal}}, and logs will be lost on reboot.

+

+

{{Tip|If {{ic|/var/log/journal/}} resides in a [[btrfs]] filesystem you should consider disabling [[Btrfs#Copy-On-Write_.28CoW.29|Copy-on-Write]] for the directory:

+

# chattr +C /var/log/journal

+

}}

=== Filtering output ===

=== Filtering output ===

−

{{ic|journalctl}} allows you to filter the output by specific fields.

+

''journalctl'' allows you to filter the output by specific fields.

Examples:

Examples:

Line 567:

Line 402:

provided, that the previous boot happened today. Be aware that, if there are many messages for the current day, the output of this command can be delayed for quite some time.

provided, that the previous boot happened today. Be aware that, if there are many messages for the current day, the output of this command can be delayed for quite some time.

+

{{note|This needs to be corrected once 206 lands. {{ic|journalctl -b}} now takes arguments such as {{ic|-0}} for the last boot or a boot id. E.g. {{ic|journalctl -b -3}} will show all messages from the fourth to last boot.}}

4. We see that some of the kernel module configs have wrong settings. Therefore we have a look at these settings in {{ic|/etc/modules-load.d/}}:

+

$ ls -al /etc/modules-load.d/

+

total 44

+

drwxr-xr-x 2 root root 4096 14. Jul 11:01 .

+

drwxr-xr-x 114 root root 12288 25. Aug 11:40 ..

+

-rw-r--r-- 1 root root 79 1. Dez 2012 blacklist.conf

+

-rw-r--r-- 1 root root 1 2. Mär 14:30 encrypt.conf

+

-rw-r--r-- 1 root root 3 5. Dez 2012 printing.conf

+

-rw-r--r-- 1 root root 6 14. Jul 11:01 realtek.conf

+

-rw-r--r-- 1 root root 65 2. Jun 23:01 virtualbox.conf

+

+

5. The {{ic|Failed to find module 'blacklist usblp'}} error message might be related to a wrong setting inside of {{ic|blacklist.conf}}. Lets deactivate it with inserting a trailing '''#''' before each option we found via step 3:

+

$ nano /etc/modules-load.d/blacklist.conf

+

'''#''' blacklist usblp

+

'''#''' install usblp /bin/false

−

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 [http://freedesktop.org/wiki/Software/systemd/Debugging#Shutdown_Completes_Eventually this article].

+

6. Now, try to start {{ic|systemd-modules-load}}:

+

$ systemctl start systemd-modules-load.service

+

If it was successful, this shouldn't prompt anything. If you see any error, go back to step 3. and use the new PID for solving the errors left.

−

=== Short lived processes do not seem to log any output ===

+

If everything is ok, you can verify that the service was started successfully with:

If {{ic|journalctl -u foounit}} does not show any output for a short lived service, look at the PID instead. For example, if {{ic|systemd-modules-load.service}} fails, and {{ic|systemctl status systemd-modules-load}} shows that it ran as PID 123, then you might be able to see output in the journal for that PID, i.e. {{ic|journalctl -b _PID&#61;123}}. Metadata fields for the journal such as _SYSTEMD_UNIT and _COMM are collected asynchronously and rely on the {{ic|/proc}} directory for the process existing. Fixing this requires fixing the kernel to provide this data via a socket connection, similar to SCM_CREDENTIALS.

+

Often you can solve these kind of problems like shown above. For further investigation look at the following caption "'''Diagnosing boot problems'''"

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 [http://freedesktop.org/wiki/Software/systemd/Debugging/#shutdowncompleteseventually this article].

+

+

=== Short lived processes do not seem to log any output ===

+

+

If {{ic|journalctl -u foounit}} does not show any output for a short lived service, look at the PID instead. For example, if {{ic|systemd-modules-load.service}} fails, and {{ic|systemctl status systemd-modules-load}} shows that it ran as PID 123, then you might be able to see output in the journal for that PID, i.e. {{ic|journalctl -b _PID&#61;123}}. Metadata fields for the journal such as _SYSTEMD_UNIT and _COMM are collected asynchronously and rely on the {{ic|/proc}} directory for the process existing. Fixing this requires fixing the kernel to provide this data via a socket connection, similar to SCM_CREDENTIALS.

=== Disabling application crash dumps journaling ===

=== Disabling application crash dumps journaling ===

−

To get back normal core dump files, edit the following file in order to overwrite the settings from {{ic|/lib/sysctl.d/}}:

+

Run the following in order to overwrite the settings from {{ic|/lib/sysctl.d/}}:

−

{{hc|/etc/sysctl.d/49-coredump.conf|2=<nowiki>

+

# ln -s /dev/null /etc/sysctl.d/50-coredump.conf

−

kernel.core_pattern = core

+

# sysctl kernel.core_pattern=core

−

kernel.core_uses_pid = 0</nowiki>}}

+

−

Then run:

+

This will disable logging of coredumps to the journal.

−

# /usr/lib/systemd/systemd-sysctl

−

As before, you also need to “unlimit” the core files size in the shell:

+

Note that the default RLIMIT_CORE of 0 means that no core files are written, either.

+

If you want them, you also need to "unlimit" the core file size in the shell:

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.

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

Installation procedure

Once completed you may enable any desired services via the use of systemctl enable service_name (this roughly equates to what you included in the DAEMONS array. New names can be found in Daemons List).

Reboot your system and verify that systemd is currently active by issuing the following command: cat /proc/1/comm. This should return the string systemd.

Make sure your hostname is set correctly under systemd: hostnamectl set-hostname myhostname or /etc/hostname.

Proceed to remove initscripts and sysvinit from your system and install systemd-sysvcompat.

Optionally, remove the init=/usr/lib/systemd/systemd parameter. It is no longer needed since systemd-sysvcompat provides a symlink to systemd's init where sysvinit used to be.

Supplementary information

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

It is not necessary to add your user to groups (sys, disk, lp, network, video, audio, optical, storage, scanner, power, etc.) for most use cases with systemd. The groups can even cause some functionality to break. For example, the audio group will break fast user switching and allows applications to block software mixing. Every PAM login provides a logind session, which for a local session will give you permissions via POSIX ACLs on audio/video devices, and allow certain operations like mounting removable storage via udisks.

Using units

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 short forms when specifying the unit in the following systemctl commands:

If you do not specify the suffix, systemctl will assume .service. For example, netcfg and netcfg.service are equivalent.

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

Similar 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: Services without an [Install] section are usually called automatically by other services. 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

Reload systemd, scanning for new or changed units:

# systemctl daemon-reload

Power management

polkit is necessary for power management. If you are in a local systemd-logind 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.

The default setup will automatically fsck and mount filesystems before starting services that need them to be mounted. For example, systemd automatically makes sure that remote filesystem mounts like NFS or Samba are only started after the network has been set up. Therefore, local and remote filesystem mounts specified in /etc/fstab should work out of the box.

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 checked by fsck. This can be achieved by adding the following options to the /etc/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.

Note: This will make your /home filesystem type autofs, which is ignored by mlocate by default. The speedup of automounting /home may not be more than a second or two, depending on your system, so this trick may not be worth it.

The same applies to remote filesystem mounts. If you want them to be mounted only upon access, you will need to use the noauto,x-systemd.automount parameters. In addition, you can use the x-systemd.device-timeout=# option to specify a timeout in case the network resource is not available.

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 does not have to wait for the device to become available. For example:

Temporary files

"systemd-tmpfiles creates, deletes and cleans up volatile and temporary files and directories." It reads configuration files in /etc/tmpfiles.d/ and /usr/lib/tmpfiles.d/ to discover which actions to perform. Configuration files in the former directory take precedence over those in the latter directory.

Configuration files are usually provided together with service files, and they are named in the style of /usr/lib/tmpfiles.d/program.conf. For example, the Samba daemon expects the directory /run/samba to exist and to have the correct permissions. Therefore, the samba package ships with this configuration:

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

D /run/samba 0755 root root

Configuration files may also be used to write values into certain files on boot. For example, if you used /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

See the systemd-tmpfiles and tmpfiles.d(5) man pages for details.

Note: This method may not work to set options in /sys since the systemd-tmpfiles-setup service may run before the appropriate device modules is loaded. In this case you could check whether the module has a parameter for the option you want to set with modinfo module and set this option with a config file in /etc/modprobe.d. Otherwise you will have to write a udev rule to set the appropriate attribute as soon as the device appears.

Writing custom .service files

The syntax of systemd's unit files is inspired by XDG Desktop Entry Specification .desktop files, which are in turn inspired by Microsoft Windows .ini 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 (default): systemd considers the service 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 service 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. 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=yes 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. The reference implementation for this notification is provided by libsystemd-daemon.so.

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

Editing provided unit files

To edit a unit file provided by a package, you can create a directory called /etc/systemd/system/unit.d/ for example /etc/systemd/system/httpd.service.d/ and place *.conf files in there to override or add new options. systemd will parse these *.conf files and apply them on top of the original unit. For example, if you simply want to add an additional dependency to a unit, you may create the following file:

/etc/systemd/system/unit.d/customdependency.conf

[Unit]
Requires=new dependency
After=new dependency

Then run the following for your changes to take effect:

# systemctl daemon-reload
# systemctl restart unit

Alternatively you can copy the old unit file from /usr/lib/systemd/system/ to /etc/systemd/system/ and make your changes there. A unit file in /etc/systemd/system/ always overrides the same unit in /usr/lib/systemd/system/. Note that when the original unit in /usr/lib/ is changed due to a package upgrade, these changes will not automatically apply to your custom unit file in /etc/. Additionally you will have to manually reenable the unit with systemctl reenable unit. It is therefore recommended to use the *.conf method described before instead.

Tip: You can use systemd-delta to see which unit files have been overridden and what exactly has been changed.

As the provided unit files will be updated from time to time, use systemd-delta for system maintenance.

Syntax highlighting for units within Vim

Targets

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 systemdtargets that mimic the common SystemVinit runlevels so you can still switch targets using the familiar telinit RUNLEVEL command.

Get current targets

The following should be used under systemd instead of running 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 systemdtarget. 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 systemdtarget 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 target

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

# systemctl isolate graphical.target

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

Change default 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:

Tip: The .target extension can be left out.

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 output 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.

Timers

Journal

systemd has its own logging system called the journal; therefore, running a syslog daemon is no longer required. To read the log, use:

# journalctl

As in Arch Linux the directory /var/log/journal/ is part of the systemd package, the journal (when Storage= is set to auto in /etc/systemd/journald.conf) will write to /var/log/journal/. If you or some program delete that directory, systemd will not recreate it automatically; however, it will be recreated during the next update of the systemd package. Until then, logs will be written to /run/systemd/journal, and logs will be lost on reboot.

Tip: If /var/log/journal/ resides in a btrfs filesystem you should consider disabling Copy-on-Write for the directory:

# chattr +C /var/log/journal

Filtering output

journalctl allows you to filter the output by specific fields.

Examples:

Show all messages from this boot:

# journalctl -b

However, often one is interested in messages not from the current, but from the previous boot (e.g. if an unrecoverable system crash happened). Currently, this feature is not implemented, though there was a discussion at systemd-devel@lists.freedesktop.org (September/October 2012).

Journal size limit

If the journal is persistent (non-volatile), its size limit is set to a default value of 10% of the size of the respective file system. For example, 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 syslog

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). The syslog-ng package in the repositories automatically provides the necessary configuration.

5. The Failed to find module 'blacklist usblp' error message might be related to a wrong setting inside of blacklist.conf. Lets deactivate it with inserting a trailing # before each option we found via step 3:

Diagnosing boot problems

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.

Short lived processes do not seem to log any output

If journalctl -u foounit does not show any output for a short lived service, look at the PID instead. For example, if systemd-modules-load.service fails, and systemctl status systemd-modules-load shows that it ran as PID 123, then you might be able to see output in the journal for that PID, i.e. journalctl -b _PID=123. Metadata fields for the journal such as _SYSTEMD_UNIT and _COMM are collected asynchronously and rely on the /proc directory for the process existing. Fixing this requires fixing the kernel to provide this data via a socket connection, similar to SCM_CREDENTIALS.

Disabling application crash dumps journaling

Run the following in order to overwrite the settings from /lib/sysctl.d/: