]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
initramfs-framework: move storage mounts to actual rootfs
authorMuhammad Hamza <Muhammad_Hamza@mentor.com>
Fri, 17 Jun 2022 05:50:22 +0000 (10:50 +0500)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Tue, 21 Jun 2022 17:44:23 +0000 (18:44 +0100)
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!

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>
meta/recipes-core/initrdscripts/initramfs-framework/finish

index f08a9208675307d7ae0ed06aa1c1d9b892d1b5cd..ac0de9f996f83a1b7aae88ef5f61c7e6c43995d0 100755 (executable)
@@ -26,6 +26,15 @@ finish_run() {
 
                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