Migration from initscripts to systemd on Archlinux

systemd is a system and service manager for Linux. It is a replacement for sysvinit. It provides an improved way of booting up the system (allowing more work to be done in parallel at system startup) and also to manage services. “systemd” appears a remarkable adoption from many Linux distributions. Some of them are Fedora, Mandriva, openSUSE, ArchLinux. In Debian and Gentoo systemd is available, but not enabled by default. Inclusion in Red Hat Enterprise Linux 7 is also planned.

In short, except Ubuntu who has developed its own startup manager, almost all the rest distributions will use systemd as system and service manager.

Archlinux included systemd since October 2012. From now, initscripts will be dropped from various packages. Any users still using them should switch to systemd.

This is just a practical guide for migration to systemd in Archlinux. In order to be useful, you have to read carefully the basics about systemd at:

systemd setup

First make a copy of your rc.conf

sudo cp /etc/rc.conf /data/tmp/rc.conf.bak

systemd must be installed during a system upgrade. Partial upgrades are unsupported in Archlinux.

Full system update:

sudo pacman -Syu

Then remove sysvinit and install systemd-sysvcompat

sudo pacman -Rns sysvinit initscripts
sudo pacman -S systemd-sysvcompat

systemd should have been installed during system upgrade, otherwise last command should be:

sudo pacman -S systemd systemd-sysvcompat

Configuration files needed by systemd

systemd needs some configuration files to hold information, which /etc/rc.conf kept until now to your system:

As root:

nano /etc/hostname

Add a line with your hostname, in my case:

athena


nano /etc/timezone

Add a line with your timezone, in my case:

Europe/Athens


nano /etc/vconsole.conf

Add appropriate values, in my case:

FONT_MAP=
KEYMAP=us
FONT=


nano /etc/locale.conf

Add appropriate values, in my case:

LANG=en_US.UTF-8


Add modules definitions in /etc/modules-load.d/, in my case:

nano /etc/modules-load.d/nfsd.conf

nfsd

nano /etc/modules-load.d/vboxdrv.conf

vboxdrv

nano /etc/modules-load.d/vboxnetadp.conf

vboxnetadp

nano /etc/modules-load.d/vboxnetflt.conf

vboxnetflt

There is a helper tool which can perform the above task for you. Find it on Github: arch-linux-SysV-to-systemd-migrationscript. This script will parse your /etc/rc.conf and generate the above config files.

Create service files

At this time, only a part of information existed in /etc/rc.conf has been migrated using the “systemd” way. Another task is to tranform DAEMONS array members to systemd services. In my case DEAMONS array was:

DAEMONS=(syslog-ng network crond sshd !hwclock ntpd apcupsd rpcbind nfs-common alsa dbus samba cupsd webmin exim httpd mysqld)

For each DEAMONS element you have to create a service file at /etc/systemd/system/ folder. Fortunately, these files exist at /usr/lib/systemd/system/

For example to start Apache at boot, give:

systemctl enable httpd.service

Archlinux will create the appropriate symbolic links. Example:

ls -la /etc/systemd/system/multi-user.target.wants/

Result:

drwxr-xr-x 2 root root 4096 Apr  4 22:50 .
drwxr-xr-x 6 root root 4096 Apr  4 18:26 ..
lrwxrwxrwx 1 root root   39 Apr  4 14:50 apcupsd.service -> /usr/lib/systemd/system/apcupsd.service
lrwxrwxrwx 1 root root   44 Apr  4 15:12 avahi-daemon.service -> /usr/lib/systemd/system/avahi-daemon.service
lrwxrwxrwx 1 root root   46 Apr  4 15:13 avahi-dnsconfd.service -> /usr/lib/systemd/system/avahi-dnsconfd.service
lrwxrwxrwx 1 root root   33 Apr  4 18:26 cups.path -> /usr/lib/systemd/system/cups.path
lrwxrwxrwx 1 root root   36 Apr  4 14:55 exim.service -> /usr/lib/systemd/system/exim.service
lrwxrwxrwx 1 root root   37 Apr  4 14:37 httpd.service -> /usr/lib/systemd/system/httpd.service
lrwxrwxrwx 1 root root   38 Apr  4 14:55 mysqld.service -> /usr/lib/systemd/system/mysqld.service
lrwxrwxrwx 1 root root   35 Apr  4 22:50 network.service -> /etc/systemd/system/network.service
lrwxrwxrwx 1 root root   36 Apr  4 14:53 nfsd.service -> /usr/lib/systemd/system/nfsd.service
lrwxrwxrwx 1 root root   36 Apr  4 15:10 ntpd.service -> /usr/lib/systemd/system/ntpd.service
lrwxrwxrwx 1 root root   40 Mar 22 14:34 remote-fs.target -> /usr/lib/systemd/system/remote-fs.target
lrwxrwxrwx 1 root root   39 Apr  4 14:53 rpcbind.service -> /usr/lib/systemd/system/rpcbind.service
lrwxrwxrwx 1 root root   36 Apr  4 14:53 sshd.service -> /usr/lib/systemd/system/sshd.service
lrwxrwxrwx 1 root root   41 Apr  4 14:54 syslog-ng.service -> /usr/lib/systemd/system/syslog-ng.service
lrwxrwxrwx 1 root root   38 Apr  4 14:54 webmin.service -> /usr/lib/systemd/system/webmin.service

Static IP Ethernet network

systemd network.service must be created manually. An example is provided in ArchWiki here: Static Ethernet network

sudo nano /etc/conf.d/network

interface=eth0
address=192.168.1.51
netmask=24
broadcast=192.168.1.255
gateway=192.168.1.1

sudo nano /etc/systemd/system/network.service

[Unit]
Description=Network Static IP
Wants=network.target
Before=network.target
BindsTo=sys-subsystem-net-devices-eth0.device
After=sys-subsystem-net-devices-eth0.device

[Service]
Type=oneshot
RemainAfterExit=yes
EnvironmentFile=/etc/conf.d/network
ExecStart=/sbin/ip link set dev eth0 up
ExecStart=/sbin/ip addr add 192.168.1.51/24 dev eth0
ExecStart=/sbin/ip route add default via 192.168.1.1

ExecStop=/sbin/ip addr flush dev eth0
ExecStop=/sbin/ip link set dev eth0 down

[Install]
WantedBy=multi-user.target

Reboot

Reboot your system. If everything has gone well, you will notice a faster system startup.

systemd basic commands

With UNIT we mean the unit/service name (for example: mysqld.service)

  • Enable (run on startup):
    systemctl enable UNIT
    
  • Disable:
    systemctl disable UNIT
    
  • Get UNIT status:
    systemctl status UNIT
    
  • List units/services:
    systemctl list-unit-files
    
  • Start manually:
    systemctl start UNIT
    
  • Stop manually:
    systemctl stop UNIT
    
  • Restart manually:
    systemctl restart UNIT
    
  • Reload UNIT configuration:
    systemctl reaload UNIT
    
  • Analyse boot process:
    systemd-analyze
    

    example:

    Startup finished in 4496ms (kernel) + 19558ms (userspace) = 24054ms
    
  • Analyse boot process (details):
    systemd-analyze blame | less
    
  • Analyse boot process (graph):
    systemd-analyze plot > /path/to/result.svg
    
  • Reboot:
    systemctl reboot
    
  • Halt:
    systemctl halt
    
  • Poweroff:
    systemctl poweroff
    

Open in new tab image below to see (in details) systemd-analyze plot in my system as SVG file:

systemadm: systemd System Manager graphic GUI

systemadm is the official graphical frontend for systemctl. You may install it from AUR using:

yaourt systemd-ui-git

Well, it seems that systemd will become the default init and service manager for the most Linux distributions. What do you think? Leave us a comment.