This is Gentoo's testing wiki. It is a non-operational environment and its textual content is outdated.

Please visit our production wiki at https://wiki.gentoo.org

Systemd

From Gentoo Wiki (test)
Jump to:navigation Jump to:search
This page is a translated version of the page Systemd and the translation is 39% complete.
Outdated translations are marked like this.

Warning: Display title "systemd/ja" overrides earlier display title "Systemd".

systemd is a modern SysV-style init and rc replacement for Linux systems. It is supported in Gentoo as an alternative init system.

インストール

Note
If updating from <=sys-apps/systemd-203 check the upgrade sub-article.

The core around which all distributions are built is the Linux kernel. It is the layer between the user programs and the system hardware. Gentoo provides its users several possible kernel sources. A full listing with description is available at the Kernel overview page.

For amd64-based systems, Gentoo recommends the sys-kernel/gentoo-sources package.

Choose an appropriate kernel source and install it using emerge:

root #emerge --ask sys-kernel/gentoo-sources

カーネル

systemdはLinuxカーネルの比較的新しい機能を多用しています。現在、ebuildにて指定されたカーネルの下限バージョンは2.6.39です。sys-kernel/gentoo-sourcesの最近のバージョンでは、systemdが必須、あるいは任意とするカーネルオプションを簡便に選択する方法が用意されています (詳細については Kernel/Configuration をご覧ください):

KERNEL gentoo-sources を使った高速設定
'"`UNIQ--pre-00000001-QINU`"'

カーネルのオプションを手動で設定する場合は、次のカーネルオプションが必須となるか、あるいは推奨されます。(なお、sys-kernel/gentoo-sourcesを使わない場合は手動で設定しなければなりません)

KERNEL Mandatory options
General setup  --->
	[*] Control Group support --->
		[*]   Support for eBPF programs attached to cgroup
	[ ] Enable deprecated sysfs features to support old userspace tools
	[*] Configure standard kernel features (expert users)  --->
		[*] open by fhandle syscalls
		[*] Enable eventpoll support
		[*] Enable signalfd() system call
		[*] Enable timerfd() system call
[*] Networking support --->
Device Drivers  --->
	Generic Driver Options  --->
		[*] Maintain a devtmpfs filesystem to mount at /dev
File systems  --->
	[*] Inotify support for userspace
	Pseudo filesystems  --->
		[*] /proc file system support
		[*] sysfs file system support
KERNEL Recommended options
General setup  --->
	[*] Configure standard kernel features (expert users)  --->
		[*] Checkpoint/restore support
	[*] Namespaces support  --->
		[*] Network namespace
[*] Enable the block layer  --->
	[*] Block layer SG support v4
Processor type and features  --->
	[*] Enable seccomp to safely compute untrusted bytecode
Networking support --->
	Networking options --->
		<*> The IPv6 protocol
Device Drivers  --->
	Generic Driver Options  --->
		()  path to uevent helper
		[ ] Fallback user-helper invocation for firmware loading
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

UEFIのシステム上では、次のオプションも有効にしてください:

KERNEL UEFI サポート
'"`UNIQ--pre-00000008-QINU`"'

システムがBFQスケジュラーを使用している場合は、"Enable the block layer -> IO Schedulers"下にある"BFQ hierarchical scheduling support"を有効にすることがBFQの開発元によって推奨されています。

For an up-to-date list, see section "REQUIREMENTS" in the upstream README file.

/etc/mtab

開発元は、 /etc/mtab ファイルが /proc/self/mounts へのシンボリックリンクである環境のみをサポートしています。また、このシンボリックリンクが存在しない場合、mount (bug #434090) および df (bug #477240) にも問題が発生します。かつて一部のユーティリティがマウントオプションなどを書き込んでいたため、/etc/mtab は通常のファイルであることが期待されていましたが、現在ではあらゆるソフトウェアが対策を終えているものと思われます。とはいえ念のため、ファイルをリンクに変更する作業を行う前に、 bug #477498 を閲覧の上、システムが既知の問題を抱えていないことをお確かめください。

シンボリックリンクを作成するには、以下を実行します:

root #ln -sf /proc/self/mounts /etc/mtab

/usr がブート時に存在することを確実にする

/usr を分割したシステム構成では、initramfs を使用して /usr を systemd の起動以前にマウントします。現在のところ、sys-kernel/genkernel/usr をサポートしていないため、sys-kernel/dracutsys-kernel/genkernel-next を利用することになります。移行作業のための時間を確保しておいてください:

root #emerge --ask --unmerge sys-kernel/genkernel
root #emerge --ask sys-kernel/dracut
root #emerge --ask sys-kernel/genkernel-next

dracut を使用する際、自動的に有効になっていなければ、usrmount モジュールを選択し、/usr を自動でマウントするよう設定しておいてください。

FILE /etc/dracut/dracut.conf
# Dracut modules to add to the default
add_dracutmodules+="usrmount"

genkernel-next を利用する場合、カーネルをリビルドする前に、genkernel の設定ファイル中の UDEV 変数が yes に設定されていることを確かめてください。/usr が initramfs に組み込まれるようになります:

FILE /etc/genkernel.conf
# Use udev instead of mdev as the default device manager for the initramfs.
# If systemd and perhaps lvm is used, then this _must_ be turned on.
UDEV="yes"
root #genkernel --install all

その他の方法については Initramfs guide をご覧ください。

Using LVM and initramfs

sys-fs/lvm2 が使われているシステムを initramfs でブートする場合、initramfs の作成には sys-kernel/genkernel-next が必須です:

root #genkernel --udev --lvm <target>

<target> は、 initramfs もしくは initramfs が暗黙的に作成される他の genkernel ターゲットです。詳細は genkernel --help の出力を参照してください:

user $genkernel --help

LVM を使用するシステムでは、LVM ボリュームをマウントするため、systemd と共に lvmetad デーモンが起動されなければなりません。lvmetad/etc/lvm/lvm.conf で有効化できます:

FILE /etc/lvm/lvm.conflvm.conf に必要な変更の一部分
# Set use_lvmetad to '1' for systemd
use_lvmetad = 1
Note
/etc/lvm/lvm.conf を修正するほかにも、lvmetad.socket ユニットを利用して lvmetad.service を起動することでも対処できるのではないかと考えられますが、現行バージョンの sys-fs/lvm2 にはこれらのファイルが含まれていません。

USE flags

USE flags for sys-apps/systemd System and service manager for Linux

acl Add support for Access Control Lists
apparmor Enable support for the AppArmor application security system
audit Enable support for sys-process/audit
boot Enable EFI boot manager and stub loader
cgroup-hybrid Default to hybrid (legacy) cgroup hierarchy instead of unified (modern).
cryptsetup Enable cryptsetup tools (includes unit generator for crypttab)
curl Enable support for uploading journals
dns-over-tls Enable DNS-over-TLS support
elfutils Enable coredump stacktraces in the journal
fido2 Enable FIDO2 support
gcrypt Enable use of dev-libs/libgcrypt for various features
gnutls Prefer net-libs/gnutls as SSL/TLS provider (ineffective with USE=-ssl)
homed Enable portable home directories
http Enable embedded HTTP server in journald
idn Enable support for Internationalized Domain Names
importd Enable import daemon
iptables Use libiptc from net-firewall/iptables for NAT support in systemd-networkd; this is used only if the running kernel does not support nftables
kernel-install Enable kernel-install
kmod Enable kernel module loading via sys-apps/kmod
lz4 Enable lz4 compression for the journal
lzma Support for LZMA compression algorithm
openssl Enable use of dev-libs/openssl for various features
pam Add support for PAM (Pluggable Authentication Modules) - DANGEROUS to arbitrarily flip
pcre Add support for Perl Compatible Regular Expressions
pkcs11 Enable PKCS#11 support for cryptsetup and homed
policykit Enable PolicyKit (polkit) authentication support
pwquality Enable password quality checking in homed
qrcode Enable qrcode output support in journal
resolvconf Install resolvconf symlink for systemd-resolve
seccomp Enable seccomp (secure computing mode) to perform system call filtering at runtime to increase security of programs
secureboot Automatically sign efi executables using user specified key
selinux  !!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur
split-usr Enable behavior to support maintaining /bin, /lib*, /sbin and /usr/sbin separately from /usr/bin and /usr/lib*
sysv-utils Install sysvinit compatibility symlinks and manpages for init, telinit, halt, poweroff, reboot, runlevel, and shutdown
test Enable dependencies and/or preparations necessary to run tests (usually controlled by FEATURES=test but can be toggled independently)
tpm Enable TPM support
ukify Enable systemd-ukify
vanilla Disable Gentoo-specific behavior and compatibility quirks
xkb Depend on x11-libs/libxkbcommon to allow logind to control the X11 keymap
zstd Enable support for ZSTD compression

Profile

systemd USE フラグを、システム全体に対して有効化してください。また、systemd-logind サービスとの干渉を避けるため、consolekit USE フラグを無効にしなければなりません。別の方法として、systemd サブプロファイルに切り替えることで、適切な USE フラグを初期設定とすることも可能で、この場合 make.conf を変更する必要はありません。

root #eselect profile list

Finally update the system with the new profile:

root #emerge -avDN @world

sys-fs/udev blocking sys-apps/systemd などの依存関係問題が発生するとき、sys-fs/udev が world ファイルに登録されていることが原因かもしれません。deselect を試みてください:

sys-apps/systemd contains udev. Once installed, sys-fs/udev can be removed as systemd will be the provider for the virtual/udev requirement.

root #emerge --deselect sys-fs/udev

Bootloader

systemd を実行するため、カーネル(もしくは initramfs)が使用する init を切り替えます。

Warning
切替中に、以前のサービスマネージャーに対して設定されたサービスが自動的に起動することはありません。ネットワークなどの機能を回復するには、それらのサービスを再び有効化する必要があります。この文書の下部に位置するサービスセクションの中で解説します。
Note
移行作業がシステムを壊してしまった場合、この手順での init の変更を差し戻すことによって、いつでも初期のサービスマネージャー (OpenRC) を使用してのブートに復旧することが可能です。この記事の末部に記載しているトラブルシューティングを実行するには、この方法で元の状態に戻します。

以下のサブセクションでは、ブートマネージャまたはカーネルのいずれかで init を切り替える方法を文書化します。

GRUB Legacy (0.x)

カーネルのコマンドライン引数として init=/usr/lib/systemd/systemd を追加する必要があります。grub.conf の一例からの抜粋はこのようになるでしょう:

FILE /boot/grub/grub.confsystemd 用 GRUB 設定の例
title=Gentoo with systemd
root (hd0,0)
kernel /vmlinuz root=/dev/sda2 init=/usr/lib/systemd/systemd

システムが OpenRC を使用して起動してしまうことがあれば、init の代わりに real_init を試してみてください。

GRUB 2

When grub-mkconfig is used, add the init option to GRUB_CMDLINE_LINUX:

Note
dracut が systemd をとりこんで生成した initramfs を使用するときには、この作業は必要ありません。initramfs が systemd を起動することになります。
FILE /etc/default/grubConfigure GRUB2 for systemd
# Append parameters to the linux kernel command line
GRUB_CMDLINE_LINUX="init=/lib/systemd/systemd"

When the GRUB2 configuration file is written by hand (experts only), append the init= parameter to the linux or linux16 command.

FILE /boot/grub/grub.cfgGRUB2 設定ファイルの一部の例
linux /vmlinuz-3.10.9 root=UUID=508868e4-54c6-4e6b-84b0-b3b28b1656b6 init=/usr/lib/systemd/systemd


YABOOT

Yaboot is a boot loader for PowerPC-based hardware running Linux, particularly New World ROM Macintosh systems.

The init=/usr/lib/systemd/systemd argument should be added directly after the kernel command-line. An example from yaboot.conf:

FILE /etc/yaboot.confExample yaboot config for systemd
image=/vmlinux 
   append="init=/usr/lib/systemd/systemd" 
   label=Linux 
   read-only 
   initrd=/initramfs 
   initrd-size=8192

You must run the ybin command each time you modify yaboot.conf for the changes to take effect.


In-kernel config

The init configuration can also be hard-coded in the kernel configuration. See Processor type and features -> Built-in kernel command line. Note that this technique works for both GRUB and GRUB2.

Upgrades

systemd has the ability to update in-place on a running system (no reboot necessary). After an upgrade to systemd has emerged, run the following command:

root #systemctl daemon-reexec

Configuration

systemd では、最も基本的なシステムの詳細を設定するのには、いくつかのシステム設定ファイルをサポートしています。

Note
対応する設定ファイルの変更によって更新できる設定もありますが、大半の設定は systemd が実行されていなければ動作しないユーティリティを使って管理します。hostnamectllocalectltimedatectl などの必要なユーティリティを使用するには、コンピューターを再起動してください。この場合の systemd を使用した再ブートは安全に行えます。

Machine ID

Create a machine ID for journaling to work. This can be done through the following command:

root #systemd-machine-id-setup
Note
The command systemd-machine-id-setup also has an impact on the systemd-networkd service. If you don't run this command, strange behavior like network interfaces not coming UP or network addresses not being applied will occur.

ホスト名

ホスト名を設定するには、/etc/hostname を作成または編集して、希望のホスト名を入力してください。

systemd を使って起動したときには、hostnamectl と呼ばれるツールが利用でき、/etc/hostname/etc/machine-info の編集が行えます。ホスト名を変更するには以下を実行してください:

root #hostnamectl set-hostname <HOSTNAME>

他のオプションについては man hostnamectl を参照してください。


ロケール

通常、ロケールは systemd をインストールする作業の中で、OpenRC から正しい形で移行されます。ロケールを変更する必要があれば、Gentoo ハンドブックの手順通りに、/etc/locale.conf で設定できます。

FILE /etc/locale.confシステムロケールの設定
LANG="en_US.utf8"

systemd を使って起動した後には、localectl ツールが、ロケールおよびコンソールやX11のキーマップの設定を行います。システムロケールを変更するには、以下のコマンドを実行してください:

root #localectl set-locale LANG=<LOCALE>

仮想コンソールのキーマップを変更するには:

root #localectl set-keymap <KEYMAP>

最後に X11 のキー配列を設定するには:

root #localectl set-x11-keymap <LAYOUT>

必要があれば model、variant、options も指定できます:

root #localectl set-x11-keymap <LAYOUT> <MODEL> <VARIANT> <OPTIONS>


After doing any of the above, update the environment so the changes will take effect:

root #env-update && source /etc/profile

時刻と日付

時刻と日付は timedatectl ユーティリティで設定できます。net-misc/ntp などを利用せず、systemd 付属の実装によって同期を行う機能も持ちます。

timedatectl の使い方を知るには:

root #timedatectl --help

モジュールの自動読み込み

Automatic module loading is configured in a different file, or rather directory of files. The configuration files are stored in /etc/modules-load.d. On boot every file with a list of modules will be loaded. The file format is a list of modules separated by newlines and can have any name as long as it ends with .conf. The module loading can be separated by program, service or whatever way that fits personal preference. An example virtualbox.conf is listed below:

FILE /etc/modules-load.d/virtualbox.confvirtualbox モジュール用の設定ファイル例
vboxdrv
vboxnetflt
vboxnetadp
vboxpci

ネットワーク

systemd-networkd

systemd-networkd は簡単な有線接続を設定する時に便利です。初期状態では無効にされています。

To configure systemd-networkd, create a

  • .network file under /etc/systemd/network. See systemd.network(5) for reference. A simple DHCP configuration is given below:
FILE /etc/systemd/network/50-dhcp.network
[Match]
Name=en*
 
[Network]
DHCP=yes
root #systemctl enable systemd-networkd.service
root #systemctl start systemd-networkd.service

初期設定では systemd-networkd は resolv.conf を更新しないことに注意が必要です。systemd に DNS 設定を管理させるには、resolv.conf をシンボリックリンクに置き換え、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

ネットワークの設定を構成するのによく使用されるのが NetworkManager です。X11 上のデスクトップから設定するには、次のコマンドを実行するだけです:

root #nm-connection-editor

デスクトップではなく、コンソールから設定する必要がある場合には、nmcli を試してみる、もしくは nmtui の設定手続きに従います:

root #nmtui

nmtui は、コンソールで設定を行うユーザーを手助けする curses フロントエンドです。

ログファイルの対応

systemd は、app-admin/syslog-ngapp-admin/rsyslog などの外部のログシステムに依存しない、独自の手法でログファイルを管理します。メッセージを閲覧するには journalctl を使います。ユーザーの好みの外部ツールを利用するよう設定することもでき、その他さまざまな個人の要求を満たす形に journald を設定する方法については、man journald.conf をご覧ください。

If desired, the logging service be configured to pass log messages to external logging utilities such as sysklog or syslog-ng. See man journald.conf to learn how to configure the systemd-journald service to suit situational needs.

systemd's integrated logging service writes log messages in a secure, binary format. The logs are read by using the journalctl command, which is a separate executable from the systemd-journald logging service.

Important
When using systemd's systemd-journald.service for logging, which is typically the default for systems running systemd, standard users running the journalctl command will be unable to view system logs. To view system logs as a non-root account, users must be in one of the following three user groups in order to view system logs: systemd-journal, adm, or wheel. The simplest method to allow a standard user to view logs is to use the systemd-journal group. Add a user by running the following command where larry is the desired username:

root #gpasswd --add larry systemd-journal

System logs can now be read by running journalctl --system as the user(s) added in the previous command.

よく使われる journalctl のオプション:

journalctl のコマンドラインオプション 結果
journalctl without options Show all log entries, starting with earliest.
-b, --boot Show all log entries from this boot.
-r, --reverse Newest entries first.
-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= Restrict to a number of entries.
-k, --dmesg Restrict to kernel messages.
-u, --unit= Restrict to a certain Systemd unit.

詳しい情報、そしてここに記載されていない数多くのオプションについては、man journalctl をご覧ください。

/tmp が tmpfs に

Unless some other filesystem is explicitly mounted to /tmp in /etc/fstab, systemd will mount /tmp as tmpfs. That means it will be emptied on every boot and its size will be limited to 50% of the system's RAM size. To know why this is the desired behavior and how to modify it, take a look at API File Systems.

ブートプロセスの冗長性の設定

systemd へ移行中のユーザーは、ブートプロセスの冗長性に差があることに気がつきます:

  • ブートオプション quiet が、カーネルの出力だけではなく、systemd からの出力にも影響します。発生したエラーの発見を容易にするため、systemd の設定作業を行っている間は、quiet オプションを除去してください。作業後に元に戻しておきましょう。画面が静かになるのに加えて、ブート時間の短縮にも役立ちます。
  • quiet オプションを指定している場合でも、systemd.show_status=1 の指定によって、systemd が状態を報告するように設定できます。
  • quiet オプションを使用しないとき、コンソールにメッセージが上書きされることがあるかも知れません。これはカーネルの特定のコンフィギュレーションによるものです(man 5 proc を開き、/proc/sys/kernel/printk を調べましょう)。改善するには、カーネルに loglevel=5 ブートパラメータを渡し、必要に応じて1のような小さい数を指定するなどの調整を行ってください。

サービス

systemd がシステムモードで動作している状態に移行するために、ある時点でシステムを再起動する必要があります。この文書に最初から最後まで目を通し、systemd に対して再起動の前に可能な限りの設定が行われたことを確認してください。journalctl は systemd が起動していなくても動作しますが、systemctl が機能するには systemd が必要です。サービスの有効化と開始などの設定は、systemd が動作しているシステムにログインした後で行います。

OpenRC サービス

当初の systemd は、旧来の init.d スクリプトの実行を可能にするように考慮されていましたが、このサポート機能が OpenRC のような依存性を基づく RC に適したものでなかったため、Gentoo では完全に無効化されています。予期しない結果を引き起こさないよう、OpenRC が起動に使われなかったシステムでは、init.d スクリプトの動作を防ぐ保護措置が、OpenRC に組み込まれています。

利用可能なサービスの一覧表示

利用できるすべてのサービスを、systemctllist-units 引数を使用して一覧できます:

root #systemctl list-units
UNIT                               LOAD   ACTIVE SUB       DESCRIPTION
boot.automount                     loaded active waiting   EFI System Partition Automount
proc-sys-fs-binfmt_misc.automount  loaded active waiting   Arbitrary Executable File Formats File System Automount Point
...

以下のファイル名の接尾辞が関心の対象となるでしょう:

Suffix Description
.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 the systemctl tool can be used to list all services (including implicit ones):

root #systemctl --all --full

最後に、起動に失敗したサービスを確認する方法です:

root #systemctl --failed

Enabling, disabling, starting, and stopping services

サービスを有効にする一般的な方法は次のコマンドを使用します。:

root #systemctl enable foo.service

Services can be disabled likewise:

root #systemctl disable foo.service

These 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 users prefer to have another name/target.

Note that these commands only enable or disable the service to be started on a next boot; to start the service right now, use:

root #systemctl start foo.service

サービスは、同様に停止することができます。:

root #systemctl stop foo.service

Installing custom unit files

Custom unit files can be placed in /etc/systemd/system, where they will be recognized after running systemctl daemon-reload:

root #systemctl daemon-reload

/lib/systemd/system is reserved for service files installed by the package manager.

Customizing unit files

When only minor changes to a unit are needed, there's no need to create a full copy of the original unit file in /etc/systemd/system. Overriding settings in a package management provided unit can be achieved by drop-in files in a

  • .d directory named after the original unit (e.g. apache2.d) in /etc/systemd/system/.
FILE /etc/systemd/system/apache2.d/mem-limit.confExample of adding/overriding settings in a service file
[Service]
MemoryLimit=1G

A reload of systemd is needed to inform it of the changes:

root #systemctl daemon-reload

Then the service needs to be restarted to apply the changes:

root #systemctl restart apache2

サービスのプロパティの変更が適用されたことを確認します。:

root #systemctl show --property=MemoryLimit apache2
MemoryLimit=1074000000

Enabling a service under a custom name

When the name provided by "Alias" in the unit's "[Install]" section does not meet the expectations and providing a permanent new value for this through a customization is not desired, a symlink can be created manually in /etc/systemd/system/*.wants/. The name of the

  • .wants directory can either specify a target or another service which will depend on the new one.

For example, to install mysqld.service as db.service in the multi-user.target:

root #ln -s /lib/systemd/system/mysqld.service /etc/systemd/system/multi-user.target.wants/db.service

To disable the service, just remove the symlink:

root #unlink /etc/systemd/system/multi-user.target.wants/db.service

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:

Service migration chart
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 See note always enabled as part of systemd (i.e. it is baked in and it is not a unit)
keymaps systemd-vconsole-setup.service always enabled, uses vconsole.conf
killprocs
local
localmount local-fs.target actual units are created implicitly from /etc/fstab
modules systemd-modules-load.service always enabled, uses /etc/modules-load.d/*.conf
mount-ro
mtab
netmount remote-fs.target
numlock
procfs (builtin)
root remount-rootfs.service
savecache n/a OpenRC internals
staticroute
swap swap.target actual units are created implicitly from /etc/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
app-admin/syslog-ng syslog-ng syslog-ng.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/netifrc net.* net@.service systemd wrapper for net.* scripts (comes with net-misc/netifrc)
netctl@.service net-misc/netctl is originally an Arch Linux tool.
NetworkManager.service For <networkmanager-0.9.8.4 : enable NetworkManager-dispatcher.service for dispatcher.d scripts to work.
Enable NetworkManager-wait-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 ntpd ntpd.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-wireless/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-apps/microcode-ctl microcode_ctl Configure 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 right option based on the system having an intel or amd processor.
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 Most of its functionality is done by systemd itself, so consider disabling this
x11-apps/xdm (xdm) xdm.service OpenRC uses common xdm init.d installed by x11-base/xorg-server. With systemd the corresponding unit file for each DM (gdm.service, kdm.service...) needs to be enabled.
net-firewall/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 system was powered down when the timer was scheduled.

The following is an example on how to make a simple timer that runs in the context of a user. It will even run if the user is not logged in. Every timed service needs a timer and a service file that is activated by the timer as follows:

FILE ~/.local/share/systemd/user/backup-work.timerExample of a timer running every working day
[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 ~/.local/share/systemd/user/backup-work.serviceExample of a service triggering backup
[Unit]
Description=daily backup work
RefuseManualStart=no
RefuseManualStop=yes
 
[Service]
Type=oneshot
ExecStart=/home/<user>/scripts/backup-work.sh

Firstly, tell systemd to rescan the service files:

user $systemctl --user daemon-reload

It is possible to trigger the backup manually by running the following command:

user $systemctl --user start backup-work.service

Start and stop the timer manually as follows:

user $systemctl --user start backup-work.timer
user $systemctl --user stop backup-work.timer

Finally, to activate the timer at every system start, run:

user $systemctl --user enable backup-work.timer

To check the last results of running the service:

user $systemctl --user list-timers

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 specifies what should happen if a service fails. A failure is detected by a non-zero return code of the invoked script.

次のようにそのためのスクリプトを変更します。:

FILE ~/.local/share/systemd/user/backup-work.serviceExample of a service triggering backup
[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.

Replacing cron

The above timer and service files can also be added to /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. Then activate the new cron replacement with the following commands:

root #systemctl enable cron.target
root #systemctl start cron.target

Troubleshooting

/dev/kmsg buffer overrun, some messages lost

Problem
When booting the system displays an infinite loop of /dev/kmsg buffer overrun, some messages lost. The login screen to console never appears since the system never gets to that point in the boot process.
Solution
Most of the time this issue is caused when the CONFIG_POWER_SUPPLY_DEBUG option is enabled in the kernel. The current workaround is to disable this option in the kernel, then recompile, install, and boot the new kernel. The solution can also be found in this thread on the Gentoo forums. According to one user one the forum, this issue was also seen when using I2C EEPROM on an embedded system[1]. The solution in this case was to disable the CONFIG_I2C_DEBUG_CORE kernel option.

Graphical sessions opened in random places

By default systemd only launches a getty process when it's going to be used. This causes some display managers (like GDM) to use the remaining TTYs for opening graphical sessions on demand, which can result in having consoles and graphical sessions placed randomly depending on the order they were used.

To stick with a more "classical" behavior (i.e, consoles placed from tty1 to tty6 and graphical sessions using the remaining TTYs) force it to always launch getty on those:

root #systemctl enable getty@tty{2,3,4,5,6}.service

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

Make sure that CONFIG_DEBUG_KERNEL, CONFIG_SCHED_DEBUG, and CONFIG_SCHEDSTATS are enabled.

KERNEL Enable systemd-bootchart support
'"`UNIQ--pre-00000024-QINU`"'

Next, enable systemd-bootchart.service:

root #systemctl enable systemd-bootchart

The result of the changes will produce a bootchart report in SVG format located in /run/log/ after each boot. It can be viewed using a modern web browser.

As an alternative to systemd-bootchart the starting of services can be visualized with:

root #systemd-analyze plot > plot.svg

syslog-ng source for systemd

There is no need to add unix-dgram('/dev/log'); to the /etc/syslog-ng/syslog-ng.conf config file. It will cause syslog-ng to fail (at least on version syslog-ng-3.7.2). Update the source src { ...; }; line mentioned in the syslog-ng article as follows:

FILE /etc/syslog-ng/syslog-ng.conf
# default config for openrc
#source src { system(); internal(); };
 
# systemd
source src { systemd-journal(); internal(); };

sys-fs/cryptsetup configuration

systemd does not seem to respect /etc/conf.d/dmcrypt (see bug #429966) so it needs to be configured through the /etc/crypttab file:

FILE /etc/crypttabConfiguration file for encrypted block devices
crypt-home UUID=c25dd0f3-ecdd-420e-99a8-0ff2eaf3f391 -

Make sure to enable the cryptsetup USE flag for sys-apps/systemd. It will install /lib/systemd/system-generators/systemd-cryptsetup-generator that will automatically create a service (cryptsetup@crypt-home.service for above example) for each entry on boot.

Check for units that failed to start

Check for units that failed to start with:

root #systemctl --failed

Enable debug mode

To get more informations set the following in /etc/systemd/system.conf:

FILE /etc/systemd/system.conf
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 /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
could not find udev device: Permission denied

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.

logind may also have subtle permission issues with CONFIG_GRKERNSEC_PROC active, see bug #472098.

shutdown -rF does not force fsck

The systemd-fsck service is responsible of running fsck when needed. It doesn't honor shutdown's -rF option, but instead honors the following kernel boot parameters.

Boot parameter Supported options Description
fsck.mode auto
force
skip
Controls the mode of operation. The default is auto, and ensures that file system checks are done when the file system checker deems them necessary. force unconditionally results in full file system checks. skip skips any file system checks.
fsck.repair preen
yes
no
Controls the mode of operation. The default is preen, and will automatically repair problems that can be safely fixed. yes will answer yes to all questions by fsck and no will answer no to all questions.

See also

External resources

References