Difference between revisions of "Systemd"
m (→Initscripts emulation) |
(→Power management: halt actually doesn't work without root, even in a logind session and there is no reason to use it anyway.) |
||
(38 intermediate revisions by 17 users not shown) | |||
Line 5: | Line 5: | ||
[[fr:Systemd]] | [[fr:Systemd]] | ||
[[it:Systemd]] | [[it:Systemd]] | ||
+ | [[ja:Systemd]] | ||
[[ru:Systemd]] | [[ru:Systemd]] | ||
[[zh-CN:Systemd]] | [[zh-CN:Systemd]] | ||
Line 10: | Line 11: | ||
{{Article summary text|Covers how to install and configure systemd.}} | {{Article summary text|Covers how to install and configure systemd.}} | ||
{{Article summary heading|Related}} | {{Article summary heading|Related}} | ||
− | {{Article summary wiki| | + | {{Article summary wiki|systemd/User}} |
− | {{Article summary wiki| | + | {{Article summary wiki|systemd/Services}} |
− | {{Article summary wiki| | + | {{Article summary wiki|systemd FAQ}} |
+ | {{Article summary wiki|init Rosetta}} | ||
{{Article summary wiki|udev}} | {{Article summary wiki|udev}} | ||
{{Article summary end}} | {{Article summary end}} | ||
Line 23: | Line 25: | ||
See also the [[Wikipedia:Systemd|Wikipedia article]]. | See also the [[Wikipedia:Systemd|Wikipedia article]]. | ||
− | == | + | == Considerations before switching == |
* It is highly recommended to switch to the new '''initscripts''' configuration system described in the [[rc.conf|rc.conf article]]. Once you have this configuration established, you will have done most of the work needed to make the switch to systemd. | * It is highly recommended to switch to the new '''initscripts''' configuration system described in the [[rc.conf|rc.conf article]]. Once you have this configuration established, you will have done most of the work needed to make the switch to systemd. | ||
Line 29: | Line 31: | ||
* Note the fact that systemd has a '''journal''' system that replaces '''syslog''', although the two can co-exist. See the [[#Journal|section on the journal]] below. | * Note the fact that systemd has a '''journal''' system that replaces '''syslog''', although the two can co-exist. See the [[#Journal|section on the journal]] below. | ||
* While systemd can replace some of the functionality of '''cron''', '''acpid''', or '''xinetd''', there is no need to switch away from using the traditional daemons unless you want to. | * While systemd can replace some of the functionality of '''cron''', '''acpid''', or '''xinetd''', there is no need to switch away from using the traditional daemons unless you want to. | ||
+ | * Interactive initscripts are not working with systemd. In particular, '''netcfg-menu''' [https://bugs.archlinux.org/task/31377 cannot] be used at system start-up. | ||
== Installation == | == Installation == | ||
+ | {{Note|{{pkg|systemd}} and {{pkg|systemd-sysvcompat}} are both installed by default on installation media newer than [https://www.archlinux.org/news/systemd-is-now-the-default-on-new-installations/ 2012-10-13].}} | ||
+ | The following section is aimed at Arch Linux installations that still rely on {{pkg|sysvinit}} and {{pkg|initscripts}} which have not migrated to {{pkg|systemd}}. | ||
− | + | # Install {{pkg|systemd}} and append the following to your [[kernel line]]: {{ic|1=init=/usr/lib/systemd/systemd}} | |
− | + | # 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). | |
− | + | # Reboot your system and verify that {{ic|systemd}} is currently active by using the following command: {{ic|$ cat /proc/1/comm}}. This should return the string {{ic|systemd}}. | |
− | + | # Proceed to remove {{pkg|initscripts}} and {{pkg|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. | |
− | |||
− | |||
− | |||
− | |||
− | # | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
=== Supplementary information === | === Supplementary information === | ||
Line 79: | Line 49: | ||
* Adding your user to [[Users and Groups|groups]] ({{ic|optical}}, {{ic|audio}}, {{ic|scanner}}, etc.) is '''not''' necessary 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 [[Wikipedia:Access control list|POSIX ACLs]] on audio/video devices, and allow certain operations like mounting removable storage via [[udisks]]. | * Adding your user to [[Users and Groups|groups]] ({{ic|optical}}, {{ic|audio}}, {{ic|scanner}}, etc.) is '''not''' necessary 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 [[Wikipedia:Access control list|POSIX ACLs]] on audio/video devices, and allow certain operations like mounting removable storage via [[udisks]]. | ||
− | {{ | + | * Removing {{Pkg|initscripts}} package will break compatibility with {{ic|rc.conf}}. Be careful if you have static network set up there or use some daemons, which are not migrated to systemd yet. See the [[#Initscripts emulation|Initscripts emulation section]] for more details on how the two systems can coexist. |
== Native configuration == | == Native configuration == | ||
Line 124: | Line 94: | ||
FONT_MAP=8859-1_to_uni}} | FONT_MAP=8859-1_to_uni}} | ||
− | {{Note|As of {{pkg|systemd-194 | + | {{Note|As of {{pkg|systemd}}-194, the built-in ''kernel'' font and the ''us'' keymap are used if {{ic|1=KEYMAP=}} and {{ic|1=FONT=}} are empty or not set.}} |
Another way to set the keyboard mapping (keymap) is doing: | Another way to set the keyboard mapping (keymap) is doing: | ||
Line 142: | Line 112: | ||
# timedatectl set-timezone America/Toronto | # timedatectl set-timezone America/Toronto | ||
− | See {{ic|man 1 timedatectl}} | + | See {{ic|man 1 timedatectl}}, {{ic|man 5 localtime}}, and {{ic|man 7 archlinux}} for more details. |
Alternatively, create the symlink yourself: | Alternatively, create the symlink yourself: | ||
− | + | <!-- DO NOT MAKE THIS AN ABSOLUTE SYMLINK, archlinux(7) clearly shows this should be a relative symlink --> | |
# ln -sf ../usr/share/zoneinfo/America/Toronto /etc/localtime | # ln -sf ../usr/share/zoneinfo/America/Toronto /etc/localtime | ||
Line 166: | Line 136: | ||
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). | 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# | + | 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]]. There, it is recommended that Windows are changed 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 don't 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. |
* For more information, see [[Time]]. | * For more information, see [[Time]]. | ||
Line 196: | Line 166: | ||
==== Automount ==== | ==== Automount ==== | ||
− | * 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 being fsck'ed. This can be achieved by adding the following options to the fstab entry of your {{ic|/home}} partition: | + | * 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 being fsck'ed. This can be achieved by adding the following options to the {{ic|/etc/fstab}} entry of your {{ic|/home}} partition: |
noauto,x-systemd.automount | noauto,x-systemd.automount | ||
Line 221: | Line 191: | ||
=== ACPI power management === | === ACPI power management === | ||
− | Systemd handles some power-related [ | + | 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|HandlePowerKey}}: specifies which action is invoked when the power key is pressed. | ||
Line 236: | Line 206: | ||
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. | 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 | + | {{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. New versions are on the way that will include this functionality.}} |
{{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.}} | {{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.}} | ||
Line 422: | Line 392: | ||
$ systemctl poweroff | $ systemctl poweroff | ||
− | |||
− | |||
− | |||
− | |||
Suspend the system: | Suspend the system: | ||
Line 575: | Line 541: | ||
Examples: | Examples: | ||
+ | |||
+ | Show all messages from this boot: | ||
+ | |||
+ | # journalctl -b | ||
+ | |||
+ | Follow new messages: | ||
+ | |||
+ | # journalctl -f | ||
Show all messages by a specific executable: | Show all messages by a specific executable: | ||
Line 588: | Line 562: | ||
# journalctl -u netcfg | # journalctl -u netcfg | ||
− | See {{ic|man journalctl}} | + | See {{ic|man journalctl}}, {{ic|systemd.journal-fields}} or Lennert's [http://0pointer.de/blog/projects/journalctl.html blog post] for details. |
=== Journal size limit === | === Journal size limit === | ||
Line 653: | Line 627: | ||
Change {{ic|verbose}} to {{ic|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. | Change {{ic|verbose}} to {{ic|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. | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
== Troubleshooting == | == Troubleshooting == |
Revision as of 12:42, 18 November 2012
zh-CN:Systemd Template:Article summary start Template:Article summary text Template:Article summary heading Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary wiki Template:Article summary end From the project web page:
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.
See also the Wikipedia article.
Contents
- 1 Considerations before switching
- 2 Installation
- 3 Native configuration
- 4 Transitioning from initscripts to systemd
- 5 Basic systemctl usage
- 6 Running DEs under systemd
- 7 Writing custom .service files
- 8 Targets
- 9 Journal
- 10 Optimization
- 11 Troubleshooting
- 12 See also
Considerations before switching
- 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.
- Do some reading about 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.
- While systemd can replace some of the functionality of cron, acpid, or xinetd, there is no need to switch away from using the traditional daemons unless you want to.
- Interactive initscripts are not working with systemd. In particular, netcfg-menu cannot be used at system start-up.
Installation
The following section is aimed at Arch Linux installations that still rely on sysvinit and initscripts which have not migrated to systemd.
- Install systemd and append the following to your kernel line:
init=/usr/lib/systemd/systemd
- Once completed you may enable any desired services via the use of
systemctl enable <service_name>
(this roughly equates to what you included in theDAEMONS
array). - Reboot your system and verify that
systemd
is currently active by using the following command:$ cat /proc/1/comm
. This should return the stringsystemd
. - Proceed to remove initscripts and sysvinit from your system and install systemd-sysvcompat.
- Optionally, remove the
init=/usr/lib/systemd/systemd
parameter as it is no longer needed. systemd-sysvcompat provides the default init.
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.
- Adding your user to groups (
optical
,audio
,scanner
, etc.) is not necessary 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.
- Removing initscripts package will break compatibility with
rc.conf
. Be careful if you have static network set up there or use some daemons, which are not migrated to systemd yet. See the Initscripts emulation section for more details on how the two systems can coexist.
Native configuration
Hostname
The hostname is configured in /etc/hostname
. The file should not contain the system's domain, if any. To set the hostname, do:
# hostnamectl set-hostname myhostname
See man 5 hostname
and man 1 hostnamectl
for details.
Here is an example file:
/etc/hostname
myhostname
Locale
The default system locale is configured in /etc/locale.conf
. To set the default locale, do:
# localectl set-locale LANG="de_DE.utf8"
/etc/locale.gen
and then executing locale-gen
as root. The locale set via localectl
must be one of the uncommented locales in /etc/locale.gen
.See man 1 localectl
and man 5 locale.conf
for details.
- For more information, see Locale.
Here is an example file:
/etc/locale.conf
LANG=en_US.utf8
Virtual console
The virtual console (keyboard mapping, console font and console map) is configured in /etc/vconsole.conf
:
/etc/vconsole.conf
KEYMAP=us FONT=lat9w-16 FONT_MAP=8859-1_to_uni
KEYMAP=
and FONT=
are empty or not set.Another way to set the keyboard mapping (keymap) is doing:
# localectl set-keymap de
This has the advantage that it will also set the same keymap for use in X11.
See man 1 localectl
and man 5 vconsole.conf
for details.
- For more information, see console fonts and keymaps.
Time zone
The time zone is configured by creating an appropriate /etc/localtime
symlink, pointing to a zoneinfo file under /usr/share/zoneinfo/
. To do this automatically:
# timedatectl set-timezone America/Toronto
See man 1 timedatectl
, man 5 localtime
, and man 7 archlinux
for more details.
Alternatively, create the symlink yourself:
# ln -sf ../usr/share/zoneinfo/America/Toronto /etc/localtime
Hardware clock
Systemd will use UTC for the hardware clock by default.
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 (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 (which uses localtime). However, Windows is able to deal with the RTC being in UTC with a simple registry fix. There, it is recommended that Windows are changed 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 don't 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.
- For more information, see Time.
Kernel modules
Today, all necessary module loading is handled automatically by udev, so that, if you don't want/need to use any out-of-tree kernel modules, there is no need to put modules that should be loaded at boot in any config file. However, there are cases where you might want to load an extra module during the boot process, or blacklist another one for your computer to function properly.
Extra modules to load at boot
Extra kernel modules to be loaded during boot are configured as a static list in files under /etc/modules-load.d/
. Each configuration file is named in the style of /etc/modules-load.d/<program>.conf
. Configuration files 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.
/etc/modules-load.d/virtio-net.conf
# Load virtio-net.ko at boot virtio-net
See man 5 modules-load.d
for more details.
Blacklisting
Module blacklisting works the same way as with initscripts since it is actually handled by kmod. See Module Blacklisting for details.
Filesystem mounts
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.
See man 5 systemd.mount
for details.
Automount
- 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/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.
- 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 thex-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 doesn't have to wait for the device to become available. For example:
/etc/crypttab
data /dev/md0 /root/key noauto
LVM
If you have LVM volumes not activated via the initramfs, enable lvm.service
(provided by the lvm2 package):
# systemctl enable lvm
Similarly, if you have LVM on encrypted devices mounted later during boot (e.g. from /etc/crypttab
), enable lvm-on-crypt.service
(also provided by the lvm2 package):
# systemctl enable lvm-on-crypt
ACPI power management
Systemd handles some power-related ACPI events. They can be configured via the following options from /etc/systemd/logind.conf
:
-
HandlePowerKey
: specifies which action is invoked when the power key is pressed. -
HandleSuspendKey
: specifies which action is invoked when the suspend key is pressed. -
HandleHibernateKey
: specifies which action is invoked when the hibernate key is pressed. -
HandleLidSwitch
: specifies which action is invoked when the lid is closed.
The specified action can be one of ignore
, poweroff
, reboot
, halt
, suspend
, hibernate
or kexec
.
If these options are not configured, systemd will use its defaults: HandlePowerKey=poweroff
, HandleSuspendKey=suspend
, HandleHibernateKey=hibernate
, and 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.
In the current version of systemd, the 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.
Handle
options to ignore
if you want your ACPI events to be handled by Xfce, acpid or other programs. New versions are on the way that will include this functionality.Sleep hooks
Systemd does not use pm-utils to put the machine to sleep when using systemctl suspend
or systemctl hibernate
; pm-utils hooks, including any custom hooks, 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/
, passing two arguments to each of them:
- Argument 1: either
pre
orpost
, depending on whether the machine is going to sleep or waking up - Argument 2: either
suspend
orhibernate
, 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
or systemd-hibernate.service
. You can see its output in systemd's journal:
# journalctl -b -u systemd-suspend
Note that you can also use sleep.target
, suspend.target
or hibernate.target
to hook units into the sleep state logic instead of using custom scripts.
An example of a custom sleep script:
/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
See man 7 systemd.special
and man 8 systemd-sleep
for more details.
Temporary files
Systemd-tmpfiles uses 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 5 tmpfiles.d
for details.
Units
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 5 systemd.unit
for details.
Transitioning from initscripts to systemd
Initscripts emulation
Integration with Arch's classic configuration is provided by the initscripts package. When initscripts are installed in parallel with systemd, with the system running on systemd, systemd will do the following:
- Parse the
DAEMONS
array of/etc/rc.conf
and start all listed daemons at boot - Execute
/etc/rc.local
during boot - Execute
/etc/rc.local.shutdown
during shutdown
Initscripts emulation is simply meant as a transitional measure to ease users' move to systemd, and will eventually go away. Native systemd does not rely on rc.conf
centralised configuration, so it is recommended to use native systemd configuration files, which will take precedence over /etc/rc.conf
.
/etc/rc.local
is to write the custom service files for any things you want to run on the system startup. See the corresponding section./etc/inittab
, you will have to reconfigure this setting for systemd by running systemctl mask ctrl-alt-del.target
as root.Moving away from the DAEMONS array
For a pure systemd setup, you should remove the /etc/rc.conf
file entirely and enable services only via systemctl
. For each <service_name>
in the DAEMONS
array in /etc/rc.conf
, run:
# systemctl enable <service_name>
If <service_name>.service
does not exist:
- Most probably, systemd uses a different name. For example,
cronie.service
replaces thecrond
init daemon;alsa-store.service
andalsa-restore.service
replace thealsa
init daemon. Another important instance is thenetwork
daemon, which is replaced with another set of service files (see Configuring Network for more details.) - Otherwise, a 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.
$ pacman -Ql cronie [...] cronie /etc/rc.d/crond #Daemon initscript listed in the DAEMONS array (unused in a "pure" systemd configuration) [...] cronie /usr/lib/systemd/system/cronie.service #Corresponding systemd daemon service [...]
- Finally, some services do not need to be explicitly enabled by the user. For instance,
dbus.service
will automatically be enabled whendbus-core
is installed.alsa-store.service
andalsa-restore.service
are also enabled automatically by systemd. Check the list of available services and their state using thesystemctl
command like this:systemctl status <service_name>
.
Basic systemctl usage
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 man 1 systemctl
for more details.
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.systemadm
is the official graphical frontend for systemctl
. It is provided by the systemd-ui-gitAUR package from the AUR.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
andnetcfg.service
are treated equivalent. - Mount points will automatically be translated into the appropriate
.mount
unit. For example, specifying/home
is equivalent tohome.mount
. - Similiar to mount points, devices are automatically translated into the appropriate
.device
unit, therefore specifying/dev/sda2
is equivalent todev-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>
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.
# ln -s /usr/lib/systemd/system/foo.service /etc/systemd/system/graphical.target.wants/
Disable a unit to not start during bootup:
# systemctl disable <unit>
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 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:
$ systemctl reboot
Shut down and power-off the system:
$ systemctl poweroff
Suspend the system:
$ systemctl suspend
Put the system into hibernation:
$ systemctl hibernate
Running DEs under systemd
To enable graphical login, run your preferred Display Manager daemon (e.g. KDM). At the moment, service files exist for GDM, KDM, SLiM, XDM, LXDM and LightDM.
# systemctl enable kdm
This should work out of the box. If not, you might have a default.target
set manually or from a older install:
# ls -l /etc/systemd/system/default.target
/etc/systemd/system/default.target -> /usr/lib/systemd/system/graphical.target
Simply delete the symlink and systemd will use its stock default.target
(i.e. graphical.target
).
# rm /etc/systemd/system/default.target
Using systemd-logind
In order to check the status of your user session, you can use loginctl
. All PolicyKit actions like suspending the system or mounting external drives will work out of the box.
$ loginctl show-session $XDG_SESSION_ID
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 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 specifyPIDFile=
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 setRemainAfterExit=
as well so that systemd still considers the service as active after the process has exited. -
Type=notify
: Identical toType=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 bylibsystemd-daemon.so
. -
Type=dbus
: The service is considered ready when the specifiedBusName
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:
/etc/systemd/system/<service-name>.service
.include /usr/lib/systemd/system/<service-name>.service [Unit] Requires=<new dependency> After=<new dependency>
Then run the following for your changes to take effect:
# systemctl reenable <unit> # systemctl restart <unit>
systemd-delta
to see which unit files have been overridden and what exactly has been changed.Syntax highlighting for units within Vim
Syntax highlighting for systemd unit files within Vim can be enabled by installing vim-systemdAUR from the AUR.
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 targets 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 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 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:
.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 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.
Journal
Since version 38, systemd has its own logging system, the journal. Therefore, running a syslog daemon is no longer required. To read the log, use:
# journalctl
By default (when Storage=
is set to auto
in /etc/systemd/journald.conf
), the journal writes to /var/log/journal/
. If the directory /var/log/journal/
does not exist (e.g. if you or some program delete it), systemd will not create it automatically, but instead write its logs to /run/systemd/journal
. This means that logs will be lost on reboot.
Filtering output
journalctl
allows you to filter the output by specific fields.
Examples:
Show all messages from this boot:
# journalctl -b
Follow new messages:
# journalctl -f
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 -u netcfg
See man journalctl
, systemd.journal-fields
or Lennert's blog post for details.
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. 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 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.
# systemctl enable syslog-ng
Optimization
Analyzing the boot process
Using 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 kernelspace and userspace on boot, simply use:
$ systemd-analyze
timestamp
hook to your HOOKS
array in /etc/mkinitcpio.conf
and as root, rebuild your initramfs with mkinitcpio -p linux
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 graphically, similiar to Bootchart:
$ systemd-analyze plot > plot.svg
Using bootchart
You could also 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:
# systemctl enable bootchart
Read the bootchart documentation for further details on using this version of bootchart.
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:
# systemctl enable systemd-readahead-collect systemd-readahead-replay
Remember that in order for the readahead to work its magic, you should reboot a couple of times.
Early start for services
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 UPower) 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 upower
This will cause systemd to start UPower as soon as possible, without causing races with the socket or D-Bus activation.
Less output during boot
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.
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.
See also
- Official Web Site
- Manual Pages
- systemd Optimizations
- FAQ
- Tips And Tricks
- systemd for Administrators (PDF)
- About systemd on Fedora Project
- How to debug systemd problems
- Booting up: Tools and tips for systemd, a Linux init tool. In The H
- Lennart's blog story
- status update
- status update2
- status update3
- most recent summary
- Fedora's SysVinit to systemd cheatsheet