systemd

systemd is a system and service manager for Linux, compatible with SysV and LSB init scripts. systemd provides aggressive parallelization capabilities, uses socket and D-Bus activation for starting services, offers on-demand starting of daemons, keeps track of processes using/ Linux cgroups, supports snapshotting and restoring of the system state, maintains mount and automount points and implements an elaborate transactional dependency-based service control logic. It can work as a drop-in replacement for sysvinit.

Setting services

By default systemd will start your system to allow you to login in on a tty. This means no display manager gets started, no network is set up, etc. Make sure to enable the necessary services before you reboot.

Finalizing w/ grub

Finally you will need to tell your kernel to run the init provided by systemd. If you have a kernel built by genkernel, change the real_init kernel parameter to point to /usr/lib/systemd/systemd:

ALSA

alsa-utils already provides systemd service files. They are enabled automatically when installed.

Network

netctl

net-misc/netctl can be used for network configuration of various types in simple manner. Netctl is borrowed from Arch Linux and provides units for systemd. User should create a network profile for each desired network interface in /etc/netctl (use examples in /etc/netctl/examples) and then activate it with:

startx

File: /etc/systemd/system/startx.service

[Unit]
Description=Startx
[Service]
#User=bob #uncomment this to run startx as desired user (in example bob), otherwise it will run startx as root
ExecStart=/usr/bin/startx
[Install]
WantedBy=graphical.target

# See the mediatomb(1) manpage for more info.
# MediaTomb Web UI port.
# NOTE: The minimum value allowed is 49152
MEDIATOMB_PORT=49152
# Run MediaTomb as this user.
# NOTE: For security reasons do not run MediaTomb as root.
MEDIATOMB_USER="mediatomb"
# Run MediaTomb as this group.
# NOTE: For security reasons do not run MediaTomb as root.
MEDIATOMB_GROUP="mediatomb"
# Path to MediaTomb config file.
MEDIATOMB_CONFIG="/etc/mediatomb/config.xml"
# Path to MediaTomb log file.
MEDIATOMB_LOGFILE="/var/log/mediatomb.log"
# Other options you want to pass to MediaTomb.
# Add "--interface ${MEDIATOMB_INTERFACE}" to bind to a named interface.
MEDIATOMB_OPTIONS=""

OpenRC Compatibility

systemd doesn't initialize the OpenRC environment for you, so starting any OpenRC service will fail and complain that the service has already been started. For example:

* WARNING: lvm has already been started

Enable the OpenRC service to initialize the openrc enviornment:

systemctl enable openrc-init.service

If you get the following error message when enabling openrc-init.service:

Unit files contain no applicable installation information. Ignoring.

You may need to modify openrc-init.service to work with the latest versions of systemd where empty sections of scripts are disabled by default:

File: /lib/systemd/system/openrc-init.service

...
[Install]
WantedBy=multi-user.target

Removing only sysvinit

killall

killall = functioning

reboot

reboot = functioning

systemctl reboot

systemctl reboot = functioning

shutdown -h now

shutdown -h now = functioning

shutdown -h 60

shutdown -h 60 = functioning

halt

halt = works but fails to power off as a work around add "alias halt="shutdown -h now"" to /etc/profile.d/rc.sh & run source /etc/profile as your user and then again as root

Removing OpenRC

If you want to have a pure systemd system then you can disable the sysv USE flag globally, then unmerge sysvinit as it won't be used anymore..

Warning: If you remove sysvinit then the /etc/inittab contents are going to be ignored and init, halt, shutdown, reboot, killall5 (and a few others) commands wont be available.

Warning: Until bug 373219 is resolved, it is highly inadvisable to remove openrc since package provides a file, functions.sh, that is used by several other unrelated programs.

Warning: If you remove openrc then you cannot continue using the /etc/init.d scripts anymore, and the config files on /etc/conf.d aren't going to be used either, so you will have to create and maintain your own unit files for the missing services until upstream or Gentoo provides them.

PAM support: su, sudo, screen...

If you want systemd to register your user sessions in cgroups with the optional advantages of having CPU (or other controllers) balancing between sessions, then you can add the USE flag pam to systemd and do the following:

Note: Dont add kill-user=1 if you expect daemons (e.g. screen) to remain available when the session ends.

Note: You can add a cgroup controller to the controller list like controllers=cpu if you want CPU load balancing between sessions (other controllers are also available depending of the kernel cgroup options enabled). If you don't intend to have any type of balancing (or you are using the BFS patch on your kernel) then you can leave the list empty. If this option is omitted then the default is controllers=cpu.

Warning: The current implementation of /bin/su (provided by sys-apps/shadow) in Gentoo is broken because it tries to close the PAM session after dropping root privileges (when being invoked as "su - <user>") and this leaves empty cgroups sessions around (bug report). Note that the /bin/su implementation of coreutils doesn't have this problem so other distros where the coreutils implementation is used won't have this issue.

If with systemd-39 and later your su - sessions are ending with a ...killed message and/or your sudo doesn't work anymore, here is what solved it for me. Copy the contents of the session section from /etc/pam.d/system-auth to /etc/pam.d/sudo then edit that file and /etc/pam.d/su:

File: /etc/pam.d/sudo

auth include system-auth
account include system-auth
password include system-auth
===> Comment the line that mentions pam_loginuid.so.
===> Leave the remaining "session" lines as they are.
...
#session optional pam_loginuid.so
...

File: /etc/pam.d/su

auth include system-auth
account include system-auth
password include system-auth
session include sudo