systemd
systemd is a modern sysvinit & RC replacement for Linux systems. It is supported in Gentoo as an alternate init system.
See also: Comparison of init systems
Contents |
Installation
Prerequisites: 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 addition to that, the following kernel configuration options should be enabled:
General setup --->
[*] Control Group support
[ ] Enable deprecated sysfs features to support old userspace tools
[*] Networking support --->
Device Drivers --->
Generic Driver Options --->
[*] Maintain a devtmpfs filesystem to mount at /dev
File systems --->
[*] Inotify support for userspace
Pseudo filesystems --->
[*] sysfs file system support
General setup --->
[*] open by fhandle syscalls
Processor type and features --->
[*] Enable seccomp to safely compute untrusted bytecode
Networking support --->
Networking options --->
TCP/IP networking --->
<*> The IPv6 protocol
Device Drivers --->
Generic Driver Options --->
() path to uevent helper
Firmware Drivers --->
[*] Export DMI identification via sysfs to userspace
File systems --->
<*> Kernel automounter version 4 support (also supports v3)
Pseudo filesystems --->
[*] Tmpfs virtual memory file system support (former shm fs)
[*] Tmpfs POSIX Access Control Lists
[*] Tmpfs extended attributes
File systems --->
Pseudo filesystems --->
[*] /proc file system support
Kernel hacking --->
[*] Kernel debugging
[*] Collect scheduler debugging info
[*] Collect scheduler statistics
[*] Enable the block layer --->
Partition Types --->
[*] Advanced partition selection
[*] EFI GUID Partition support
Processor type and features --->
[*] EFI runtime service support
Firmware Drivers --->
<*> EFI Variable Support via sysfs
Prerequisites: filesystem
/run directory
The /run directory is used by systemd (and some applications) as a non-persistent storage for runtime data like pidfiles, sockets and state files.
The systemd package will create /run directory itself. However, please note that this change will trigger automatic mounting of it in OpenRC as well, and may trigger using it by different software packages.
/etc/mtab symlink
Upstream suggests that the /etc/mtab file should be a symlink to /proc/self/mounts. This is not obligatory and can create problems with mount -o user and NFS mounts.
To create the symlink:
root # ln -sf /proc/self/mounts /etc/mtab/etc/machine-id
Often systemd guides mention creating the file /etc/machine-id as a global replacement for the D-Bus specific /var/lib/dbus/machine-id. This is already done in the sys-apps/dbus package.
Software
Install sys-apps/systemd:
| USE flag | Default | Recommended | Description |
|---|---|---|---|
| acl | Yes | Adds support for Access Control Lists | |
| audit | No | Enable support for sys-process/audit | |
| cryptsetup | No | Use libcryptsetup | |
| doc | No | Adds extra documentation (API, Javadoc, etc). It is recommended to enable per package instead of globally | |
| firmware-loader | Yes | Enable user-space firmware loader (for kernels prior to 3.8) | |
| gcrypt | No | Enable sealing of journal files using gcrypt | |
| gudev | Yes | enable libudev gobject interface | |
| http | No | Enable embedded HTTP server in journald | |
| introspection | Yes | Adds support for GObject based introspection | |
| keymap | Yes | Map custom hardware's multimedia keys | |
| kmod | Yes | Enable kernel module loading via sys-apps/kmod | |
| lzma | No | Support for LZMA (de)compression algorithm | |
| openrc | No | Depend on sys-fs/udev-init-scripts | |
| pam | Yes | Adds support for PAM (Pluggable Authentication Modules) - DANGEROUS to arbitrarily flip | |
| policykit | No | Enable PolicyKit authentication support | |
| python | No | Adds optional support/bindings for the Python language | |
| qrcode | No | Enable qrcode output support in journal | |
| selinux | No | !!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur | |
| static-libs | No | Build static libraries | |
| tcpd | Yes | Adds support for TCP wrappers | |
| vanilla | No | Disable Gentoo-specific behavior and compatibility quirks | |
| xattr | No | Adds support for extended attributes (filesystem-stored metadata) |
root # emerge --ask systemd
Portage knows the global USE flag systemd for enabling use of systemd-specific libraries and features like socket activation or session tracking.
USE="... systemd ..."
After setting this you want to update your system so the changes take effect:
root # emerge --ask --changed-use --deep @worldConfiguration
Configuration files
systemd supports a few system configuration files to set the most basic system details.
A tool called hostnamectl exists for editing /etc/hostname and etc/machine-info. To change hostname:
root # hostnamectl set-hostname <hostname>Refer to man hostnamectl for more options.
frobnicator
This example sets hostname of frobnicator.
KEYMAP=pl2 FONT=LatArCyrHeb-16
/etc/vconsole.conf doesn't yet support all features of those init.d scripts. This example is a simple console configuration.
LANG="pl_PL.UTF-8" LC_ALL="pl_PL.UTF-8"
/etc/locale.conf supports same syntax as shell locale variables, so you can basically rename /etc/env.d/02locale or a similar file. This is an example for utf8.
PRETTY_NAME="Larry's Computer" ICON_NAME="computer-laptop"
/etc/adjtime is a configuration file for system time. Replaces /etc/conf.d/hwclock. See the system time article.
Additionally, the following configuration directories are both used by OpenRC and systemd:
- /etc/modules-load.d,
- /etc/sysctl.d,
- /etc/binfmt.d
systemd-logind & pam_systemd
systemd intends to provide an integrated ConsoleKit replacement called logind. Some applications (like NetworkManager and polkit) provide support for it through USE=systemd. Please note that this flag usually disables ConsoleKit support as well and thus packages may stop working as expected if the procedure described below is not fulfilled. If you're having issues with kde-misc/networkmanagement not being able to detect NetworkManager is running, modify your system-auth file to add pam_systemd.
... session optional pam_systemd.so
In order to enable session tracking for systemd-logind, you have to enable the pam_systemd PAM module first. This can be done using USE=systemd on sys-auth/pambase.
Except for tracking user logins (like ConsoleKit does), this will cause all user processes to belong to a cgroup. You can add controllers=... to provide additional cgroup controllers (like cpu for CPU load balancing). You can also add kill-session-processes=1 to ensure that all processes spawned by user are killed on logout. For more information, take a look at pam_systemd man page.
Enabling
In order to run systemd, you have to switch the init executable kernel (or your initramfs) uses.
With simple kernels, the init=/usr/lib/systemd/systemd argument should be added to the kernel command-line. An example excerpt from grub.conf would look like:
title=Gentoo with systemd root (hd0,0) kernel /vmlinuz root=/dev/sda2 init=/usr/lib/systemd/systemd
When using initramfs, other command-line argument will be needed. For example, genkernel uses real_init= there:
title=Gentoo with systemd root (hd0,0) kernel /my-genkernel... root=/dev/hda2 real_init=/usr/lib/systemd/systemd initrd /initramfs-genkernel...
Listing available services
All global service files are installed in /usr/lib/systemd/system. Thus, the simplest way of looking up available service units is listing that directory:
root # ls /usr/lib/systemd/system
acpid.service runlevel2.target
alsa-restore.service runlevel2.target.wants
alsa-store.service runlevel3.target
autovt@.service runlevel3.target.wants
avahi-daemon.service runlevel4.target
avahi-daemon.socket runlevel4.target.wants
avahi-dnsconfd.service runlevel5.target
basic.target runlevel5.target.wants
...
The following file suffixes are of interest:
- .service - plain service files (e.g. ones just running a daemon directly),
- .socket - socket listeners (much like inetd),
- .path - filesystem triggers for services (running services when files change etc.).
Alternatively, systemctl tool can be used to list all services (including implicit ones):
root # systemctl --all --fullAnd finally the systemadm graphical tool can be used. It can be installed with the sys-apps/systemd-ui package.
Installing custom service files
Any custom service files should be copied to the /etc/systemd/system directory. The /usr/lib/systemd/system directory is reserved for service files installed by ebuilds.
Enabling and disabling services
The usual way of enabling a service is using
root # systemctl enable foo.serviceServices can be disabled likewise:
root # systemctl disable foo.serviceThese commands enable services using their default name in default target (both specified in Install section of the service file). However, sometimes services either don't provide that information or you want to use another name/target.
Enabling a service under a custom name
This is especially a case for template services -- services in which part of the name following @ (at sign) is used as a parameter to the service. This is often used to specify the terminal on which getty will run.
To enable a service under custom name, you have to create a symlink to the service file in correct /etc/systemd/system/*.wants directory. The name of that directory can either specify a target or another service which will depend on the new one.
For example, to enable stand-alone wpa_supplicant on wlan0, type:
root # ln -s /lib/systemd/system/wpa_supplicant@.service /etc/systemd/system/multi-user.target.wants/wpa_supplicant@wlan0.serviceTo disable the service, just remove the symlink:
root # rm /etc/systemd/system/multi-user.target.wants/wpa_supplicant@wlan0.serviceServices
Native services
Some of Gentoo packages already install systemd unit files. For these services, it is enough to enable them. A quick summary of packages installing unit files can be seen on systemd eclass users list.
The following table lists systemd services matching OpenRC ones:
| Gentoo package | OpenRC service | systemd unit | Notes |
|---|---|---|---|
| sys-apps/openrc | bootmisc | systemd-tmpfiles-setup.service | always enabled, uses tmpfiles.d |
| consolefont | systemd-vconsole-setup.service | always enabled, uses vconsole.conf | |
| devfs | |||
| dmesg | |||
| fsck | fsck*.service | pulled in implicitly by mounts | |
| functions.sh | See note | bug #373219 | |
| hostname | (builtin) | /etc/hostname | |
| hwclock | |||
| keymaps | systemd-vconsole-setup.service | always enabled, uses vconsole.conf | |
| killprocs | |||
| local | |||
| localmount | local-fs.target | actual units are created implicitly from fstab | |
| modules | systemd-modules-load.service | always enabled, uses /etc/modules-load.d/*.conf | |
| mount-ro | |||
| mtab | |||
| net.lo | |||
| netmount | remote-fs.target | ||
| network | netctl@.service | net-misc/netctl is originally an Arch Linux tool. | |
| numlock | |||
| procfs | (builtin) | ||
| root | remount-rootfs.service | ||
| savecache | n/a | OpenRC internals | |
| staticroute | |||
| swap | swap.target | actual units are created implicitly from fstab | |
| swclock | |||
| sysctl | systemd-sysctl.service | sysctl.conf and sysctl.d/ | |
| sysfs | (builtin) | ||
| termencoding | systemd-vconsole-setup.service | always enabled, uses vconsole.conf | |
| urandom | systemd-random-seed-load.service | ||
| systemd-random-seed-save.service | |||
| app-admin/rsyslog | rsyslog | rsyslog.service | |
| media-sound/alsa-utils | alsasound | alsa-store.service | (enabled by default) |
| alsa-restore.socket | (enabled by default) | ||
| net-misc/dhcpcd | dhcpcd | dhcpcd.service | |
| net-misc/openssh | sshd | sshd.service | runs sshd as a daemon |
| sshd.socket | runs sshd on a inetd-like basis (for each incoming connection) | ||
| net-misc/wpa_supplicant | wpa-supplicant | wpa_supplicant.service | D-Bus controlled daemon (e.g. for NetworkManager) |
| wpa_supplicant@.service | interface-specific wpa_supplicant (used like wpa_supplicant@wlan0.service) | ||
| net-print/cups | cupsd | cups.service | classic on-boot start up service |
| cups.socket | socket and path activation (cups only started on-demand) | ||
| cups.path | |||
| net-wireless/bluez | bluetooth | bluetooth.service | |
| sys-apps/dbus | dbus | dbus.service | |
| dbus.socket | |||
| sys-apps/irqbalance | irqbalance | irqbalance.service | supports daemon mode only |
| sys-fs/udev | udev | udev.service | |
| udev-mount | (builtin) | /dev is mounted as tmpfs | |
| udev-postmount | udev-trigger.service | ||
| udev-settle.service | |||
| sys-power/acpid | acpid | acpid.service | |
| x11-apps/xdm | (xdm) | xdm.service | OpenRC uses common xdm init.d installed by x11-base/xorg-server |
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).
Troubleshooting
Enable debug mode
To get more informations you need to set the following in /etc/systemd/system.conf:
LogLevel=debug