Systemd

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

Installation
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 are required:

For UEFI system you'll also need to enable the following:

The directory is used by systemd(and some applications) as a non-persistent storage for runtime data like pid files, 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.

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. On the other hand, not creating it will cause problems with mount and df.

To create the symlink, run:

It is necessary to install before enabling the flag. Otherwise, circular dependencies will prevent Portage from continuing. Install :

Enable the USE flag systemd for systemd-specific libraries and features like socket activation or session tracking.

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

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

Hostname
A tool called hostnamectl exists for editing and. To change hostname, run:

Refer to man hostnamectl for more options.

Locale
The tool localectl is used to set locale and console or X11 keymaps. To change the system locale, run the following command. Warning: it will not work until bug 465468 is fixed. In this case please edit and run env-update.

To change the virtual console keymap:

And finaly, to set the X11 layout:

If needed you can specify the model, variant and options too:

Time & Date
Time and date can be set using the timedatectl utility.

Automatic module loading
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 seperated by newline and can have any name you want as long as it ends with .conf. You can seperate out the module loading by program, service or whatever way you like. My virtualbox.conf example is listed below. But I can image one also has an iptables.conf for all the kernel modules needed for your firewall or one big file with all modules.

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

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 console_loglevel=5 parameter (or a higher value like 6 or 7) or change kernel configuration (See "Kernel hacking" -> "Default message log level (1-7)").

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

Grub Legacy (0.x)
With simple kernels, the init=/usr/lib/systemd/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:

Grub 2
When using grub version 2 you should not edit boot configuration files directly. You will need to add the commandline to the following file.

In kernel config
You can also set this in your kernel configuration. See "Processor type and features" -> "Built-in kernel command line". Note that this technique works for bot h grub and grub2.

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 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:
 * - 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 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 wpa_supplicant 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:

Troubleshooting

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

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 not being able to detect NetworkManager is running, modify your system-auth file to add pam_systemd.

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.

syslog-ng
Systemd creates as datagram socket   so you will need to tell syslog-ng to read from a unix-dgram instead of a unix-stream:

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

sys-fs/cryptsetup
Systemd doesn't seem to respect ( ?):

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

External resources

 * FAQ
 * Tips and tricks