]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test: check if we correctly propagate /run mounts during switch root 28497/head
authorFrantisek Sumsal <frantisek@sumsal.cz>
Wed, 19 Jul 2023 12:26:26 +0000 (14:26 +0200)
committerLuca Boccassi <bluca@debian.org>
Mon, 24 Jul 2023 09:39:14 +0000 (10:39 +0100)
Since 7c764d4 we bind mount certain directories during switch root
instead of moving the mount directly, and for /run we do this without
MS_REC. This, unfortunately, leaves all mounts under /run behind
in the old root, which breaks certain use cases.

See: https://github.com/systemd/systemd/issues/28452

test/TEST-01-BASIC/test.sh
test/units/testsuite-01.sh

index d0e714ac30f0e42d7a5a3073b93136fd0619e88a..c729e95f1dde606f5960af56a5b236d1a9e80321 100755 (executable)
@@ -23,4 +23,31 @@ test_append_files() {
     cp -v "$TEST_UNITS_DIR"/{testsuite-01,end}.service "$TEST_UNITS_DIR/testsuite.target" "$dst"
 }
 
+# Setup a one shot service in initrd that creates a dummy bind mount under /run
+# to check if the mount persists though the initrd transition. The "check" part
+# is in the respective testsuite-01.sh script.
+#
+# See: https://github.com/systemd/systemd/issues/28452
+run_qemu_hook() {
+    local extra="$WORKDIR/initrd.extra"
+
+    mkdir -m 755 "$extra"
+    mkdir -m 755 "$extra/etc" "$extra/etc/systemd" "$extra/etc/systemd/system" "$extra/etc/systemd/system/initrd.target.wants"
+
+    cat >"$extra/etc/systemd/system/initrd-run-mount.service" <<EOF
+[Unit]
+Description=Create a mount in /run that should survive the transition from initrd
+
+[Service]
+Type=oneshot
+RemainAfterExit=yes
+ExecStart=sh -xec "mkdir /run/initrd-mount-source /run/initrd-mount-target; mount -v --bind /run/initrd-mount-source /run/initrd-mount-target"
+EOF
+    ln -svrf "$extra/etc/systemd/system/initrd-run-mount.service" "$extra/etc/systemd/system/initrd.target.wants/initrd-run-mount.service"
+
+    (cd "$extra" && find . | cpio -o -H newc -R root:root > "$extra.cpio")
+
+    INITRD_EXTRA="$extra.cpio"
+}
+
 do_test "$@"
index 780f37ee128116028248e1c7be3d6f00aa018772..a1193ce6fbf4e06e44a8e604c4baf868723a650e 100755 (executable)
@@ -19,6 +19,11 @@ if systemd-detect-virt -q --container; then
     test ! -e /run/systemd/container
     cp -afv /tmp/container /run/systemd/container
 else
+    # We should've created a mount under /run in initrd (see the other half of the test)
+    # that should've survived the transition from initrd to the real system
+    test -d /run/initrd-mount-target
+    mountpoint /run/initrd-mount-target
+
     # We bring the loopback netdev up only during a full setup, so it should
     # not get brought back up during reexec if we disable it beforehand
     [[ "$(ip -o link show lo)" =~ LOOPBACK,UP ]]