systemd

Revision 9 as of 2010-12-19 12:28:11

Clear message

systemd - An alternative boot manager

systemd is a system and session 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.

See the systemd home page for further information.

Warning! Experimental code

systemd is under active development. It has not yet been shipped in a production release of a major Linux distro.

Current versions of systemd require that you customize your kernel as well as running a non-standard init process. These are pretty intrusive changes.

Installing systemd may limit the amount of help and support available to you. If you have a commercial support agreement then installing systemd would almost certainly invalidate it. Even if you rely on forums etc, you will probably have to reproduce problems on a standard Ubuntu build before anyone can help you much.

If you want to quickly try out systemd, it may be a good idea to create a "sandpit" system for the purpose (e.g. a virtual machine that you can easily re-install or delete afterwards). If you are installing systemd on a system containing data that you care about, please take a full backup first, and make a plan for restoring from backup in the event that the system ends up unbootable.

Status as at December 2010

systemd on Ubuntu can boot the system to the desktop with networking configured and a reasonable number of services running. Some services are not started. This is because they have been converted to "native" upstart jobs in Ubuntu. systemd parses traditional sysvinit boot scripts (under /etc/init.d) but does not parse native upstart jobs (under /etc/init).

Package systemd-extra-units ships additional units (configuration files) that replace the native upstart jobs. Additional services could be started by adding further units to this package.

Personal Package Area location

systemd and related packages are available on this PPA To use the PPA, first add it to your software sources list as follows.

add-apt-repository ppa:andrew-edmunds/ppa
apt-get update

Kernel requirements

systemd requires the directory /sys/fs/cgroup as a mountpoint. It doesn't exist in the current Ubuntu kernel (2.6.35). It can't be created with mkdir either because sysfs doesn't allow that. To create the directory this patch from the 2.6.36 kernel must be backported.

The following kernel config options must be selected. The standard Ubuntu kernel meets these config requirements.

General setup  --->
     [*] Control Group support
Device Drivers --->
     Generic Driver Options  --->
          [*] Maintain a devtmpfs filesystem to mount at /dev
          [*]   Automount devtmpfs at /dev, after the kernel mounted the rootfs (NEW)
File systems --->
     < > Kernel automounter support
     <*> Kernel automounter version 4 support (also supports v3)

A suitably patched kernel is available on the PPA. You can install it as follows.

apt-get install linux-image-2.6.35-23-generic=2.6.35-23.41ppa1 linux-headers-2.6.35-23-generic=2.6.35-23.41ppa1 linux-headers-2.6.35-23=2.6.35-23.41ppa1

If you prefer to build your own kernel you will need to apply the patch mentioned above and select the appropriate config options.

Installing systemd

systemd can be installed from the PPA as follows.

apt-get install systemd libpam-systemd systemd-gui systemd-extra-units

This results in systemd being installed alongside upstart. If you were going to try replacing upstart altogether then you would need the additional package systemd-sysv, which provides replacements for commands such as reboot.

Boot loader configuration

After installation, the machine will still boot under upstart by default. To boot under systemd, the following argument must be specified on the kernel command line:

init=/bin/systemd

Note that systemd resides in /bin rather than /sbin.

To make a boot menu entry that boots with systemd, first find the menuentry stanza in /boot/grub/grub.cfg for your patched kernel. Copy it to /etc/grub.d/40_custom and then:

  • modify the menu entry name
  • modify the kernel command line to include init=/bin/systemd

Here is an example /etc/grub.d/40_custom file. Note that you cannot just copy this example literally because the UUID will not be correct for your system.

exec tail -n +3 $0
# This file provides an easy way to add custom menu entries.  Simply type the
# menu entries you want to add after this comment.  Be careful not to change
# the 'exec tail' line above.
menuentry 'Ubuntu, 2.6.35-23-generic and systemd' --class ubuntu --class gnu-linux --class gnu --class os {
        recordfail
        insmod part_msdos
        insmod ext2
        set root='(hd0,msdos1)'
        search --no-floppy --fs-uuid --set 552e0817-f1b2-4c99-b2b0-4e1ac4fd9a01
        linux   /boot/vmlinuz-2.6.35-23-generic root=UUID=552e0817-f1b2-4c99-b2b0-4e1ac4fd9a01 ro   crashkernel=384M-2G:64M,2G-:128M init=/bin/systemd
        initrd  /boot/initrd.img-2.6.35-23-generic
}

To boot under systemd by default, edit /etc/default/grub and specify the custom menu entry for systemd as the default one. Continuing with the example above, the relevant line would be changed to read as follows.

GRUB_DEFAULT="Ubuntu, 2.6.35-23-generic and systemd"

After modifying any of /etc/default/grub or any files in /etc/grub.d the following command is needed to bring the changes into effect.

update-grub

/etc/mtab

systemd prints the following warning on boot:

/etc/mtab is not a symlink or not pointing to /proc/self/mounts. This is not supported anymore. Please make sure to replace this file by a symlink to avoid incorrect or misleading mount(8) output.

It is advisable to do as suggested and replace /etc/mtab. It is not only mount that will behave incorrectly otherwise, but also df and probably most other commands that look at the list of mounted filesystems. This change can be made as follows.

ln -fs /proc/self/mounts /etc/mtab

Using systemd

Booting

To boot under systemd, select the boot menu entry that you created for the purpose. If you didn't bother to create one, just select the entry for your patched kernel, edit the kernel command line directly in grub and add init=/bin/systemd.

If a normal boot under systemd is not successful then it is worth trying with the following parameters:

init=/bin/systemd systemd.unit=emergency.service
  • systemd.unit= specifies the target state that the system should boot to (similar to specifying a run level under sysvinit).

  • emergency.service launches an emergency bash shell on the console without attempting to start any other services.

Controlling systemd once booted

The main command used to control systemd is systemctl. Some of its subcommands are as follows.

  • systemctl list-units - List all units (where unit is the term for a job/service)

  • systemctl start [NAME...] - Start (activate) one or more units
  • systemctl stop [NAME...] - Stop (deactivate) one or more units
  • systemctl enable [NAME...] - Enable one or more unit files
  • systemctl disable [NAME...] - Disable one or more unit files
  • systemctl reboot - Shut down and reboot the system

For the complete list, see systemctl(1).

systemadm is the GUI equivalent to systemctl, if you like that sort of thing.

Remote filesystem mounts

If you have NFS mounts listed in /etc/fstab then systemd will attempt to mount them but will typically do so too early, before networking has been configured. To get the timing correct we need to tell systemd explicitly that the mount depends on networking and on rpc.statd. To do this, create a file under /lib/systemd/system named <mount-unit-name>.mount with contents as follows.

[Unit]
Description=<mountpoint>
Wants=network.target statd.service
After=network.target statd.service 

[Mount]
What=<server>:<share>
Where=<mountpoint>
Type=nfs
StandardOutput=syslog
StandardError=syslog

In the above

  • mount-unit-name is the full path to the mountpoint in an escaped format. For example, a mount unit for /usr/local must be named usr-local.mount.

  • mountpoint is the local mountpoint

  • server:share specify the remote filesystem in the same manner as for /etc/fstab

See systemd.unit(5) and systemd.mount(5) for further details.

A similar approach will probably be required for other remote filesystem types such as nfs4 and cifs

Implementation issues

Packaging of units

A unit properly belongs in the package of the daemon that it starts. systemd units are already included in some upstream packages and some Debian Experimental packages. They will probably appear in Ubuntu packages in due course, unless Ubuntu maintainers deliberately remove them.

The systemd-extra-units package is intended only to make systemd usable in the short term by shipping some important units that don't yet exist in other Ubuntu packages. It should be scaled back as and when units start to appear in their proper places, and should eventually be dropped.

Dependencies on things not yet available in Ubuntu

Upstream systemd depends on recent upstream changes to several other packages that are not yet available in Ubuntu. These have been worked around by reverting the relevant changes in systemd or disabling the relevant feature. In brief these are:

  • systemd 15 wants libnotify >= 0.7 and vala 0.11

    • Relevant changes have been reverted in order to build with libnotify 0.5.0 and vala 0.9.
  • systemd wants /sbin/agetty but Debian/Ubuntu renames it to /sbin/getty

    • /sbin/agetty will be added as a link in Debian wheezy (Debian bug 603786).

  • systemd invokes agetty -s where the option -s was added by recent upstream commits in util-linux.

    • Units getty@.service and serial-getty@.service have been patched to remove this option.

  • systemd-fsck invokes fsck -l where the option -l was added by recent upstream commits in util-linux

    • systemd-fsck has been patched to remove this option.

Networking

NetworkManager.service just starts NetworkManager and does not wait for it to bring up a network interface. This seems appropriate, but network.target should not become active until a network connection is up. An extra unit, wait-for-network.service, has been created to delay network.target.

The appropriate way to wait for a network connection with NetworkManager appears to be nm-online, but this binary is not shipped in the Debian or Ubuntu packages for some reason. For systemd-extra-units 0.2 a simple shell loop has been used. This is effective, but hardly in the spirit of systemd.

TODO: Ask whether nm-online could be shipped in the network-manager package, or re-implement something similar if not.

Remote filesystem mounts

systemd reads /etc/fstab and automatically creates a mount unit for each entry. The automatically generated dependencies for these units are insufficient in the case of remote filesystems. The correct dependencies can be specified explicitly in a mount unit configuration file (see above) but ideally this should be handled automatically.

Proposal: When parsing an /etc/fstab entry, systemd should look for a unit template named after the filesystem type (e.g. nfs@.mount for an NFS mount). If a template is found it should be used, with appropriate substitutions. Otherwise systemd should fall back to creating the mount unit with default settings as per the current behaviour.

TODO: Write a patch for this and propose it upstream.

/etc/default

Existing sysvinit style scripts read configuration in the form of variable assignments from a file under /etc/default. A policy decision is needed on whether systemd units will do the same.

Advantages: Separates configuration from code, simplifies package upgrade (i.e. same reasoning that applies to the existing sysvinit scripts).

Disadvantages: Extra complexity. Some may argue that systemd units are simple enough to be treated entirely as configuration files.

/etc/default files can be read using the EnvironmentFile= parameter in a systemd service unit. However, this is not fully compatible with the shell. In particular the quoting rules differ. It is not possible to write an environment variable assignment containing whitespace or literal quotes in a way that both a legacy init script and systemd will understand.

TODO: Decide whether systemd will use /etc/default files. Needs discussion with Debian maintainers. There would be little benefit in Ubuntu going it's own way on this.

TODO: Finish off patch for shell compatible quoting support and submit upstream.