guest: keep systemd from taking over a Debian boot: the base's init execs /usr/local/sbin/kw-init where the image has it (a package that pulls in systemd-sysv replaces /sbin/init, and systemd as PID 1 waits for dev-hvc0.device), an apt pin keeps systemd-sysv out (desktop packages then take dbus-x11, and sysv-rc stays), and kw-init boots without services where sysv-rc is already gone

This commit is contained in:
Pooya Parsa
2026-11-22 09:39:13 +00:00
parent 57249c59e9
commit 85c746562f
5 changed files with 29 additions and 7 deletions

View File

@@ -37,8 +37,8 @@ missing).
`upper=data|tmpfs|none`, `why=`, `state=`, `dev=`, `fstype=`) for
`kw-overlay`, `data-stop` and the page.
- **Safe mode** is deterministic and for one boot: before the switch the
merged root is checked (its `/bin/sh` runs under `chroot`, `/sbin/init`
is executable). If that fails, or the overlay does not mount, this boot
merged root is checked (its `/bin/sh` runs under `chroot`, its init,
`/usr/local/sbin/kw-init` or else `/sbin/init`, is executable). If that fails, or the overlay does not mount, this boot
runs the image on a tmpfs upper with `/data` mounted and the data upper
untouched, and says `kw-overlay: SAFE MODE: <reason>`; the next boot
checks again, so a repair in `/data/distros/NAME/upper` (from the safe

View File

@@ -125,7 +125,8 @@ UNKERNEL_TEST_KERNEL=/tmp/b/unkernel.wasm UNKERNEL_TEST_DISTRO_DIR=/tmp/d pnpm t
`/usr/lib/kw-image` and prints the image id last. It gets `KW_DISTRO`
and `KW_DISTRO_DIR` from the driver.
3. `distro/NAME/rootfs/`: at least an executable `/sbin/init` (or what it
links to). The base has mounted `/dev`, `/proc`, `/sys`, `/run`, `/tmp`
links to), or `/usr/local/sbin/kw-init`, which the base execs first
(where a package manager may replace `/sbin/init`: Debian). The base has mounted `/dev`, `/proc`, `/sys`, `/run`, `/tmp`
and `/data`; init runs `/usr/lib/kw/rc`, `/usr/lib/kw/welcome` and
`/usr/lib/kw/net`, keeps `/usr/bin/kwtty login` on hvc0 (the console's
shell, as the image's user) and `/usr/bin/kwtty serve` running, and at

View File

@@ -2,7 +2,11 @@
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2026 Pooya Parsa <pooya@pi0.io>
# /init of the base initramfs (guest/base/build.sh): find the distro image,
# make the root an overlay of it, and exec its /sbin/init.
# make the root an overlay of it, and exec its init: /usr/local/sbin/kw-init
# where the image has one (an init of ours, where no package puts files:
# on Debian a package that pulls in systemd-sysv replaces /sbin/init, and
# the next boot would be systemd's, which does not come up here), else
# /sbin/init.
#
# 1. devtmpfs, proc, sysfs and a tmpfs on /run;
# 2. /data: the data disk (ext4 labelled kwdata), if the host attached one;
@@ -14,7 +18,7 @@
# else (no data disk, safe mode, kw.root=initramfs) a tmpfs at /kw/tmp;
# 5. the root: overlay of /kw/layer (the kw tools and runtime, on top) and
# /kw/distro under that upper layer, checked (the merged /bin/sh runs,
# /sbin/init is executable), then pivot_root with this root at
# its init is executable), then pivot_root with this root at
# /run/kw-lower, /dev /proc /sys /run /data moved along and a tmpfs on
# /tmp.
#
@@ -156,10 +160,11 @@ root() {
mount -t overlay overlay -o "lowerdir=/kw/layer:/kw/distro,upperdir=$1,workdir=$2,redirect_dir=off,index=off,xino=off,metacopy=off" /mnt
}
# Whether the merged root can boot: its /bin/sh runs (a broken shell or C
# library shows up here) and /sbin/init is executable. Sets $bad.
# library shows up here) and its init (kw-init, else /sbin/init) is
# executable. Sets $bad.
check() {
bad=
chroot /mnt /bin/sh -c '[ -x /sbin/init ]' 2>/dev/null && return 0
chroot /mnt /bin/sh -c '[ -x /usr/local/sbin/kw-init ] || [ -x /sbin/init ]' 2>/dev/null && return 0
if chroot /mnt /bin/sh -c : 2>/dev/null; then
bad="/sbin/init is missing or not executable"
elif [ -e /mnt/bin/sh ] || [ -L /mnt/bin/sh ]; then
@@ -214,4 +219,5 @@ if ! cd /mnt || ! pivot_root . run/kw-lower; then
base_shell "pivot_root into the overlay failed"
fi
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
[ ! -x /usr/local/sbin/kw-init ] || exec /usr/local/sbin/kw-init
exec /sbin/init

View File

@@ -0,0 +1,12 @@
# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2026 Pooya Parsa <pooya@pi0.io>
Explanation: unkernel: PID 1 is /usr/local/sbin/kw-init, which runs services
Explanation: through sysv-rc. systemd-sysv would replace /sbin/init and remove
Explanation: sysv-rc (systemd does not boot here), and desktop packages reach
Explanation: it through dbus-user-session and libpam-systemd; without it apt
Explanation: takes their other alternatives (dbus-x11). systemd itself, not as
Explanation: init, installs fine.
Package: systemd-sysv
Pin: release *
Pin-Priority: -1

View File

@@ -34,6 +34,9 @@ rc() {
local links="/etc/rc$2.d/[SK][0-9][0-9]*"
[ "$1" != N ] || links="/etc/rc$2.d/S[0-9][0-9]*"
compgen -G "$links" >/dev/null || return 0
# No sysv-rc (a disk from before /etc/apt/preferences.d/kw-init, where a
# package had apt replace it with systemd): no services, the boot goes on.
[ -x /etc/init.d/rc ] || return 0
RUNLEVEL=$2 PREVLEVEL=$1 /etc/init.d/rc "$2"
}
rc N 2