Skip to contentSkip to conversation

initramfs-framework: remove hard dependency with busybox

PATCH Superseded Christos Gavros 4 participants 6 messages Mar 28, 2025 – Apr 11, 2025 1 message not in the archive

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/1 initramfs-framework: remove hard dependency with busybox

In 'finish'script the Switch_root command with option -c is busybox specific. When package-core-base-utils is selected the boot is breaking. Remove -c option to make it compatible with both providers
Fixes [YOCTO #15716]

CC Yoann Congal <[email protected]>
CC Randy MacLeod <[email protected]>
CC Ross Burton <[email protected]>
---
 meta/recipes-core/initrdscripts/initramfs-framework/finish | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
meta/recipes-core/initrdscripts/initramfs-framework/finish +1 -1
index ac0de9f996..716c2f44af 100755
@@ -41,7 +41,7 @@ finish_run() {
 		mount --move /sys $ROOTFS_DIR/sys
 
 		cd $ROOTFS_DIR
-		exec switch_root -c /dev/console $ROOTFS_DIR ${bootparam_init:-/sbin/init}
+		exec switch_root $ROOTFS_DIR ${bootparam_init:-/sbin/init}
 	else
 		debug "No rootfs has been set"
 	fi
Signature · 1 line
2.34.1
#2 lore raw

Hi Christos

Since the -c has been around for a very long time, I assume that there are many users who use it with busybox. Using it with core-utils will probably remain the special use case.
The proposed fix raises the question of why the -c was introduced at some point. If your fix also works for busybox, was the -c always redundant? Or has something changed in the meantime?

Please also address the busybox users' point of view in the commit message and summarize how this was tested with busybox in particular.

Thank you.
Adrian

Quoted 44 lines · Christos Gavros via lists.openembedded.org

In 'finish'script the Switch_root command with option -c is busybox specific.
When package-core-base-utils is selected the boot is breaking. Remove -c option to make it compatible with both providers Fixes [YOCTO #15716]

CC Yoann Congal <[email protected]>
CC Randy MacLeod <[email protected]>
CC Ross Burton <[email protected]>

---
 meta/recipes-core/initrdscripts/initramfs-framework/finish | 2 +-

 1 file changed, 1 insertion(+), 1 deletion(-)
(quoted diff) +0 -0

framework/finish b/meta/recipes-core/initrdscripts/initramfs- framework/finish
index ac0de9f996..716c2f44af 100755

meta/recipes-core/initrdscripts/initramfs-framework/finish +0 -0
@@ -41,7 +41,7 @@ finish_run() {

  mount --move /sys $ROOTFS_DIR/sys

  cd $ROOTFS_DIR

meta/recipes-core/initrdscripts/initramfs-framework/finish +0 -1
-		exec switch_root -c /dev/console $ROOTFS_DIR

${bootparam_init:-/sbin/init}

meta/recipes-core/initrdscripts/initramfs-framework/finish +1 -0
+		exec switch_root $ROOTFS_DIR ${bootparam_init:-

/sbin/init}
  else
  debug "No rootfs has been set"
  fi

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#213861):
https://lists.openembedded.org/g/openembedded-core/message/213861
Mute This Topic: https://lists.openembedded.org/mt/111959232/4454582
Group Owner: [email protected] Unsubscribe:
https://lists.openembedded.org/g/openembedded-core/unsub [
[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#3 lore raw

hi Adrian

thank you for the comment. I had a look in commits log and it looks that '-c' was there since the beginning in 2008/09/10 in script 'init-live.sh' and then moved in 'finish.sh' in 2011/12/08. I reproduced the issue by using qemu and I described how I did it in detail in bug # 15716.
After I applied the change I tested both busybox and packagegroup-core-base-utils. The boot was successful in both cases.
Also '-c' is an option in busybox: https://www.busybox.net/downloads/BusyBox.html

I will wait for more comments and then I will extend the commit message and send a v2.

Br
Christos

#4 lore raw
Quoted 8 lines · Christos Gavros via lists.openembedded.org

hi Adrian

thank you for the comment. I had a look in commits log and it looks that '-c' was there since the beginning in 2008/09/10 in script 'init-live.sh' and then moved in 'finish.sh' in 2011/12/08. I reproduced the issue by using qemu and I described how I did it in detail in bug #15716.
After I applied the change I tested both busybox and packagegroup-core-base-utils. The boot was successful in both cases.
Also '-c' is an option in busybox: https://www.busybox.net/downloads/BusyBox.html

-c option is to redirect the console after switching root. Some devices it did not work properly because util-linux version moved the pseudo filesystems like /dev automatically
but busybox version did not, maybe things have changed but I would suggest that this operation is now happening with both switch_root versions with you script manually doing so.

Quoted 14 lines

I will wait for more comments and then I will extend the commit message and send a v2.

Br
Christos

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#213885): https://lists.openembedded.org/g/openembedded-core/message/213885
Mute This Topic: https://lists.openembedded.org/mt/111959232/1997914
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#5 lore raw
Quoted 17 lines · Khem Raj via lists.openembedded.org
Quoted 13 lines · Christos Gavros via lists.openembedded.org

hi Adrian

thank you for the comment. I had a look in commits log and it looks that '-c' was there since the beginning in 2008/09/10 in script 'init-live.sh' and then moved in 'finish.sh' in 2011/12/08. I reproduced the issue by using qemu and I described how I did it in detail in bug #15716.
After I applied the change I tested both busybox and packagegroup- core-base-utils. The boot was successful in both cases. Also '-c' is an option in busybox:
https://www.busybox.net/downloads/BusyBox.html

Quoted 6 lines

-c option is to redirect the console after switching root. Some devices it did not work properly because util-linux version moved the pseudo filesystems like /dev automatically
but busybox version did not, maybe things have changed but I would suggest that this operation is now happening with both switch_root versions with you script manually doing so.

I tested this on a device with kernel 6.1+. It seams to work as expected also with a busybox based initramfs. Maybe you are right and this is more like a legacy thing which can (or even should?) be removed.

Additionally I looked into the code from busybox. The related lines are:

	if (console) {
		close(0);
		xopen(console, O_RDWR);
		xdup2(0, 1);
		xdup2(0, 2);
	}

https://github.com/brgl/busybox/blob/master/util-linux/switch_root.c#L143

At least on my device this would just close /dev/console and open it again. Not really useful.

I think the patch is beneficial for probably all kind of systems. Adrian

Quoted 22 lines
Quoted 10 lines

I will wait for more comments and then I will extend the commit message and send a v2.

Br
Christos

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group. View/Reply Online (#213886):
https://lists.openembedded.org/g/openembedded-core/message/213886
Mute This Topic: https://lists.openembedded.org/mt/111959232/4454582
Group Owner: [email protected] Unsubscribe:
https://lists.openembedded.org/g/openembedded-core/unsub [
[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

#6 lore raw
Quoted 40 lines · Adrian Freihofer
Quoted 17 lines · Khem Raj via lists.openembedded.org
Quoted 13 lines · Christos Gavros via lists.openembedded.org

hi Adrian

thank you for the comment. I had a look in commits log and it looks that '-c' was there since the beginning in 2008/09/10 in script 'init-live.sh' and then moved in 'finish.sh' in 2011/12/08. I reproduced the issue by using qemu and I described how I did it in detail in bug #15716.
After I applied the change I tested both busybox and packagegroup- core-base-utils. The boot was successful in both cases. Also '-c' is an option in busybox:
https://www.busybox.net/downloads/BusyBox.html

Quoted 6 lines

-c option is to redirect the console after switching root. Some devices it did not work properly because util-linux version moved the pseudo filesystems like /dev automatically
but busybox version did not, maybe things have changed but I would suggest that this operation is now happening with both switch_root versions with you script manually doing so.

I tested this on a device with kernel 6.1+. It seams to work as expected also with a busybox based initramfs. Maybe you are right and this is more like a legacy thing which can (or even should?) be removed.

Additionally I looked into the code from busybox. The related lines are:

	if (console) {
		close(0);
		xopen(console, O_RDWR);
		xdup2(0, 1);
		xdup2(0, 2);
	}
Quoted 6 lines

https://github.com/brgl/busybox/blob/master/util-linux/switch_root.c#L143

At least on my device this would just close /dev/console and open it again. Not really useful.

I think the patch is beneficial for probably all kind of systems.

Thanks, this analysis really helps.

I agree that this does appear to make sense. I guess it is in case the initramfs and the main system have different /dev/console entries but that is probably/hopefully very rare. It would only be the init process affected.

Cheers,

Richard