[meta-oe,kirkstone] initramfs-framework: move storage mounts to actual rootfs

Message ID 20220616124515.322289-1-muhammad_hamza@mentor.com
State New, archived
Headers show
Series [meta-oe,kirkstone] initramfs-framework: move storage mounts to actual rootfs | expand

Commit Message

Hamza, Muhammad June 16, 2022, 12:45 p.m. UTC
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>
---
 .../initrdscripts/initramfs-framework/finish             | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Steve Sakoman June 16, 2022, 4:58 p.m. UTC | #1
Hi Muhammad,

This issue is also present in the master branch, so you would need to
submit this first for master before I can take it for kirkstone.

Also, since this is a patch for oe-core you shouldn't include a
[meta-oe] tag in the subject line.  Some of us maintainers are easily
confused ;-)

Steve

On Thu, Jun 16, 2022 at 2:45 AM Muhammad Hamza
<Muhammad_Hamza@mentor.com> wrote:
>
> 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>
> ---
>  .../initrdscripts/initramfs-framework/finish             | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/meta/recipes-core/initrdscripts/initramfs-framework/finish b/meta/recipes-core/initrdscripts/initramfs-framework/finish
> index f08a920867..ac0de9f996 100755
> --- a/meta/recipes-core/initrdscripts/initramfs-framework/finish
> +++ b/meta/recipes-core/initrdscripts/initramfs-framework/finish
> @@ -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
> --
> 2.25.1
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#167006): https://lists.openembedded.org/g/openembedded-core/message/167006
> Mute This Topic: https://lists.openembedded.org/mt/91797957/3620601
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [steve@sakoman.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
Hamza, Muhammad June 17, 2022, 5:47 a.m. UTC | #2
Got it, thanks

-----Original Message-----
From: Steve Sakoman <steve@sakoman.com> 
Sent: Thursday, June 16, 2022 9:58 PM
To: Hamza, Muhammad <Muhammad_Hamza@mentor.com>
Cc: openembedded-core@lists.openembedded.org; Belal, Awais <Awais_Belal@mentor.com>
Subject: Re: [OE-core] [meta-oe][kirkstone][PATCH] initramfs-framework: move storage mounts to actual rootfs

Hi Muhammad,

This issue is also present in the master branch, so you would need to submit this first for master before I can take it for kirkstone.

Also, since this is a patch for oe-core you shouldn't include a [meta-oe] tag in the subject line.  Some of us maintainers are easily confused ;-)

Steve

On Thu, Jun 16, 2022 at 2:45 AM Muhammad Hamza <Muhammad_Hamza@mentor.com> wrote:
>
> 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>
> ---
>  .../initrdscripts/initramfs-framework/finish             | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git 
> a/meta/recipes-core/initrdscripts/initramfs-framework/finish 
> b/meta/recipes-core/initrdscripts/initramfs-framework/finish
> index f08a920867..ac0de9f996 100755
> --- a/meta/recipes-core/initrdscripts/initramfs-framework/finish
> +++ b/meta/recipes-core/initrdscripts/initramfs-framework/finish
> @@ -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
> --
> 2.25.1
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#167006): 
> https://lists.openembedded.org/g/openembedded-core/message/167006
> Mute This Topic: https://lists.openembedded.org/mt/91797957/3620601
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub 
> [steve@sakoman.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
Hamza, Muhammad June 17, 2022, 5:52 a.m. UTC | #3
Sent in patch for master.

Cheers,
Hamza

-----Original Message-----
From: openembedded-core@lists.openembedded.org <openembedded-core@lists.openembedded.org> On Behalf Of Hamza, Muhammad
Sent: Friday, June 17, 2022 10:48 AM
To: Steve Sakoman <steve@sakoman.com>
Cc: openembedded-core@lists.openembedded.org
Subject: Re: [OE-core] [meta-oe][kirkstone][PATCH] initramfs-framework: move storage mounts to actual rootfs

Got it, thanks

-----Original Message-----
From: Steve Sakoman <steve@sakoman.com>
Sent: Thursday, June 16, 2022 9:58 PM
To: Hamza, Muhammad <Muhammad_Hamza@mentor.com>
Cc: openembedded-core@lists.openembedded.org; Belal, Awais <Awais_Belal@mentor.com>
Subject: Re: [OE-core] [meta-oe][kirkstone][PATCH] initramfs-framework: move storage mounts to actual rootfs

Hi Muhammad,

This issue is also present in the master branch, so you would need to submit this first for master before I can take it for kirkstone.

Also, since this is a patch for oe-core you shouldn't include a [meta-oe] tag in the subject line.  Some of us maintainers are easily confused ;-)

Steve

On Thu, Jun 16, 2022 at 2:45 AM Muhammad Hamza <Muhammad_Hamza@mentor.com> wrote:
>
> 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>
> ---
>  .../initrdscripts/initramfs-framework/finish             | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git
> a/meta/recipes-core/initrdscripts/initramfs-framework/finish
> b/meta/recipes-core/initrdscripts/initramfs-framework/finish
> index f08a920867..ac0de9f996 100755
> --- a/meta/recipes-core/initrdscripts/initramfs-framework/finish
> +++ b/meta/recipes-core/initrdscripts/initramfs-framework/finish
> @@ -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
> --
> 2.25.1
>
>
> 
>

Patch

diff --git a/meta/recipes-core/initrdscripts/initramfs-framework/finish b/meta/recipes-core/initrdscripts/initramfs-framework/finish
index f08a920867..ac0de9f996 100755
--- a/meta/recipes-core/initrdscripts/initramfs-framework/finish
+++ b/meta/recipes-core/initrdscripts/initramfs-framework/finish
@@ -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