]> code.ossystems Code Review - openembedded-core.git/commitdiff
initramfs-framework: unmount automounts before switch_root
authorJustin Bronder <jsbronder@cold-front.org>
Thu, 10 Feb 2022 20:23:22 +0000 (15:23 -0500)
committerAnuj Mittal <anuj.mittal@intel.com>
Tue, 22 Feb 2022 03:29:53 +0000 (11:29 +0800)
If mounts are left lingering, then after we switch_root, attempts to
modify the block devices will result in an EBUSY with no way to unmount
them.  As we're about to switch_root anyways, there isn't much use to
keep anything mounted unless it has the new rootfs.

Signed-off-by: Justin Bronder <jsbronder@cold-front.org>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
(cherry picked from commit 4dc7af6d25597ea10ea43e76c7c3d7251462c0e5)
Signed-off-by: Anuj Mittal <anuj.mittal@intel.com>
meta/recipes-core/initrdscripts/initramfs-framework/finish

index 717383ebac830fc8ce37ee45d8c4f389557567a5..f08a9208675307d7ae0ed06aa1c1d9b892d1b5cd 100755 (executable)
@@ -12,6 +12,18 @@ finish_run() {
                        fatal "ERROR: There's no '/dev' on rootfs."
                fi
 
+               # Unmount anything that was automounted by busybox via mdev-mount.sh.
+               # We're about to switch_root, and leaving anything mounted will prevent
+               # the next rootfs from modifying the block device.  Ignore ROOT_DISK,
+               # if it was set by setup-live, because it'll be mounted over loopback
+               # to ROOTFS_DIR.
+               local dev
+               for dev in /run/media/*; do
+                       if mountpoint -q "${dev}" && [ "${dev##*/}" != "${ROOT_DISK}" ]; then
+                               umount -f "${dev}" || debug "Failed to unmount ${dev}"
+                       fi
+               done
+
                info "Switching root to '$ROOTFS_DIR'..."
 
                debug "Moving /dev, /proc and /sys onto rootfs..."