Systemd

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

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, there is a convenient way of selecting the mandatory and optional kernel options for systemd:

To configure the kernel options manually (which is the only option when not using ), the following kernel configuration options are required and recommended:

For an UEFI system also enable the following:

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

The directory
The directory is used by systemd and other applications as a non-persistent storage for runtime data like pid files, sockets and state files.

The systemd package will create the directory itself. However, please note that this change will trigger automatic mounting of it in OpenRC as well, and may trigger its use by different software packages.

Upstream only supports the file being a symlink to. Not creating this symlink will also cause problems with mount and df. In the past some utilities wrote information (like mount options) into and thus it was supposed to be a regular file. Nowadays all software is supposed to avoid this problem. Still, before switching the file to become a symbolic link, please check to be sure that the system is not affected by any reported regressions.

To create the symlink, run:

Ensure /usr is present at boot time
For a split configuration, one must use an initramfs to mount  before starting systemd. See the Initramfs Gentoo Guide for instructions.

Using LVM2 and initramfs
When sys-fs/lvm2 is used and the system is booted using an initramfs, the initramfs will have to be created using by running:

is either  or one of the other genkernel targets which imply the creation of an initramfs. For more information, look at the output of genkernel --help:

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 :

Installation
contains udev. Once installed, can be removed as systemd will be the provider for.


 * Enable the  USE flag globally (in ). The   USE flag should also be disabled to prevent conflicts with the systemd-logind service. It is also possible to switch to a systemd subprofile to use saner USE flags defaults in which case it is not necessary to change :

Finally update the system with the new flags:

When dependency problems occur (such as blocking ),  might be registered in the world file. Try to resolve this by deselecting it:

Booting with systemd
In order to run systemd, switch the init that the executable kernel (or the initramfs) uses.

The following subsections document how to switch the init in one of the boot managers or the kernel.

Grub Legacy (0.x)
The  argument should be added to the kernel command-line. An example excerpt from would look like so:

Should the system boot using openrc, try using  instead of.

Grub 2
When grub2-mkconfig is used, add the init option to  (it is not required when using an initramfs generated by dracut with systemd inside):

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

When using genkernel-next's initrd, use  instead of.

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.

Setting root password
At this point don't forget to set the system's root password. If something goes wrong, systemd will prompt for the root password to go into maintenance mode.

Post Installation Configuration
systemd supports a few system configuration files to set the most basic system details.

Hostname
To set the hostname, create/edit and simply provide the desired hostname.

When booted using systemd, a tool called hostnamectl exists for editing and. To change the hostname, run:

Refer to man hostnamectl for more options.

Locale
Usually, locales will be properly migrated from openRC when installing systemd. When required, the locale can be set in as per the Handbook instructions:

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:

To change the virtual console keymap:

And finally, to set the X11 layout:

If needed the model, variant and options can be specified as well:

Time & Date
Time and date can be set using the timedatectl</tt> utility. That will also allow users to set up synchronization without needing to rely on or other providers than systemd's own implementation.

To learn how to use timedatectl</tt> simply run:

Automatic module loading
Automatic module loading is configured in a different file, or rather directory of files. The configuration files are stored in. 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. The module loading can be separated by program, service or whatever way that fits personal preference. An example virtualbox.conf</tt> is listed below:

systemd-networkd
systemd-networkd is useful for simple configuration of wired network interfaces. It is disabled by default.

To configure systemd-networkd, create a "network" file under. See systemd.network(5) for reference. A simple DHCP configuration is given below.

Note that systemd-networkd does not update by default. To have systemd manage the DNS settings, replace with a symlink and start systemd-resolved.

NetworkManager
Often NetworkManager is used to configure network settings. For that purpose, simply run the following command when using an X11-powered desktop:

If that is not the case and the network needs to be configured from console, give nmcli a try, or follow a guided configuration process through nmtui</tt>:

nmtui is a curses frontend that will guide the user in the process while running in console mode.

Handling of log files
systemd has its own way of handling log files without needing to rely on any external log system (like syslog-ng or rsyslog). Messages can now be read with journalctl. Anyway, you can still configure it to use your preferred external tool for handling them. Please type man journald.conf for learning about how to configure journald to suit your needs.

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

Configure verbosity of boot process
When migrating to systemd you will probably notice differences regarding verbosity of boot process:
 * quiet option not only affects to kernel output, but also to systemd itself. Then, while you are setting up systemd for your machine, you will probably want to drop it to see any errors could arise more easily. After that, you can add it back to get a quiet (and faster) boot.
 * Even passing quiet option, you can still configure systemd to show its status by also passing systemd.show_status=1.
 * When not using quiet option, you could get some messages overwriting consoles, that is caused by kernel configuration (see man 5 proc and look for /proc/sys/kernel/printk). To tweak it you can pass the loglevel=5 boot parameter to the kernel (or a lower value like 1).

Services
At some point you will have to reboot your system in order to get systemd running (in system mode). Be sure to read all of this document to ensure you have systemd configured as completely as possible before rebooting. Note that journalctl(8) works with systemd(8) not running, but that systemctl(8) will not do anything useful without systemd running. You will likely want to complete the service configuration (enabling and starting of services) after you get logged in to your 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).

Listing available services
All available service units can be listed using the list-units verb provided by systemctl:

The following file suffixes are of interest:
 * - plain service files (e.g. ones just running a daemon directly),
 * - socket listeners (much like inetd),
 * - 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 you can check for services that failed to start running:

Enabling, disabling, starting and stopping 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.

Note that these commands only enable or disable the system to be started on a next boot; if you want to start the service right now, you can use

Services can be stopped likewise:

Installing custom unit files
Custom unit files can be placed in, where they'll be recognized after running:

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

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

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

Verify, the changed property was applied to the service:

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

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:

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

Firstly, you must tell systemd to rescan the service files

You can trigger the backup manually by running

You can start and stop the timer manually by running

And finally to activate the timer at every system start run

You can check the last result of running the service with

Emailing failures
If a timed service runs and fails you can be informed by email. This is possible with the OnFailure stanza that allows you to specify what should happen if a service fails. A failure is detected by a non-zero return code of the backup-work script. For that change the script as follows:

This requires you to have the service  installed, which can be found here.

Replacing cron
The above timer and service files can also be added to to make them available system-wide. The install section should then say  to enable the service at system start.

However, cron also runs the scripts in etc. and several packages place scripts there that they expect to be run daily. You can emulate this behaviour with systemd by first installing and then systemd-cron. Just run  and. You can ignore the systemd-crontab-generator stuff if you are only interested in running the files in. Just copy the files from to. Then ensure you adjust the path to  in the service files. The  script is located in gentoo in. Then activate your new cron replacement with

Troubleshooting

 * Upstream debugging guide
 * Upstream debugging guide
 * Upstream debugging guide

lvm
If you are switching from openrc to systemd and you need lvm to properly mount your volumes, you should activate lvm service:

While it might not be needed for activation of root volume, if lvm is integrated into your initramfs, it might not work for other lvm volumes, unless you activate the service.

systemd-bootchart
As systemd-bootchart attempts to start, you may have to edit its configuration file:

Result is a report in svg located in.

syslog-ng conflicts with systemd
systemd creates as datagram socket  so you will need to tell syslog-ng to read from a unix-dgram instead of a unix-stream if you are hitting problems and are using "wrong" stream:

should be replaced with: in order to use the syslog-ng service in systemd.

sys-fs/cryptsetup configuration
systemd doesn't seem to respect  and, then, you will need to configure it in /etc/crypttab file:

Check for units that failed to start
To check for units that failed to start you can run:

Enable Debug Mode
To get more informations you need to set the following in :

Or enable the debug-shell, that opens an terminal at tty9. This help to debug such service during boot process.

e4rat usage
Please remember to edit setting 'init' to /usr/lib/systemd/systemd, otherwise it will keep booting openrc.

GRSecurity hardening
Synopsis: systemd-networkd log error

could not find udev device: Permission denied The error raises due to systemd-networkd works under non-root user.

You should set kernel option CONFIG_GRKERNSEC_SYSFS_RESTRICT=N.

External resources

 * FAQ
 * Tips and tricks