System D
System D
System D
systemd
https://wiki.gentoo.org/wiki/Systemd
(/)
Wiki
Contents
1 Pre-installation Conguration
1.1 Kernel
1.2 The /run directory
1.3 /etc/mtab
1.4 Ensure /usr is present at boot time
1.5 Using LVM2 and initramfs
2 Installation
3 Booting with systemd
3.1 Grub Legacy (0.x)
3.2 Grub 2
3.3 In kernel cong
3.4 Setting root password
4 Post-installation conguration
4.1 Hostname
4.2 Locale
4.3 Time and date
4.4 Automatic module loading
4.5 Network
4.5.1 systemd-networkd
4.5.2 NetworkManager
4.6 Handling of log les
4.7 /tmp is now in tmpfs
4.8 Congure verbosity of boot process
5 Services
5.1 OpenRC services
5.2 Listing available services
5.3 Enabling, disabling, starting, and stopping services
5.4 Installing custom unit les
5.5 Customizing unit les
5.6 Enabling a service under a custom name
5.7 Native services
5.8 Timer services
5.8.1 Emailing failures
5.8.2 Replacing cron
6 Troubleshooting
6.1 Graphical sessions opened in random places
6.2 lvm
6.3 systemd-bootchart
6.4 syslog-ng conicts with systemd
6.5 sys-fs/cryptsetup conguration
6.6 Check for units that failed to start
6.7 Enable Debug Mode
6.8 e4rat usage
1 of 18
Resources
Home (http://freedesktop.org
/wiki/Software/systemd)
Wikipedia (http://en.wikipedia.org
/wiki/Systemd)
GitWeb (http://cgit.freedesktop.org
/systemd/systemd/)
09/03/2016 02:55
https://wiki.gentoo.org/wiki/Systemd
Pre-installation Configuration
Note
When updating from <=sys-apps/systemd-203 check the upgrade subpage (/wiki/Systemd/upgrade).
Kernel
systemd makes use of many modern Linux kernel features. Right now, the lower bound on kernel version is set in
the ebuild to 2.6.39. In recent versions of sys-kernel/gentoo-sources (https://packages.gentoo.org/packages
/sys-kernel/gentoo-sources), there is a convenient way of selecting the mandatory and optional kernel options for
systemd:
KERNEL
To congure the kernel options manually (which is the only option when not using sys-kernel/gentoo-sources
(https://packages.gentoo.org/packages/sys-kernel/gentoo-sources)), the following kernel conguration options are
required or recommended:
KERNEL
Mandatory options
KERNEL
2 of 18
Recommended options
09/03/2016 02:55
https://wiki.gentoo.org/wiki/Systemd
UEFI support
If the system is using the BFQ scheduler, it's recommended by BFQ upstream to enable "BFQ hierarchical
scheduling support" under "Enable the block layer -> IO Schedulers".
For an up-to-date list, see section "REQUIREMENTS" in the upstream README (http://cgit.freedesktop.org/systemd
/systemd/tree/README) le.
/etc/mtab
Upstream only supports the /etc/mtab le being a symlink to /proc/self/mounts. Not creating this symlink will
also cause problems with mount ( bug #434090 (https://bugs.gentoo.org/show_bug.cgi?id=434090)) and df (
bug #477240 (https://bugs.gentoo.org/show_bug.cgi?id=477240)). In the past some utilities wrote information (like
3 of 18
09/03/2016 02:55
https://wiki.gentoo.org/wiki/Systemd
mount options) into /etc/mtab and thus it was supposed to be a regular le. Nowadays all software is supposed to
avoid this problem. Still, before switching the le to become a symbolic link, please check bug #477498
(https://bugs.gentoo.org/show_bug.cgi?id=477498) to be sure that the system is not aected by any reported
regressions.
To create the symlink, run:
root # ln -sf /proc/self/mounts /etc/mtab
When using dracut, enable the usrmount module if it is not automatically enabled to mount /usr automatically.
FILE
/etc/dracut/dracut.conf
If using genkernel-next, before rebuilding the kernel, be sure to set the UDEV variable in genkernel's conguration
le to yes . This will pull /usr into the initramfs:
FILE
/etc/genkernel.conf
# Use udev instead of mdev as the default device manager for the initramfs.
# If you use systemd and perhaps lvm, you _must_ keep this turned on.
UDEV="yes"
When LVM is used, the lvmetad daemon needs to be started as well. Otherwise systemd will be unable to mount
LVM volumes. lvmetad can be enabled in /etc/lvm/lvm.conf:
FILE
Note
Instead of modifying /etc/lvm/lvm.conf this could probably be achieved through a lvmetad.socket unit
4 of 18
09/03/2016 02:55
https://wiki.gentoo.org/wiki/Systemd
Installation
sys-apps/systemd (https://packages.gentoo.org/packages/sys-apps/systemd) contains udev. Once installed,
sys-fs/udev (https://packages.gentoo.org/packages/sys-fs/udev) can be removed as systemd will be the provider for
virtual/udev (https://packages.gentoo.org/packages/virtual/udev).
Enable the systemd USE ag globally (in make.conf). The consolekit USE ag should also be disabled to prevent
conicts with the systemd-logind service. It is also possible to switch to a systemd subprole to use saner USE
ags defaults in which case it is not necessary to change make.conf:
root # eselect profile list
Note
In case the migration yields a broken state, it is always possible to boot back into the default service manager
(OpenRC) by undoing this init change step. This allows safe return and a way to follow through the
troubleshooting section at the end of this article to x the problem.
The following subsections document how to switch the init in one of the boot managers or the kernel.
Should the system boot using OpenRC, try using real_init instead of init .
Grub 2
When grub2-mkconfig is used, add the init option to GRUB_CMDLINE_LINUX:
Note
This is not needed when using an initramfs generated by dracut with systemd inside as the initramfs already
starts systemd.
5 of 18
09/03/2016 02:55
FILE
https://wiki.gentoo.org/wiki/Systemd
When the GRUB 2 conguration le is written by hand (experts only), append the init= parameter to the linux or
linux16 command.
FILE
In kernel config
The init conguration can also be hard-coded in the kernel conguration. See Processor type and features ->
Built-in kernel command line. Note that this technique works for both grub and grub2.
Post-installation configuration
systemd supports a few system conguration les to set the most basic system details.
Note
While some system conguration parameters can be updated by modifying the appropriate conguration
les, most settings are managed using utilities that require systemd to be running. In this case, it is safe to
reboot the computer with systemd and use the hostnamectl, localectl, and timedatectl utilities as
required.
Hostname
To set the hostname, create/edit /etc/hostname and simply provide the desired hostname.
When booted using systemd, a tool called hostnamectl exists for editing /etc/hostname and /etc/machine-info.
To change the hostname, run:
root # hostnamectl set-hostname <HOSTNAME>
Locale
Usually, locales will be properly migrated from OpenRC when installing systemd. When required, the locale can be
set in /etc/locale.conf as per the Gentoo handbook instructions:
FILE
LANG="en_US.utf8"
Once booted with systemd, the tool localectl is used to set locale and console or X11 keymaps. To change the
system locale, run the following command:
6 of 18
09/03/2016 02:55
https://wiki.gentoo.org/wiki/Systemd
vboxdrv
vboxnetflt
vboxnetadp
vboxpci
Network
systemd-networkd
systemd-networkd is useful for simple conguration of wired network interfaces. It is disabled by default.
To congure systemd-networkd, create a *.network le under /etc/systemd/network. See systemd.network(5)
(http://www.freedesktop.org/software/systemd/man/systemd.network.html) for reference. A simple DHCP
conguration is given below:
FILE
/etc/systemd/network/50-dhcp.network
[Match]
Name=en*
[Network]
DHCP=yes
Note that systemd-networkd does not update resolv.conf by default. To have systemd manage the DNS settings,
replace resolv.conf with a symlink and start systemd-resolved.
root # ln -snf /run/systemd/resolve/resolv.conf /etc/resolv.conf
root # systemctl enable systemd-resolved.service
root # systemctl start systemd-resolved.service
NetworkManager
7 of 18
09/03/2016 02:55
https://wiki.gentoo.org/wiki/Systemd
Often NetworkManager is used to congure network settings. For that purpose, simply run the following command
when using an X11-powered desktop:
root # nm-connection-editor
If that is not the case and the network needs to be congured from console, give nmcli (https://access.redhat.com
/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Networking_Guide
/sec-Using_the_NetworkManager_Command_Line_Tool_nmcli.html) a try, or follow a guided conguration process
through nmtui:
root # nmtui
nmtui (https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Networking_Guide
/sec-Networking_Cong_Using_nmtui.html) is a curses frontend that will guide the user in the process while
running in console mode.
Result
journalctl without
options
-b , --boot
-r , --reverse
-f , --follow
Show the last few entries and display new log entries as they're being produced.
-p , --priority=
Specify (minimum) priority to display messages, with a choice from: "emerg" (0),
"alert" (1), "crit" (2), "err" (3), "warning" (4), "notice" (5), "info" (6), "debug" (7).
--since= , --until=
Restrict entries by time. Accepts the format "YYYY-MM-DD hh:mm:ss" or the strings
"yesterday", "today" and "tomorrow".
-n , --lines=
-k , --dmesg
-u , --unit=
For more information and many more options, look at man journalctl.
When not using the quiet boot option, some messages might be overwriting consoles. That is caused by the
8 of 18
09/03/2016 02:55
https://wiki.gentoo.org/wiki/Systemd
kernel conguration (see man 5 proc and look for /proc/sys/kernel/printk). To tweak it pass the
loglevel=5 boot parameter to the kernel (and update the value according to preference, for instance set a
Services
At some point the system will need to be rebooted in order to get systemd running (in system mode). Be sure to
read all of this document to ensure systemd is congured as completely as possible before rebooting. Note that
journalctl works with systemd not running, but that systemctl will not do anything useful without systemd
running. Complete the service conguration (enabling and starting of services) after logging in to the system
running systemd.
OpenRC services
Although systemd originally intended to support running old init.d scripts, that support is not suited well for a
dependency-based RC like OpenRC and thus is completely disabled on Gentoo. OpenRC provides additional
measures to ensure that init.d scripts can't be run when OpenRC was not used to boot the system (otherwise the
results would be unpredictable).
UNIT
boot.automount
proc-sys-fs-binfmt_misc.automount
...
LOAD
ACTIVE SUB
loaded active waiting
loaded active waiting
DESCRIPTION
EFI System Partition Automount
Arbitrary Executable File Formats File System Automo
Description
.service
.socket
.path
lesystem triggers for services (running services when les change etc.).
Alternatively the systemctl tool can be used to list all services (including implicit ones):
root # systemctl --all --full
These commands enable services using their default name in default target (both specied in "Install" section of
the service le). However, sometimes services either don't provide that information or users prefer to have
another name/target.
Note that these commands only enable or disable the system to be started on a next boot; to start the service right
now, use:
root # systemctl start foo.service
9 of 18
09/03/2016 02:55
https://wiki.gentoo.org/wiki/Systemd
[Service]
MemoryLimit=1G
MemoryLimit=1074000000
Native services
Some of Gentoo packages already install systemd unit les. For these services, it is enough to enable them. A quick
summary of packages installing unit les can be seen on systemd eclass users list (http://qa-reports.gentoo.org
/output/eclass-usage/systemd.txt).
The following table lists systemd services matching OpenRC ones:
Migration chart
Gentoo package
sys-apps/openrc
(https://packages.gentoo.org
/packages/sys-apps/openrc)
OpenRC service
systemd unit
Notes
bootmisc
systemd-tmplessetup.service
consolefont
systemd-vconsolesetup.service
devfs
dmesg
10 of 18
09/03/2016 02:55
https://wiki.gentoo.org/wiki/Systemd
fsck
fsck*.service
functions.sh
See note
bug #373219
(https://bugs.gentoo.org
/show_bug.cgi?id=373219)
hostname
(builtin)
/etc/hostname
hwclock
See note
keymaps
systemd-vconsolesetup.service
localmount
local-fs.target
modules
systemd-modulesload.service
killprocs
local
mount-ro
mtab
netmount
remote-fs.target
numlock
procfs
(builtin)
root
remount-rootfs.service
savecache
n/a
OpenRC internals
swap.target
sysctl
systemd-sysctl.service
sysfs
(builtin)
termencoding
systemd-vconsolesetup.service
urandom
systemd-randomseed-load.service
staticroute
swap
swclock
systemd-randomseed-save.service
11 of 18
09/03/2016 02:55
12 of 18
https://wiki.gentoo.org/wiki/Systemd
app-admin/rsyslog
(https://packages.gentoo.org
/packages/app-admin
/rsyslog)
rsyslog
rsyslog.service
app-admin/syslog-ng
(https://packages.gentoo.org
/packages/app-admin
/syslog-ng)
syslog-ng
syslog-ng.service
media-sound/alsa-utils
(https://packages.gentoo.org
/packages/mediasound/alsa-utils)
alsasound
alsa-store.service
(enabled by default)
alsa-restore.socket
(enabled by default)
net-misc/dhcpcd
(https://packages.gentoo.org
/packages/net-misc/dhcpcd)
dhcpcd
dhcpcd.service
net-misc/netifrc
(https://packages.gentoo.org
/packages/net-misc/netifrc)
net.*
net@.service
netctl@.service
net-misc/netctl is originally an
Arch Linux tool.
NetworkManager.service
For <networkmanager-0.9.8.4:
enable NetworkManagerdispatcher.service for
dispatcher.d scripts to work.
Enable NetworkManagerwait-online.service to detect that
the system has a working
internet connection.
Disable all other managers (e.g.,
wicd, dhcpcd) and
wpa_supplicant.
dhcpcd.service
Provided by net-misc/dhcpcd
systemd.networkd.service
Part of systemd
net-misc/openntpd
(https://packages.gentoo.org
/packages/net-misc
/openntpd)
ntpd
ntpd.service
net-misc/openssh
(https://packages.gentoo.org
/packages/net-misc
/openssh)
sshd
sshd.service
sshd.socket
net-wireless/wpa_supplicant
(https://packages.gentoo.org
/packages/net-wireless
/wpa_supplicant)
wpa-supplicant
wpa_supplicant.service
wpa_supplicant@.service
interface-specic wpa_supplicant
(used like
wpa_supplicant@wlan0.service)
09/03/2016 02:55
net-print/cups
(https://packages.gentoo.org
/packages/net-print/cups)
https://wiki.gentoo.org/wiki/Systemd
cupsd
cups.service
cups.socket
cups.path
net-wireless/bluez
(https://packages.gentoo.org
/packages/net-wireless
/bluez)
bluetooth
bluetooth.service
sys-apps/dbus
(https://packages.gentoo.org
/packages/sys-apps/dbus)
dbus
dbus.service
sys-apps/irqbalance
(https://packages.gentoo.org
/packages/sys-apps
/irqbalance)
irqbalance
sys-apps/microcode-ctl
(https://packages.gentoo.org
/packages/sys-apps
/microcode-ctl)
microcode_ctl
sys-fs/udev
(https://packages.gentoo.org
/packages/sys-fs/udev)
udev
udev.service
udev-mount
(builtin)
udev-postmount
udev-trigger.service
dbus.socket
irqbalance.service
Congure microcode as a
module to let it load the
microcode itself. Go to
"Processor type and features" ->
"CPU microcode loading
support" and remember to add
the option you need depending
on you having intel or amd
processor.
udev-settle.service
sys-power/acpid
(https://packages.gentoo.org
/packages/sys-power/acpid)
acpid
acpid.service
x11-apps/xdm
(https://packages.gentoo.org
/packages/x11-apps/xdm)
(xdm)
xdm.service
net-rewall/iptables
(https://packages.gentoo.org
/packages/net-rewall
/iptables)
iptables
iptables-store.service
iptables-restore.service
Timer services
Since version 197 systemd supports timers, making cron unnecessary on a systemd system. Since version 212
persistent services are supported, replacing even anacron. Persistent timers are run at the next opportunity if the
13 of 18
09/03/2016 02:55
https://wiki.gentoo.org/wiki/Systemd
[Unit]
Description=daily backup work
RefuseManualStart=no
RefuseManualStop=no
[Timer]
Persistent=false
OnCalendar=Mon-Fri *-*-* 11:30:00
Unit=backup-work.service
[Install]
WantedBy=default.target
FILE
[Unit]
Description=daily backup work
RefuseManualStart=no
RefuseManualStop=yes
[Service]
Type=oneshot
ExecStart=/home/<user>/scripts/backup-work.sh
Emailing failures
If a timed service runs and fails an e-mail can be send out to inform the user or administrator. This is possible with
the "OnFailure" stanza which species what should happen if a service fails. A failure is detected by a non-zero
return code of the invoked script.
For that change the script as follows:
FILE
14 of 18
09/03/2016 02:55
https://wiki.gentoo.org/wiki/Systemd
[Unit]
Description=daily backup work
RefuseManualStart=no
RefuseManualStop=yes
OnFailure=failure-email@%i.service
[Service]
Type=oneshot
ExecStart=/home/<user>/scripts/backup-work.sh
This requires to have the service failure-email@.service installed, which can be found in kylemanna's
systemd-utils repository (https://github.com/kylemanna/systemd-utils/tree/master/onfailure).
Replacing cron
The above timer and service les can also be added to /usr/lib/systemd/system to make them available
system-wide. The install section should then say WantedBy=multi-user.target to enable the service at system start.
However, cron also runs the scripts in /etc/cron.daily and other locations. Several packages place scripts there
that they expect to be run daily. This behavior can be emulated with systemd by installing
sys-process/systemd-cron (https://packages.gentoo.org/packages/sys-process/systemd-cron). Then activate the
new cron replacement with the following commands:
root # systemctl enable cron.target
root # systemctl start cron.target
Troubleshooting
Gentoo bugtracker: known bugs (https://bugs.gentoo.org/buglist.cgi?quicksearch=systemd&
order=bug_id%20DESC)
Freedesktop.org bugtracker: known bugs (https://bugs.freedesktop.org
/buglist.cgi?bug_status=UNCONFIRMED&bug_status=NEW&bug_status=CONFIRMED&
bug_status=ASSIGNED&bug_status=REOPENED&bug_status=NEEDINFO&bug_status=PLEASETEST&
bug_status=IN_PROGRESS&product=systemd&component=&order=bug_id%20DESC)
Upstream debugging guide (http://freedesktop.org/wiki/Software/systemd/Debugging)
lvm
When switching from OpenRC to systemd and lvm is needed to properly mount the system volumes, activate the
lvm service:
root # systemctl enable lvm2-monitor.service
While it might not be needed for activation of the root volume (if lvm is integrated into the initramfs) it might not
work for other lvm volumes, unless the service is activated.
systemd-bootchart
KERNEL
15 of 18
systemd-bootchart support
09/03/2016 02:55
https://wiki.gentoo.org/wiki/Systemd
/etc/systemd/bootchart.conf
...
Init=/usr/lib/systemd/systemd
...
/etc/syslog-ng/syslog-ng.conf
# By default syslog-ng uses unix-stream. Comment this out and add unix-dgram instead.
# unix-stream('/dev/log');
unix-dgram('/dev/log');
sys-fs/cryptsetup configuration
systemd does not seem to respect /etc/conf.d/dmcrypt (see bug #429966 (https://bugs.gentoo.org
/show_bug.cgi?id=429966)) so it needs to be congured through the /etc/crypttab le:
FILE
crypt-home UUID=c25dd0f3-ecdd-420e-99a8-0ff2eaf3f391 -
You may need to create a new service le from your /etc/crypttab le. To do this, enable the cryptsetup USE ag
for sys-apps/systemd (https://packages.gentoo.org/packages/sys-apps/systemd). It will install /usr/lib/systemd
/system-generators/systemd-cryptsetup-generator. Executing it will create a service le in /tmp/, which you
can now copy to /etc/systemd/system, adjust manually and add to the desired runlevel.
16 of 18
/etc/systemd/system.conf
09/03/2016 02:55
https://wiki.gentoo.org/wiki/Systemd
LogLevel=debug
Or enable the debug-shell, that opens a terminal at tty9. This helps to debug services during the boot process.
root # systemctl enable debug-shell.service
e4rat usage
Please remember to edit /etc/e4rat.conf setting 'init' to /usr/lib/systemd/systemd, otherwise it will keep
booting OpenRC.
GRSecurity hardening
With grsecurity enabled, systemd-networkd might log the following error:
CODE
systemd-networkd error
The error raises due to systemd-networkd working under a non-root user with grsecurity refusing access to the
complete /sys structure for such users. To disable this option, disable the CONFIG_GRKERNSEC_SYSFS_RESTRICT
kernel option.
See also
Comparison of init systems (/wiki/Comparison_of_init_systems) - An article comparing and contrasting the
dierences in Gentoo init systems.
Sakaki's EFI Install Guide (/wiki/Sakaki%27s_EFI_Install_Guide) - Particularly look at the chapter entitled
Conguring systemd and installing necessary tools (/wiki/Sakaki%27s_EFI_Install_Guide
/Conguring_systemd_and_Installing_Necessary_Tools)
OpenRC to Systemd Cheatsheet (/wiki/OpenRC_to_Systemd_Cheatsheet)
External resources
FAQ (http://www.freedesktop.org/wiki/Software/systemd/FrequentlyAskedQuestions)
Tips and tricks (http://www.freedesktop.org/wiki/Software/systemd/TipsAndTricks)
References
1. Eric S. Raymond. http://www.catb.org/jargon/html/R/rc-le.html (http://www.catb.org/jargon/html/R
/rc-le.html) Retrieved on June 27th, 2015
2. Jose Pedro Oliveira. Note about custom syslog-ng congurations les (https://bugzilla.redhat.com
/show_bug.cgi?id=770810#c10), Red Hat Bugzilla (https://bugzilla.redhat.com/), January 11, 2012. Retrieved
on January 12th, 2015
3. Systemd and syslog-ng interaction problems: system freezes / syslog-ng fails to start
(https://fedoraproject.org/wiki/Common_F16_bugs#systemd-syslog-ng-problems), Fedora Project Wiki
(https://fedoraproject.org/wiki/Fedora_Project_Wiki). Retrieved on January 12th, 2015
Retrieved from "http://wiki.gentoo.org/index.php?title=Systemd&oldid=464184 (http://wiki.gentoo.org
/index.php?title=Systemd&oldid=464184)"
Category (/wiki/Special:Categories): Init systems (/wiki/Category:Init_systems)
17 of 18
09/03/2016 02:55
https://wiki.gentoo.org/wiki/Systemd
18 of 18
09/03/2016 02:55