Muhammad Hamza ac874996c9 initramfs-framework: move storage mounts to actual rootfs
Operations such as mkfs fail on devices that are not
switched to the actual rootfs before switch_root is
called. The kernel interprets these devices as still
being used even after unmounting and errors such as
below are seen when the target is fully booted

root@v1000:~# umount /dev/sdb1
root@v1000:~# mkfs.ext4 /dev/sdb1
mke2fs 1.43.8 (1-Jan-2018)
/dev/sdb1 contains a ext4 file system
        last mounted on Wed Nov 28 07:33:54 2018
Proceed anyway? (y,N) y
/dev/sdb1 is apparently in use by the system; will not make a filesystem here!

(From OE-Core rev: 0a3ebc5584384e4bf7d9c7ba4c827db587ef3bee)

Signed-off-by: Awais Belal <awais_belal@mentor.com>
Signed-off-by: Muhammad Hamza <muhammad_hamza@mentor.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
(cherry picked from commit ec53ffd01972d1be2d6a28de828b3f0b80dc1e61)
Signed-off-by: Steve Sakoman <steve@sakoman.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2022-07-08 08:27:16 +01:00

49 lines
1.4 KiB
Bash
Executable File

#!/bin/sh
# Copyright (C) 2011 O.S. Systems Software LTDA.
# Licensed on MIT
finish_enabled() {
return 0
}
finish_run() {
if [ -n "$ROOTFS_DIR" ]; then
if [ ! -d $ROOTFS_DIR/dev ]; then
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 basic mounts onto rootfs"
for dir in `awk '/\/dev.* \/run\/media/{print $2}' /proc/mounts`; do
# Parse any OCT or HEX encoded chars such as spaces
# in the mount points to actual ASCII chars
dir=`printf $dir`
mkdir -p "${ROOTFS_DIR}/media/${dir##*/}"
mount -n --move "$dir" "${ROOTFS_DIR}/media/${dir##*/}"
done
debug "Moving /dev, /proc and /sys onto rootfs..."
mount --move /dev $ROOTFS_DIR/dev
mount --move /proc $ROOTFS_DIR/proc
mount --move /sys $ROOTFS_DIR/sys
cd $ROOTFS_DIR
exec switch_root -c /dev/console $ROOTFS_DIR ${bootparam_init:-/sbin/init}
else
debug "No rootfs has been set"
fi
}