Difference between revisions of "Systemd"
(→Installation: -) |
(Pre-installation configuration and installation) |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 11: | Line 11: | ||
* {{Path|/etc/binfmt.d}} | * {{Path|/etc/binfmt.d}} | ||
--> | --> | ||
− | == | + | == Pre-installation Configuration== |
{{Note|If you're updating from <{{=}}sys-apps/systemd-203 check the [[/upgrade|upgrade subpage]].}} | {{Note|If you're updating from <{{=}}sys-apps/systemd-203 check the [[/upgrade|upgrade subpage]].}} | ||
+ | |||
+ | ===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 are required: | 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: | ||
Line 59: | Line 61: | ||
[*] EFI runtime service support | [*] EFI runtime service support | ||
Firmware Drivers ---> | Firmware Drivers ---> | ||
− | + | EFI (Extensible Firmware Interface) Support --> | |
+ | <*> EFI Variable Support via sysfs | ||
</pre>}} | </pre>}} | ||
In the case you are using BFQ scheduler, it's recommended by BFQ upstream to enable "BFQ hierarchical scheduling support" under "Enable the block layer -> IO Schedulers" | In the case you are using BFQ scheduler, it's recommended by BFQ upstream to enable "BFQ hierarchical scheduling support" under "Enable the block layer -> IO Schedulers" | ||
+ | |||
+ | ===The {{Path|/run}} directory=== | ||
The {{Path|/run}} directory is used by systemd and other applications as a non-persistent storage for runtime data like pid files, sockets and state files. | The {{Path|/run}} 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 {{Path|/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. | The systemd package will create {{Path|/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. | ||
+ | |||
+ | ==={{Path|/etc/mtab}}=== | ||
Upstream only supports {{Path|/etc/mtab}} file being a symlink to {{Path|/proc/self/mounts}}. This has caused in the past problems problems with ''mount -o user'' and NFS mounts. On the other hand, not creating it will cause problems with ''mount'' ({{bug|434090}}) and ''df'' ({{bug|477240}}). | Upstream only supports {{Path|/etc/mtab}} file being a symlink to {{Path|/proc/self/mounts}}. This has caused in the past problems problems with ''mount -o user'' and NFS mounts. On the other hand, not creating it will cause problems with ''mount'' ({{bug|434090}}) and ''df'' ({{bug|477240}}). | ||
Line 73: | Line 80: | ||
{{RootCmd|ln -sf /proc/self/mounts /etc/mtab}} | {{RootCmd|ln -sf /proc/self/mounts /etc/mtab}} | ||
− | + | === Ensure /usr is present at boot time === | |
− | + | Splitted /usr isn't supported and, then, you need to get it mounted at boot time. For that, you will need to follow [http://www.gentoo.org/doc/en/initramfs-guide.xml Official Initramfs Gentoo Guide]. If you want to know more about initramfs and tools for preparing it, you can also see [[Initramfs|wiki page about it]]. | |
− | + | ||
+ | == Installation == | ||
+ | |||
+ | You need to both install {{Package|sys-apps/systemd}} and to set the ''systemd'' USE flag. | ||
+ | Moreover, to avoid potential Portage conflicts you need to disable the ''consolekit'' USE flag as well. | ||
− | + | The easiest method is to do all this at once specifically. | |
+ | Adjust the USE flags in | ||
{{File|/etc/portage/make.conf||<pre> | {{File|/etc/portage/make.conf||<pre> | ||
USE="... systemd -consolekit ..." | USE="... systemd -consolekit ..." | ||
</pre>}} | </pre>}} | ||
− | + | and then execute | |
− | |||
{{Emerge|params+=--changed-use --deep|@world}} | {{Emerge|params+=--changed-use --deep|@world}} | ||
+ | |||
+ | Portage will install {{Package|sys-apps/systemd}} as part of this emerge | ||
+ | |||
+ | {{Warning|Some packages may now '''no longer support OpenRC'''}} | ||
== Configuration == | == Configuration == | ||
systemd supports a few system configuration files to set the most basic system details. | systemd supports a few system configuration files to set the most basic system details. | ||
− | + | ||
− | |||
=== Hostname === | === Hostname === |
Revision as of 22:22, 13 September 2013
systemd is a modern sysvinit & RC replacement for Linux systems. It is supported in Gentoo as an alternate init system.
Pre-installation Configuration
If you're updating from <=sys-apps/systemd-203 check the upgrade subpage.
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 are required: Template:Kernel
For UEFI system you'll also need to enable the following: Template:Kernel
In the case you are using BFQ scheduler, it's recommended by BFQ upstream to enable "BFQ hierarchical scheduling support" under "Enable the block layer -> IO Schedulers"
The /run directory
The /run 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 /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
Upstream only supports /etc/mtab file being a symlink to /proc/self/mounts. This has caused in the past problems problems with mount -o user and NFS mounts. On the other hand, not creating it will cause problems with mount (bug #434090) and df (bug #477240).
To create the symlink, run:
root #
ln -sf /proc/self/mounts /etc/mtab
Ensure /usr is present at boot time
Splitted /usr isn't supported and, then, you need to get it mounted at boot time. For that, you will need to follow Official Initramfs Gentoo Guide. If you want to know more about initramfs and tools for preparing it, you can also see wiki page about it.
Installation
You need to both install sys-apps/systemd and to set the systemd USE flag. Moreover, to avoid potential Portage conflicts you need to disable the consolekit USE flag as well.
The easiest method is to do all this at once specifically. Adjust the USE flags in Template:File and then execute
root #
emerge --ask --changed-use --deep @world
Portage will install sys-apps/systemd as part of this emerge
Some packages may now no longer support OpenRC
Configuration
systemd supports a few system configuration files to set the most basic system details.
Hostname
A tool called hostnamectl exists for editing /etc/hostname and etc/machine-info. To change hostname, run:
root #
hostnamectl set-hostname <HOSTNAME>
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 /etc/env.d/02locale and run env-update.
root #
localectl set-locale LANG=<LOCALE>
To change the virtual console keymap:
root #
localectl set-keymap <KEYMAP>
And finaly, to set the X11 layout:
root #
localectl set-x11-keymap <LAYOUT>
If needed you can specify the model, variant and options too:
root #
localectl set-x11-keymap <LAYOUT> <MODEL> <VARIANT> <OPTIONS>
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.
/tmp is now in tmpfs
Unless you explicitly mount some other filesystem to /tmp in your fstab, systemd will mount /tmp 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 to 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).
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 grub.conf 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. Template: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 /usr/lib/systemd/system. Thus, the simplest way of looking up available service units is listing that directory:
root #
ls /usr/lib/systemd/system
acpid.service runlevel2.target alsa-restore.service runlevel2.target.wants alsa-store.service runlevel3.target autovt@.service runlevel3.target.wants avahi-daemon.service runlevel4.target avahi-daemon.socket runlevel4.target.wants avahi-dnsconfd.service runlevel5.target basic.target runlevel5.target.wants ...
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):
root #
systemctl --all --full
And finally the systemadm graphical tool can be used. It can be installed with the sys-apps/systemd-ui package.
Installing custom service files
Any custom service files should be copied to the /etc/systemd/system directory. The /usr/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
root #
systemctl enable foo.service
Services can be disabled likewise:
root #
systemctl disable foo.service
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 wpa_supplicant on wlan0, type:
root #
ln -s /lib/systemd/system/wpa_supplicant@.service /etc/systemd/system/multi-user.target.wants/wpa_supplicant@wlan0.service
To disable the service, just remove the symlink:
root #
rm /etc/systemd/system/multi-user.target.wants/wpa_supplicant@wlan0.service
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:
Gentoo package | OpenRC service | systemd unit | Notes |
---|---|---|---|
sys-apps/openrc | bootmisc | systemd-tmpfiles-setup.service | always enabled, uses tmpfiles.d |
consolefont | systemd-vconsole-setup.service | always enabled, uses vconsole.conf | |
devfs | |||
dmesg | |||
fsck | fsck*.service | pulled in implicitly by mounts | |
functions.sh | See note | bug #373219 | |
hostname | (builtin) | /etc/hostname | |
hwclock | |||
keymaps | systemd-vconsole-setup.service | always enabled, uses vconsole.conf | |
killprocs | |||
local | |||
localmount | local-fs.target | actual units are created implicitly from fstab | |
modules | systemd-modules-load.service | always enabled, uses /etc/modules-load.d/*.conf | |
mount-ro | |||
mtab | |||
netmount | remote-fs.target | ||
net.* | netctl@.service | net-misc/netctl is originally an Arch Linux tool. | |
NetworkManager.service | You need to also enable NetworkManager-dispatcher.service for dispatcher.d scripts to work, also NetworkManager-wait-online.service to properly detect system is connected to network. | ||
dhcpcd.service | Provided by net-misc/dhcpcd | ||
numlock | |||
procfs | (builtin) | ||
root | remount-rootfs.service | ||
savecache | n/a | OpenRC internals | |
staticroute | |||
swap | swap.target | actual units are created implicitly from fstab | |
swclock | |||
sysctl | systemd-sysctl.service | sysctl.conf and sysctl.d/ | |
sysfs | (builtin) | ||
termencoding | systemd-vconsole-setup.service | always enabled, uses vconsole.conf | |
urandom | systemd-random-seed-load.service | ||
systemd-random-seed-save.service | |||
app-admin/rsyslog | rsyslog | rsyslog.service | |
app-admin/syslog-ng | syslog-ng | syslog-ng.service | |
media-sound/alsa-utils | alsasound | alsa-store.service | (enabled by default) |
alsa-restore.socket | (enabled by default) | ||
net-misc/dhcpcd | dhcpcd | dhcpcd.service | |
net-misc/openntpd | ntpd | ntpd.service | (enabled by default) |
net-misc/openssh | sshd | sshd.service | runs sshd as a daemon |
sshd.socket | runs sshd on a inetd-like basis (for each incoming connection) | ||
net-misc/wpa_supplicant | wpa-supplicant | wpa_supplicant.service | D-Bus controlled daemon (e.g. for NetworkManager) |
wpa_supplicant@.service | interface-specific wpa_supplicant (used like wpa_supplicant@wlan0.service) | ||
net-print/cups | cupsd | cups.service | classic on-boot start up service |
cups.socket | socket and path activation (cups only started on-demand) | ||
cups.path | |||
net-wireless/bluez | bluetooth | bluetooth.service | |
sys-apps/dbus | dbus | dbus.service | |
dbus.socket | |||
sys-apps/irqbalance | irqbalance | irqbalance.service | supports daemon mode only |
sys-apps/microcode-ctl | microcode_ctl | Configure microcode as a module to let it load the microcode itself. Go to "Processor type and features" -> "CPU microcode loading support" and remember to add the option you need depending on you having intel or amd processor. | |
sys-fs/udev | udev | udev.service | |
udev-mount | (builtin) | /dev is mounted as tmpfs | |
udev-postmount | udev-trigger.service | ||
udev-settle.service | |||
sys-power/acpid | acpid | acpid.service | Most of its functionality is done by systemd itself, then, maybe you could consider to stop enabling this |
x11-apps/xdm | (xdm) | xdm.service | OpenRC uses common xdm init.d installed by x11-base/xorg-server. With systemd you will need to enable corresponding unit file for each DM (gdm.service, kdm.service...) |
Troubleshooting
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 kde-misc/networkmanagement not being able to detect NetworkManager is running, modify your system-auth file to add pam_systemd. Template:File
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 sys-auth/pambase.
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.
systemd-bootchart
syslog-ng
Systemd creates /dev/log as datagram socket [1] [2] so you will need to tell syslog-ng to read from a unix-dgram instead of a unix-stream: Template:File should be replaced with: Template:File in order to use the syslog-ng service in systemd.
sys-fs/cryptsetup
Systemd doesn't seem to respect /etc/conf.d/dmcrypt (bug #429966 ?): Template:File
Check for units that failed to start
To check for units that failed to start you can run:
root #
systemctl --failed
Enable Debug Mode
To get more informations you need to set the following in /etc/systemd/system.conf: Template:File