initfs: Adapt shutdown unmount to systemd v254
Adjust the awk match statement to unmount the ro and rw filesystems
possibly from multiple places.
Systemd version 254 changed the rules for mount propagation and what
is left mounted under run during systemd-shutdown before transfering
to the initramfs shutdown, and now the read-only and read-write mount
points we used to form the overlay are exposed in multiple places.
To avoid matching the optins, restrict the match criteria to field
two (the mountpoint) and anchor to the beginning or end of the field.
Since busybox awk doesn't handle some regular expressions according
to POSIX, just use . to match any single character instead of
non-standard and POSIX undefined escaping of / in the match criteria.
Fixes: openbmc/openbmc#3947
Change-Id: I04e83a7eb0fc2954b3108115a02cd0a73ce67a90
Signed-off-by: Milton Miller <mdmii@outlook.com>
diff --git a/meta-phosphor/recipes-phosphor/initrdscripts/files/obmc-shutdown.sh b/meta-phosphor/recipes-phosphor/initrdscripts/files/obmc-shutdown.sh
index 53d0e54..311bf31 100644
--- a/meta-phosphor/recipes-phosphor/initrdscripts/files/obmc-shutdown.sh
+++ b/meta-phosphor/recipes-phosphor/initrdscripts/files/obmc-shutdown.sh
@@ -19,12 +19,14 @@
rmdir /oldroot 2>/dev/null
# 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
+# Reverse sort order will ensure the overlay is unmounted before the loop mount
mkdir -p /mnt
mount --move /oldroot/run /mnt
+# Unmount paths with /oldroot /mnt under / and those ending with ro or rw
+# Use . to match any single character because busybox awk doesn't handle [/]
set -x
-awk '/oldroot|mnt/ { print $2 }' < /proc/mounts | sort -r | while IFS= read -r f
+awk '$2 ~ /^.oldroot|^.mnt|.r[ow]$/ { print $2 }' < /proc/mounts | sort -r | while IFS= read -r f
do
umount "$f"
done