systemd

Revision 6 as of 2010-12-19 04:29:17

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.

A unit properly belongs in the package of the daemon that it starts. systemd units are already shipped by some upstream packages. They will probably appear in Ubuntu packages in due course, unless Ubuntu maintainers deliberately remove them. At that point the corresponding units can be removed from systemd-extra-units, which exists only as a temporary measure.

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

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