<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>15716</bug_id>
          <alias>initramfs</alias>
    
    <alias>kernelpanic</alias>
    
    <alias>switch_root</alias>
          <creation_ts>2025-01-14 10:13:24 +0000</creation_ts>
          <short_desc>initrdscripts ignores virtual runtime &quot;base-utils&quot;, hard dependency on busybox</short_desc>
          <delta_ts>2025-04-13 16:59:38 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>7</classification_id>
          <classification>Build System, Metadata &amp; Runtime</classification>
          <product>OE-Core</product>
          <component>core</component>
          <version>5.99</version>
          <rep_platform>Other</rep_platform>
          <op_sys>x86_64</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium+</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>5.2 M3</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="jbk">jbk</reporter>
          <assigned_to name="Christos Gavros">gavrosc</assigned_to>
          <cc>gavrosc</cc>
    
    <cc>kexin.hao</cc>
    
    <cc>meta.mr.watcher</cc>
    
    <cc>meta.watcher</cc>
    
    <cc>randy.macleod</cc>
    
    <cc>yoann.congal</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>Don&apos;t know</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>100631</commentid>
    <comment_count>0</comment_count>
    <who name="jbk">jbk</who>
    <bug_when>2025-01-14 10:13:24 +0000</bug_when>
    <thetext>I recently had an issue with including an initramfs in my build, which I tracked down to the following interaction between the &quot;finish&quot; initrdscript and the virtual runtime for &quot;base-utils&quot; used in the initramfs images of oe-core.

The issue:
The initrdscript &quot;finish&quot; of the initramfs-framework is not provider-/runtime-agnostic. It requires busybox as virtual runtime for &quot;base-utils&quot;. Changing the base-utils to &quot;packagegroup-core-base-utils&quot; breaks the aforementioned &quot;finish&quot; script, leading to a kernel panic as the initramfs cannot transition to the final userspace / final rootfs.

The cause:
Reason is line 44, executing the switch_root command. switch_root is either provided by busybox or by util-linux, while the latter is shipped with packagegroup-core-base-utils. (Or maybe even a custom/another implementation in rare cases).
However: The invokation as in line 44 of the &quot;finish&quot; script needs the &quot;-c&quot; option , which is busybox specific and not supported by the util-linux implementation.
See switch_root as implemented by util-linux: https://man.archlinux.org/man/core/util-linux/switch_root.8.en 
And as implemented by busybox: https://www.busybox.net/downloads/BusyBox.html

Hence, when not using busybox as base-utils provider, inlcuding a initramfs based on the initrdscripts shipped with oe-core, it fails to transition to the final userspace, leading to a kernel panic.

Meaning:
1. Neither core-image-initramfs-boot nor core-image-minimal-initramfs consider this behavior. Both include the base-utils as specified in the virtual runtime (${VIRTUAL-RUNTIME_base-utils}). As soon as you change the virtual runtime in your build, those images break, leading to a kernel panic upon boot.
2. You have to either use &quot;busybox&quot; as hard-dependency in your own initramfs or ship your own initrdscripts

Version: I worked with the current master, however I see that the busybox specific switch_root was used ever since the &quot;finish&quot; script was included in oe-core. Same with the initramfs images shipped with oe-core, which seem to have used the virtual runtime for base-utils for quite a while, therefore breaking when not using busybox as base-utils.

Reproduce as follows:

- Chane your base-util provier:
PREFERRED_PROVIDER_virtual/base-utils = &quot;packagegroup-core-base-utils&quot;
VIRTUAL-RUNTIME_base-utils ?= &quot;packagegroup-core-base-utils&quot;

- Include one of the initramfs images shipped with oe-core in your build:
INITRAMFS_IMAGE = &quot;core-image-minimal-initramfs&quot;

- Build an image of your choice, including the initramfs
- Boot will lead to a kernel panic


Possible resolution:
- Either make the initrdscripts provider-agnostic by removing the &quot;-c&quot; option, or by only using the &quot;-c&quot; option when busybox is the switch_root implementation
- Or use busybox as dependency in the initramfs images shipped with oe-core, possibly mentioning in the docs that you cannot use another virtual provider for base-utils in conjunction with the initrdscripts as shipped by oe-core.

I hope I provided enough information to confirm and possibly resolve this bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>100664</commentid>
    <comment_count>1</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2025-01-16 15:42:57 +0000</bug_when>
    <thetext>Kevin may have an idea about how to handle this bug but I&apos;m just CCing him for now. Other people are welcome to submit a patch if they have one.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101379</commentid>
    <comment_count>2</comment_count>
    <who name="Christos Gavros">gavrosc</who>
    <bug_when>2025-03-15 12:54:35 +0000</bug_when>
    <thetext>hi jbk,

thank you for the description. It is very detailed. I tried to reproduce the issue.

I set the following variables in local.conf:
PREFERRED_PROVIDER_virtual/base-utils = &quot;packagegroup-core-base-utils&quot;
VIRTUAL-RUNTIME_base-utils ?= &quot;packagegroup-core-base-utils&quot;
INITRAMFS_IMAGE = &quot;core-image-minimal-initramfs&quot;
INITRAMFS_MAXSIZE = &quot;160000&quot;

execute: bitbake core-image-minimal

Then i tried to use qemu( runqemu qemux86_64 ) but i couldnt reproduce it.

- Are the above settings ok? if yes then probably qemu can not reproduce this behavior

- Did you use another hardware? 

Br
Christos</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101441</commentid>
    <comment_count>3</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2025-03-20 14:59:27 +0000</bug_when>
    <thetext>JBK - ping.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101453</commentid>
    <comment_count>4</comment_count>
    <who name="Christos Gavros">gavrosc</who>
    <bug_when>2025-03-21 11:49:02 +0000</bug_when>
    <thetext>hi

i reproduced it using qemu.

add lines in local.conf:
PREFERRED_PROVIDER_virtual/base-utils = &quot;packagegroup-core-base-utils&quot;
VIRTUAL-RUNTIME_base-utils ?= &quot;packagegroup-core-base-utils&quot;
INITRAMFS_IMAGE = &quot;core-image-minimal-initramfs&quot;
INITRAMFS_MAXSIZE = &quot;160000&quot;
INITRAMFS_IMAGE_BUNDLE = &quot;1&quot;
IMAGE_FSTYPES += &quot;cpio.gz&quot;

Run: bitbake core-image-minimal-initramfs
Run: qemu-system-x86_64 -kernel tmp/deploy/images/qemux86-64/bzImage \
  -initrd tmp/deploy/images/qemux86-64/core-image-minimal-initramfs-qemux86-64.cpio.gz \
  -nographic -append &quot;console=ttyS0 rdinit=/bin/sh&quot;

The result is kernel panic. 
If i set busybox as provider (PREFERRED_PROVIDER_virtual/base-utils and VIRTUAL-RUNTIME_base-utils) then boot is ok.

I will prepare a patch the upcoming week.
Randy and Richard thank you for the support yesterday :).

Br
Christos</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101533</commentid>
    <comment_count>5</comment_count>
    <who name="Christos Gavros">gavrosc</who>
    <bug_when>2025-03-28 18:07:10 +0000</bug_when>
    <thetext>hi

i think the right way to reproduce it is the following (and not in the previous comment i made):

add in local.conf:
PREFERRED_PROVIDER_virtual/base-utils = &quot;packagegroup-core-base-utils&quot;
VIRTUAL-RUNTIME_base-utils ?= &quot;packagegroup-core-base-utils&quot;
INITRAMFS_IMAGE = &quot;core-image-minimal-initramfs&quot;
INITRAMFS_MAXSIZE = &quot;160000&quot;

Run: bitbake core-image-minimal

Run qemu manually including initramfs:
 sudo qemu-system-x86_64 \
  -device virtio-net-pci,netdev=net0,mac=52:54:00:12:34:02 \
  -netdev tap,id=net0,ifname=tap0,script=no,downscript=no \
  -object rng-random,filename=/dev/urandom,id=rng0 \
  -device virtio-rng-pci,rng=rng0 \
  -drive file=/home/cg/poky/build/tmp/deploy/images/qemux86-64/core-image-minimal-qemux86-64.rootfs.ext4,if=virtio,format=raw \
  -usb \
  -device usb-tablet \
  -usb \
  -device usb-kbd \
  -cpu IvyBridge \
  -machine q35 \
  -smp 4 \
  -m 256 \
  -serial mon:vc \
  -serial null \
  -device virtio-vga \
  -display sdl,show-cursor=on \
  -kernel /home/cg/poky/build/tmp/deploy/images/qemux86-64/bzImage \
  -initrd /home/cg/poky/build/tmp/deploy/images/qemux86-64/core-image-minimal-initramfs-qemux86-64.cpio.gz \
  -append &apos;root=/dev/vda rw ip=192.168.7.2::192.168.7.1:255.255.255.0::eth0:off:8.8.8.8 net.ifnames=0 oprofile.timer=1 tsc=reliable no_timer_check rcupdate.rcu_expedited=1 swiotlb=0&apos;

The result is that boot stops with message:
&quot;Switch_root: invalid option — ‘c’
Try ‘switch_root –help’ for more information&quot;

If i set busybox as provider (PREFERRED_PROVIDER_virtual/base-utils and VIRTUAL-RUNTIME_base-utils) then boot is ok.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>101640</commentid>
    <comment_count>6</comment_count>
    <who name="Christos Gavros">gavrosc</who>
    <bug_when>2025-04-13 16:59:38 +0000</bug_when>
    <thetext>The patch is merged in the master:

https://git.openembedded.org/openembedded-core/commit/?id=0f745024fd40518f98390008b4f613d5641df416</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>