initfs: systemd v254 initrd interface workarounds
Bind mount /run/initramfs ourselves before mounting ro and rw
Unmount the tree under /run/initramfs (but not /run/initramfs)
Unmount /ro and /rw - were under /run/initramfs before the pivot
systemd added a soft-reboot feature in v254 and changed the shutdown
unmount semantics to preserving the mount upon umount error. In
addition for some unknown reason the automatic bind mount of
/run/initramfs is broken for some reason; at lest there is an invalid
argument when trying to manipulate the mount.
While leaving the underlying mounts is useful in that we don't loose
track that the storage is actually still in use by the kernel mount,
it turns out to be very difficult to find the run/initramfs/ro and rw
mount underneath the bind mounted run/initramfs pivoted to /. Instead
its much easier to perform the mouunt where we need it.
Signed-off-by: Milton Miller <mdmii@outlook.com>
diff --git a/meta-phosphor/recipes-phosphor/initrdscripts/files/obmc-init.sh b/meta-phosphor/recipes-phosphor/initrdscripts/files/obmc-init.sh
index 3df371f..389dcbc 100644
--- a/meta-phosphor/recipes-phosphor/initrdscripts/files/obmc-init.sh
+++ b/meta-phosphor/recipes-phosphor/initrdscripts/files/obmc-init.sh
@@ -19,6 +19,7 @@
mkdir -p $rodir $rwdir
+mount --bind run/initramfs /run/initramfs
cp -rp init shutdown update whitelist bin sbin usr lib etc var run/initramfs
# To start a interactive shell with job control at this point, run
diff --git a/meta-phosphor/recipes-phosphor/initrdscripts/files/obmc-shutdown.sh b/meta-phosphor/recipes-phosphor/initrdscripts/files/obmc-shutdown.sh
index 53d0e54..46a1d48 100644
--- a/meta-phosphor/recipes-phosphor/initrdscripts/files/obmc-shutdown.sh
+++ b/meta-phosphor/recipes-phosphor/initrdscripts/files/obmc-shutdown.sh
@@ -20,11 +20,14 @@
# Move /oldroot/run to /mnt in case it has the underlying rofs loop mounted.
# Ordered before /oldroot the overlay is unmounted before the loop mount
+# Unmount under initramfs but not the initramfs directory itself
+# Also unmount /ro and /rw if they are mounted (/run/initramfs/{ro,rw} before pivot)
mkdir -p /mnt
mount --move /oldroot/run /mnt
set -x
-awk '/oldroot|mnt/ { print $2 }' < /proc/mounts | sort -r | while IFS= read -r f
+awk '/oldroot|mnt|initramfs[^ ]/ { print $2 } / .r[ow] / { print $2 }' < /proc/mounts |
+ sort -r | while IFS= read -r f
do
umount "$f"
done