我有自定义的initramfs,应该启动busybox。cpio存档包含带有busybox
和init
的目录D2
。
busybox
是静态链接的二进制文件:
bin/busybox: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), statically linked, for GNU/Linux 3.2.0, stripped
init
是具有以下代码的shell脚本:
#!/bin/busybox sh
export PATH=/bin
/bin/busybox --install -s /bin
sh
我使用以下命令制作图像:
find | cpio -ovHnewc > ../initrd.img
当我运行它时,我会感到内核恐慌:
# 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)
initramfs图像有什么问题?对于空initramfs,我得到了相同的错误。我发行版的initramfs正在工作。
发布于 2019-07-12 06:36:02
我认为您的init脚本对于引导来说太小了。内核与/proc和/sys一起工作,因此它应该包括:
mount -t proc none /proc
mount -t sysfs none /sys
发布于 2019-07-13 00:24:50
Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)
您收到此消息是因为它找不到init脚本。(如果没有init,它会尝试继续,然后由于缺乏rootfs而失败)。
-append 'debug console=ttyS0 init=/bin/init'
应该是/init
,而不是/bin/init
。或者,您可以根据rdinit=
参数根据管理指南/内核参数指定initramfs init。
测试initramfs是否已加载的一种方法是传递rdinit=/bin/busybox
,然后它应该随消息一起死掉:
CPU: 0 PID: 1 Comm: busybox ...
[... lots of stuff ...]
Attempted to kill init!
只有在最初存在init进程的情况下,您才会得到Attempted to kill init!
消息,因此您知道它已经加载并执行了一定程度的成功。否则,如果init根本不存在,它将返回到当前已经收到的消息。
此外,如果不想处理initrd本身中的模块加载,内核本身必须支持initramfs (CONFIG_BLK_DEV_INITRD=y
)以及可执行脚本(CONFIG_BINFMT_SCRIPT=y
)加上内置驱动程序,而不是模块。所以内核配置在这里也很重要。
我不知道你是不是已经从那个页面来了,但是Gentoo Wiki有自定义Initramfs指南。这还展示了如何获得基本的/dev
/proc
/sys
环境。
https://unix.stackexchange.com/questions/529837
复制