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

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:

/run directory
The 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 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 file should be a symlink to. This is not obligatory and can create problems with mount -o user and NFS mounts.

To create the symlink:

/etc/machine-id
Often systemd guides mention creating the file as a global replacement for the D-Bus specific. This is already done in the package.

Software
Portage knows the local USE flag systemd for enabling additional support for systemd in other packages (support for journal, logind and socket activation):

The USE flags of systemd are:

After setting this you want to update your system so the changes take effect:

Shared configuration files
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:
 * for hostname,
 * for operating system identification,
 * for locale (created by env-update from ),
 * for the unicode console setting,
 * for the console font settings,
 * for the keymap setting (but only the actual keymap).

Additionally, the following configuration directories are both used by OpenRC and systemd:

Alternatively, you can migrate your system to use Native systemd configuration files. Bear in mind that upstream has made it clear that at some point in the future it will stop supporting configuration files for specific distributions, and it will only support the native systemd configuration files. If you plan to use systemd exclusively, please use its native configuration files.

Native 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/vconsole.conf: Configuration file specifying console font and keymap. Replaces and, yet it doesn't support all features of those init.d scripts.


 * /etc/locale.conf: Configuration file for locale settings. The file supports same syntax as shell locale variables, so you can basically rename or a similar file.


 * /etc/machine-info: Configuration file for local machine informations

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.

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.

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=/bin/systemd argument should be added to the kernel command-line. An example excerpt from would look like:

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

Listing available services
All global service files are installed in. 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 the systemadm graphical tool can be used. It can be installed with the package.

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

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

Enable debug mode
To get more informations you need to set the following in :

External resources

 * FAQ
 * Tips and tricks