Systemd

systemd is a modern sysvinit & RC replacement for Linux systems. It is supported in Gentoo as an alternate init system.

= 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.38. In addition to that, the following kernel configuration options should be enabled:

Prerequisites: udev
Newer versions of systemd (> 29) require udev version at least 172. The current version in the tree (175) is hard masked since both udev and systemd do not support a separated /usr partition. In order to use the newer versions of systemd, you have unmask the udev ebuild:

and keyword both udev and systemd:

You can still use systemd-29 without unmasking udev nor keywording those packages.

/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 ebuild 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 /etc/mtab file should be a symlink to /proc/self/mounts. Note that this is not obligatory, and can create problems with mount -o user and NFS mounts.

To create the symlink, please use the following command:

/etc/machine-id
Often systemd guides mention creating /etc/machine-id file as a global replacement for D-Bus specific /var/lib/dbus/machine-id. In Gentoo, this is already done in ebuild.

Installing
Installing systemd is as simple as emerging.

Enabling
Before doing this, please configure systemd first.

In order to run systemd, you have to switch the init executable kernel (or your initramfs) uses.

With simple kernels, the init=/bin/systemd argument should be added to the kernel command-line. An example excerpt from grub.conf would look like:

When using initramfs, other command-line argument will be needed. For example, genkernel uses real_init= there:

= Configuration =

System configuration
systemd comes with some degree of OpenRC compatibility, so it will gracefully read most of the base system options from its files. This includes the following files:
 * /etc/conf.d/hostname for hostname,
 * /etc/profile.env for locale (created by env-update from /etc/env.d),
 * /etc/rc.conf for the unicode console setting,
 * /etc/conf.d/consolefont for the console font settings,
 * /etc/conf.d/keymaps for the keymap setting (but only the actual keymap).

Additionally, the following configuration directories are both used by OpenRC and systemd:
 * /etc/modules-load.d,
 * /etc/sysctl.d,
 * /etc/binfmt.d (since OpenRC-0.9.4).

Alternatively, you can migrate your system to use.

Listing available services
All global service files are installed in /lib/systemd/system directory. Thus, the simplest way of looking up available service units is listing that directory:

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):

And finally, if was built with USE=gtk, the systemadm graphical tool can be used.

Installing custom service files
Any custom service files should be copied to /etc/systemd/system directory. The /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:

Services can be disabled likewise:

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 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 on wlan0, type:

To disable the service, just remove the symlink:

Native systemd configuration files
systemd supports a few system configuration files to set the most basic system details.

/etc/hostname
A trivial file containing the system hostname. Replaces /etc/conf.d/hostname.

/etc/vconsole.conf
Simple configuration file specifying console font and keymap. Replaces /etc/conf.d/consolefont and /etc/conf.d/keymaps, yet it doesn't support all features of those init.d scripts.

/etc/locale.conf
In systemd, locale settings are stored in /etc/locale.conf. The file supports same syntax as shell locale variables, so you can basically rename /etc/env.d/02locale or a similar file.