From 876c5bdf3e718970fb454483901ca94fc4de1721 Mon Sep 17 00:00:00 2001 From: Lyndon Brown Date: Wed, 25 Aug 2021 03:48:53 +0100 Subject: [PATCH] debootstrap: fix use of sysvinit if the user wants sysvinit rather than systemd, we must instruct debootstrap to include `sysvinit-core` and exclude `systemd`, `systemd-sysv` and possibly also `systemd-timesyncd` via the `--include` and `--exclude` options respectively. the existing addition of `sysvinit-core` via a chroot package-list was inadequate to make things work and is redundant now, so it has been removed from the config script. unfortunately due to #776917, as explained at [1], debootstrap does not actually work properly when you try to switch the init system just using `--include` and `--exclude` as above. i tested this on sid and confirmed that this is still the case, both the sysvinit packages and the systemd packages ended up installed together. thus i have had to implement the workaround from [1] which involves using debootstrap's alternative two-step mode, and removing systemd from a package installation list in between. i found that the details at [1] were a bit outdated so i had to adjust the solution slightly: - the `systemd` and `systemd-sysv` packages are now listed in the `base` file rather than `required`. there is also `systemd-timesyncd` there which should no doubt also be removed also. - the contents of the `required` file is no longer a space separated list, though we don't need to modify it anymore. `base` is currently a space separated list. i additionally noted that the `required` file contains `libsystemd0` and i thus tried removing that, however it turns out that `apt` depends upon it and removing it consequently causes debootstrap to fail. the use of the "proper" `--include`/`--exclude` solution remains in this commit despite not working on its own because it neatly lets the package cache code include the sysvinit packages in its caching operations. if/when debootstrap fixes the problem, we can remove everything added here with the exception of the initial few `--include`/`--exclude` lines. [1]: https://www.notinventedhere.org/articles/linux/debootstrapping-debian-jessie-without-systemd.html Gbp-Dch: Short Closes: #992916 --- scripts/build/bootstrap_debootstrap | 31 +++++++++++++++++++++++++++++ scripts/build/config | 2 +- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/scripts/build/bootstrap_debootstrap b/scripts/build/bootstrap_debootstrap index e0278844c..fe8d28f8c 100755 --- a/scripts/build/bootstrap_debootstrap +++ b/scripts/build/bootstrap_debootstrap @@ -76,6 +76,11 @@ else DEBOOTSTRAP_OPTIONS="${DEBOOTSTRAP_OPTIONS} --force-check-gpg" fi +if [ "${LB_INITSYSTEM}" = "sysvinit" ] +then + DEBOOTSTRAP_OPTIONS="${DEBOOTSTRAP_OPTIONS} --include=sysvinit-core --exclude=systemd,systemd-sysv,systemd-timesyncd" +fi + if [ "${LB_CACHE_PACKAGES}" = "true" ] then if ls cache/packages.bootstrap/*.deb > /dev/null 2>&1 @@ -99,6 +104,17 @@ fi Print_breakage Echo_message "Running debootstrap..." +Disable_systemd_hack () +{ + # note, these cope with both a space separated list form and one package per line form to + # account for potential differences between debootstrap versions. + # note, do **not** try to remove `libsystemd0` from `chroot/debootstrap/required`, this is + # required by `apt` and will break the setup. + sed -i -e 's/ systemd / /g' -e '/systemd/d' chroot/debootstrap/base + sed -i -e 's/ systemd-sysv / /g' -e '/systemd-sysv/d' chroot/debootstrap/base + sed -i -e 's/ systemd-timesyncd / /g' -e '/systemd-timesyncd/d' chroot/debootstrap/base +} + # Run appropriate bootstrap, i.e. foreign or regular bootstrap if [ "${LB_BOOTSTRAP_QEMU_ARCHITECTURE}" = "${LB_ARCHITECTURE}" ]; then @@ -110,9 +126,24 @@ if [ "${LB_BOOTSTRAP_QEMU_ARCHITECTURE}" = "${LB_ARCHITECTURE}" ]; then Echo_message "Bootstrap will be foreign" debootstrap ${DEBOOTSTRAP_OPTIONS} --foreign "${LB_PARENT_DISTRIBUTION_CHROOT}" chroot "${LB_PARENT_MIRROR_BOOTSTRAP}" ${DEBOOTSTRAP_SCRIPT} + if [ "${LB_INITSYSTEM}" = "sysvinit" ]; then + Disable_systemd_hack + fi + Echo_message "Running debootstrap second stage under QEMU" cp ${LB_BOOTSTRAP_QEMU_STATIC} chroot/usr/bin Chroot chroot /bin/sh /debootstrap/debootstrap --second-stage ${FOREIGN_DEBOOTSTRAP_OPTIONS} + +elif [ "${LB_INITSYSTEM}" = "sysvinit" ]; then + + Echo_message "Performing first stage of two-stage setup for sysvinit issue workaround" + debootstrap ${DEBOOTSTRAP_OPTIONS} --foreign "${LB_PARENT_DISTRIBUTION_CHROOT}" chroot "${LB_PARENT_MIRROR_BOOTSTRAP}" ${DEBOOTSTRAP_SCRIPT} + + Disable_systemd_hack + + Echo_message "Running debootstrap second stage" + Chroot chroot /bin/sh /debootstrap/debootstrap --second-stage ${FOREIGN_DEBOOTSTRAP_OPTIONS} + else debootstrap ${DEBOOTSTRAP_OPTIONS} "${LB_PARENT_DISTRIBUTION_CHROOT}" chroot "${LB_PARENT_MIRROR_BOOTSTRAP}" ${DEBOOTSTRAP_SCRIPT} fi diff --git a/scripts/build/config b/scripts/build/config index 804401740..3a068536f 100755 --- a/scripts/build/config +++ b/scripts/build/config @@ -1372,7 +1372,7 @@ if [ ! -e "${LIVE_PKG_LIST}" ]; then ;; sysvinit) - NEEDED_PACKAGES="${NEEDED_PACKAGES} live-config-sysvinit sysvinit-core" + NEEDED_PACKAGES="${NEEDED_PACKAGES} live-config-sysvinit" ;; esac fi