Skip to content

Commit 8256994

Browse files
mrc0mmandbluca
authored andcommitted
test: check if we correctly propagate /run mounts during switch root
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: systemd/systemd#28452
1 parent b12d41a commit 8256994

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

test/TEST-01-BASIC/test.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,31 @@ test_append_files() {
2323
cp -v "$TEST_UNITS_DIR"/{testsuite-01,end}.service "$TEST_UNITS_DIR/testsuite.target" "$dst"
2424
}
2525

26+
# Setup a one shot service in initrd that creates a dummy bind mount under /run
27+
# to check if the mount persists though the initrd transition. The "check" part
28+
# is in the respective testsuite-01.sh script.
29+
#
30+
# See: https://github.com/systemd/systemd/issues/28452
31+
run_qemu_hook() {
32+
local extra="$WORKDIR/initrd.extra"
33+
34+
mkdir -m 755 "$extra"
35+
mkdir -m 755 "$extra/etc" "$extra/etc/systemd" "$extra/etc/systemd/system" "$extra/etc/systemd/system/initrd.target.wants"
36+
37+
cat >"$extra/etc/systemd/system/initrd-run-mount.service" <<EOF
38+
[Unit]
39+
Description=Create a mount in /run that should survive the transition from initrd
40+
41+
[Service]
42+
Type=oneshot
43+
RemainAfterExit=yes
44+
ExecStart=sh -xec "mkdir /run/initrd-mount-source /run/initrd-mount-target; mount -v --bind /run/initrd-mount-source /run/initrd-mount-target"
45+
EOF
46+
ln -svrf "$extra/etc/systemd/system/initrd-run-mount.service" "$extra/etc/systemd/system/initrd.target.wants/initrd-run-mount.service"
47+
48+
(cd "$extra" && find . | cpio -o -H newc -R root:root > "$extra.cpio")
49+
50+
INITRD_EXTRA="$extra.cpio"
51+
}
52+
2653
do_test "$@"

test/units/testsuite-01.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ if systemd-detect-virt -q --container; then
1919
test ! -e /run/systemd/container
2020
cp -afv /tmp/container /run/systemd/container
2121
else
22+
# We should've created a mount under /run in initrd (see the other half of the test)
23+
# that should've survived the transition from initrd to the real system
24+
test -d /run/initrd-mount-target
25+
mountpoint /run/initrd-mount-target
26+
2227
# We bring the loopback netdev up only during a full setup, so it should
2328
# not get brought back up during reexec if we disable it beforehand
2429
[[ "$(ip -o link show lo)" =~ LOOPBACK,UP ]]

0 commit comments

Comments
 (0)