How to remove systemd from a Debian Stretch installation

From Without Systemd
Jump to: navigation, search

Contents

Using sysvinit instead of systemd in Debian Stretch

Required steps

  1. Install the sysvinit packages: apt-get install sysvinit-core
  2. Copy inittab: cp /usr/share/sysvinit/inittab /etc/inittab
  3. Reboot the system: reboot

Optional steps

  1. Install udisks2 and/or policykit if needed for graphical desktops or build them from Debian sources by applying a small patch.
  2. Remove the systemd packages, including libpam-systemd: apt-get remove --purge --auto-remove systemd
  3. Prevent apt from installing systemd-related packages in the future: echo -e 'Package: *systemd*\nPin: release *\nPin-Priority: -1\n' > /etc/apt/preferences.d/systemd



Using sysvinit instead of systemd in Debian Stretch (variant)

Required steps

  1. Configure the nosystemd repo: echo -e 'deb http://angband.pl/debian/ nosystemd-stretch main' > /etc/apt/sources.list.d/nosystemd.list
  2. Configure the nosystemd apt preference: Note: libsystemd0 does not need to be removed as it is harmless without systemd itself.
    echo -e 'Package: *\nPin: origin angband.pl\nPin-Priority: 1100\n' > /etc/apt/preferences.d/nosystemd
    echo -e 'Package: libsystemd0\nPin: version *\nPin-Priority: 500\n' >> /etc/apt/preferences.d/nosystemd
    echo -e 'Package: *systemd*\nPin: release *\nPin-Priority: -1\n' >> /etc/apt/preferences.d/nosystemd
  3. Get the GPG key for the repo: wget -qO - http://angband.pl/deb/archive.html | apt-key add -
    -OR-
    apt-get install kilobyte-archive-keyring
  4. Install the sysvinit packages: apt-get install sysvinit-core sysvinit-utils
  5. Copy inittab: cp /usr/share/sysvinit/inittab /etc/inittab
  6. Reboot the system: reboot

Optional steps

  1. Remove the systemd packages, including libpam-systemd: apt-get purge systemd*
  2. For graphical desktops, systemd independent udisks2 and/or policykit will be pulled from the repo above.


Using Debian Installer preseed.cfg

If you're installing a number of Debian machines you can use a preseed file to set up custom settings. This is especially useful for unattended installs, for instance for KVM guests. The easiest way to get settings into the post-install routine is via a script. In this example the script will be served by a local web-server running from apt-cacher-ng. In my case, this server runs on the local address 192.168.122.1, which is also the local DHCP server that the KVM instances get their IP addresses and hostnames from.

set up your preseed.cfg file with the following options:

...
# sets the proxy for apt packages
d-i mirror/http/proxy string http://192.168.122.1:3142
# 
# let's do the post-install bit with a script
# this script is being served via apt-cacher-ng in a mapped directory
# post install script, NB, you don't need to refer to `target` in the script as we chroot
d-i preseed/late_command string \
   cd /target; \
   wget http://192.168.122.1:3142/preseed/post_install.sh; \
   chmod +x ./post_install.sh; \
   chroot ./ ./post_install.sh; \
   rm -f ./post_install.sh

you'll notice that this preseed late_command simplifies things for us as we can now put arbitary commands in a post_install.sh script and it will be run chrooted in the new install.

my post_install.sh looks like this

#!/bin/bash
# this post install script is run from the target installation under chroot
# to see the log of this script starting, see `/var/log/installer/syslog` on target
echo "Post install started on `date`" > /root/manifest
echo "* Set proxy and pin..." >> /root/manifest
echo -e 'deb http://angband.pl/debian/ nosystemd-stretch main' > /etc/apt/sources.list.d/nosystemd.list
echo 'Acquire::http::proxy "http://192.168.122.1:3142/";' > /etc/apt/apt.conf.d/01proxy
echo -e 'Package: *\nPin: origin angband.pl\nPin-Priority: 1100\n' > /etc/apt/preferences.d/nosystemd
echo -e 'Package: libsystemd0\nPin: version *\nPin-Priority: 500\n' >> /etc/apt/preferences.d/nosystemd
echo -e 'Package: *systemd*\nPin: release *\nPin-Priority: -1\n' >> /etc/apt/preferences.d/nosystemd
echo "* Remove systemd..." >> /root/manifest
apt-get install -y sysvinit-core
wget -qO - http://angband.pl/deb/archive.html | apt-key add -
apt-get update

When you reboot the new install, you can then purge systemd if you like. Or you could also add this little trick to the end of the script to remove systemd automatically on first boot

# set command to run on first boot, we'll use a command in /etc/rc.local that self erases 
# delete last line of `rc.local` (i.e `exit 0)
sed -i '$ d' /etc/rc.local
# insert our post-install command, which will self-destruct!
cat <<EOT >> /etc/rc.local
#SNIP-START
apt-get purge systemd*
sed -i '/#SNIP-START/,/#SNIP-END/d' /etc/rc.local
#SNIP-END
exit 0
EOT

Support status

A January 2017 bug report discussion and a February 2017 mailing list thread indicate that Debian developers are continuing to support sysvinit.

Personal tools