Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Installing Gentoo
  • Search

Initramfs: Busybox sh makes Kernel panic

Having problems with the Gentoo Handbook? If you're still working your way through it, or just need some info before you start your install, this is the place. All other questions go elsewhere.
Post Reply
Advanced search
9 posts • Page 1 of 1
Author
Message
SvenRh
n00b
n00b
Posts: 6
Joined: Sat Feb 15, 2014 1:21 pm

Initramfs: Busybox sh makes Kernel panic

  • Quote

Post by SvenRh » Sat Jan 30, 2021 10:08 pm

Hello,

I'm trying to build a small, bloat-free system for network bridging purposes using just Busybox and wpa_supplicant in an initramfs. However, I'm greeted with a kernel panic in the very moment when Busybox should do business.

What have I done so far?

As the target machine conveniently is x86-64, I prepared a freshly downloaded Stage 3 in a chroot on my main workstation, especially setting FEATURES="buildpkg" and running emerge -e @system. Then I emerged gentoo-sources, busybox and wpa_supplicant; wpa_supplicant having all USE flags disabled and busybox having just the ipv6 and - most importantly - static USE flags set. I checked that busybox is indeed static:

Code: Select all

(chroot) r7 / # ldd /bin/busybox
        not a dynamic executable
(chroot) r7 / #
Then I started work on the gentoo-sources with make allnoconfig, gradually adding what I needed and what the target machine needed to actually boot that thing and show something on the screen. (Took me actually a few tries, have never gone the allnoconfig route before.)

I prepared the initramfs in /usr/src/initramfs/ by emerging a baselayout to it, followed by ROOT=/usr/src/initramfs emerge -atv --usepkgonly wpa_supplicant. Then I copied /bin/busybox to /usr/src/initramfs/bin/.

Lastly, I created a minimal /usr/src/initramfs/init file which (for first testing) looks like this:

Code: Select all

(chroot) r7 / # cat /usr/src/initramfs/init
#!/bin/busybox sh

echo "Boot complete. Have fun!"

exec sh
(chroot) r7 / #
I chmoded that file +x, made the kernel (built-in initramfs included) and copied it over to the target machine's EFI boot partition. Then I rebooted that machine and ...

Code: Select all

Run /init as init process
Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000000
CPU: 1 PID: 1 Comm: sh Not tainted 5.4.80-gentoo-r1 #17
Yeah, all I got was Kernel panics when Busybox should have taken over. Given that Busybox is static, I ruled it out as the bully, and fiddled about with the kernel and out of sheer desperation even tried the opposite approach, kernel-wise, make defconfig and disabling only obviously unneeded stuff (mostly a plethora of drivers for various network devices I have never owned). Different approach - no different result: Panic attacks whenever Busybox should do business.

I'm at a loss.

What's wrong here? Where have I missed something?
Top
NeddySeagoon
Administrator
Administrator
User avatar
Posts: 56082
Joined: Sat Jul 05, 2003 9:37 am
Location: 56N 3W

  • Quote

Post by NeddySeagoon » Sat Jan 30, 2021 10:22 pm

SvenRh,

Well,

Code: Select all

Attempted to kill init! 
means that the kernel loaded and fell off the end of the init process.

I suspect you need to mount /proc or you won't have stdin, stdout and stderr.
That is, busybox won't be able to talk to you.
/dev needs to be mounted too. You need at least /dev/null and /dev/console.

I don't think /sys is required but I'm not sure.
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Top
Goverp
Advocate
Advocate
User avatar
Posts: 2402
Joined: Wed Mar 07, 2007 6:41 pm

Re: Initramfs: Busybox sh makes Kernel panic

  • Quote

Post by Goverp » Sun Jan 31, 2021 11:21 am

SvenRh wrote:I'm trying to build a small, bloat-free system for network bridging purposes using just Busybox and wpa_supplicant in an initramfs. However, I'm greeted with a kernel panic in the very moment when Busybox should do business....
SvenRh, Interesting. I was thinking of doing something very similar, without the wifi, to make a stand-alone minimal bootable Busybox as a toolkit for my EFI partition. I know Intel provide an EFI Shell, but AFAIK it doesn't speak bash or anything well-known and hence needs learning afresh, whereas Busybox is pretty easy to use. Keep up your good work; I could then strip out the networking and have just what I wanted (qua probably a wider selection of file systems.)
Greybeard
Top
NeddySeagoon
Administrator
Administrator
User avatar
Posts: 56082
Joined: Sat Jul 05, 2003 9:37 am
Location: 56N 3W

  • Quote

Post by NeddySeagoon » Sun Jan 31, 2021 11:30 am

SvenRh,

Code: Select all

#cp /bin/busybox /mnt/gentoo
# chroot /mnt/gentoo/ /busybox sh
/ # ls
busybox
/ # ls /dev
ls: /dev: No such file or directory
/ # ls /proc
ls: /proc: No such file or directory
/ # ls /sys
ls: /sys: No such file or directory
/ # 
that much works
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Top
szatox
Advocate
Advocate
Posts: 3858
Joined: Tue Aug 27, 2013 12:35 pm

  • Quote

Post by szatox » Sun Jan 31, 2021 5:22 pm

(chroot) r7 / # cat /usr/src/initramfs/init
#!/bin/busybox sh

echo "Boot complete. Have fun!"

exec sh
(chroot) r7 / #
Make sure you have /dev/null and /dev/console nodes created in your initramfs.
AFAIR null is the only hard requirement, you can get all other nodes by mounting /dev (just mount /proc first and /dev second), but in the manual mode console will be needed too.
Top
SvenRh
n00b
n00b
Posts: 6
Joined: Sat Feb 15, 2014 1:21 pm

  • Quote

Post by SvenRh » Sun Jan 31, 2021 7:09 pm

NeddySeagoon wrote:I suspect you need to mount /proc or you won't have stdin, stdout and stderr.
That is, busybox won't be able to talk to you.
/dev needs to be mounted too. You need at least /dev/null and /dev/console.

I don't think /sys is required but I'm not sure.
szatox wrote:Make sure you have /dev/null and /dev/console nodes created in your initramfs.
AFAIR null is the only hard requirement, you can get all other nodes by mounting /dev (just mount /proc first and /dev second), but in the manual mode console will be needed too.
Alright, I added the respective mount commands to my /init:

Code: Select all

(chroot) r7 /usr/src/initramfs # cat init
#!/bin/busybox sh

mount -t proc none /proc
mount -t devtmpfs none /dev
mount -t sysfs none /sys

echo "Boot complete. Have fun!"

exec sh
(chroot) r7 /usr/src/initramfs #
I checked my kernel to have the required options set:

Code: Select all

(chroot) r7 /usr/src/linux # grep PROC_FS .config
CONFIG_SCSI_PROC_FS=y
CONFIG_PROC_FS=y
(chroot) r7 /usr/src/linux # grep DEVTMPFS .config
CONFIG_DEVTMPFS=y
CONFIG_DEVTMPFS_MOUNT=y
(chroot) r7 /usr/src/linux # grep SYSFS .config
# CONFIG_SYSFS_DEPRECATED is not set
CONFIG_SYSFS_SYSCALL=y
# CONFIG_DMI_SYSFS is not set
# CONFIG_FW_CFG_SYSFS is not set
# CONFIG_WATCHDOG_SYSFS is not set
CONFIG_EDAC_LEGACY_SYSFS=y
CONFIG_RTC_INTF_SYSFS=y
CONFIG_NVMEM_SYSFS=y
CONFIG_SYSFS=y
(chroot) r7 /usr/src/linux #
For reference here is my complete .config: https://pastebin.com/UCU3G8qp

I removed usr/initramfs_data.cpio from the kernel source tree and re-made the kernel, copied it to the taregt ESP an reboted. However, to no different result.

Here is a "screenshot" of the complete failure: https://imgur.com/a/daS4636
Top
NeddySeagoon
Administrator
Administrator
User avatar
Posts: 56082
Joined: Sat Jul 05, 2003 9:37 am
Location: 56N 3W

  • Quote

Post by NeddySeagoon » Sun Jan 31, 2021 9:20 pm

SvenRh,

Do those three mount points exist in the initrd?

Code: Select all

mount -t proc none /proc
mount -t devtmpfs none /dev
mount -t sysfs none /sys 
If not, the mounts will fail.
Regards,

NeddySeagoon

Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail.
Top
SvenRh
n00b
n00b
Posts: 6
Joined: Sat Feb 15, 2014 1:21 pm

  • Quote

Post by SvenRh » Sun Jan 31, 2021 11:44 pm

Damn, I should adhere to what I quote ...
szatox wrote:Make sure you have /dev/null and /dev/console nodes created in your initramfs.
AFAIR null is the only hard requirement, you can get all other nodes by mounting /dev (just mount /proc first and /dev second), but in the manual mode console will be needed too.
Then I would have come across something else missing from my initramfs ...
NeddySeagoon wrote:Do those three mount points exist in the initrd?
Nope, they didn't. I had considered them to be part of sys-apps/baselayout, but apparently they're not. So I mkdir-ed them and copied (--archive) /dev/{null,console} over. Removed initramfs_data.cpio, re-made the kernel, copied it to the target ESP, rebooted. And kaboom: It works! :D

Thank you very much for all your help!
Top
szatox
Advocate
Advocate
Posts: 3858
Joined: Tue Aug 27, 2013 12:35 pm

  • Quote

Post by szatox » Tue Feb 02, 2021 10:47 pm

had considered them to be part of sys-apps/baselayout, but apparently they're not
They are. You just have to enable "build" do-not-USE flag.

Anyway, gratz!
Top
Post Reply

9 posts • Page 1 of 1

Return to “Installing Gentoo”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic