I have custom initramfs that should start busybox shell. The cpio archive contains directory bin/ with busybox and init.

busybox is statically linked binary:

bin/busybox: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, for GNU/Linux 3.2.0, stripped

init is shell script with this code:

#!/bin/busybox sh
export PATH=/bin
/bin/busybox --install -s /bin

I make image using this command:

find | cpio -ovHnewc > ../initrd.img

I get kernel panic when I run it:

# qemu-system-x86_64 -m 512M -enable-kvm -kernel /boot/vmlinuz -initrd ../initrd.img -append 'debug console=ttyS0 init=/bin/init' -nographic
… (booting)
[    2.175321] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

What is wrong in the initramfs image? I get the same error for empty initramfs. initramfs from my distro is working.


I think perhaps your init script is too minimal for booting. Kernels work with /proc and /sys so it should include :

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

Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

You get this message because it could not find the init script. (Without init, it tries to proceed and then fails due to lack of rootfs).

-append 'debug console=ttyS0 init=/bin/init'

It should be /init, not /bin/init. Alternatively you can specify the initramfs init with the rdinit= parameter according to admin-guide/kernel-parameters.txt.

One way to test if the initramfs is loaded at all, is to pass rdinit=/bin/busybox, then it should die with the message:

CPU: 0 PID: 1 Comm: busybox ...
[... lots of stuff ...]
Attempted to kill init!

You only get the Attempted to kill init! message if there was an init process in the first place, so you know it was loaded and executed with some degree of success. Otherwise if init does not exist at all, it's back to the message you already got currently.

Also the kernel itself must support initramfs (CONFIG_BLK_DEV_INITRD=y), as well as executable scripts (CONFIG_BINFMT_SCRIPT=y) plus built-in drivers instead of modules, if you don't want to handle module loading inside the initrd itself. So the kernel configuration also matters a lot here.

I'm not sure if you're already coming from that page, but the Gentoo Wiki has a guide for Custom Initramfs. This also shows how to get the basic /dev /proc /sys environment.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.