内置于自定义 Linux 内核中的 Initramfs 未运行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10437995/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Initramfs built into custom Linux kernel is not running
提问by dag
I am building a custom initramfs image that I am building as a CPIO archive into the Linux kernel (3.2).
我正在构建一个自定义 initramfs 映像,我将它作为 CPIO 存档构建到 Linux 内核 (3.2) 中。
The issue I am having is that no matter what I try, the kernel does not appear to even attempt to run from the initramfs.
我遇到的问题是,无论我尝试什么,内核似乎都没有尝试从 initramfs 运行。
The files I have in my CPIO archive:
我的 CPIO 档案中的文件:
cpio -it < initramfs.cpio
.
init
usr
usr/sbin
lib
lib/libcrypt.so.1
lib/libm.so
lib/libc.so.6
lib/libgcc_s.so
lib/libcrypt-2.12.2.so
lib/libgcc_s.so.1
lib/libm-2.12.2.so
lib/libc.so
lib/libc-2.12.2.so
lib/ld-linux.so.3
lib/ld-2.12.2.so
lib/libm.so.6
proc
sbin
mnt
mnt/root
root
etc
bin
bin/sh
bin/mknod
bin/mount
bin/busybox
sys
dev
4468 blocks
Init is very simple, and should just init devices and spawn a shell (for now):
Init 非常简单,应该只初始化设备并生成一个 shell(现在):
#!/bin/sh
mount -t devtmpfs none /dev
mount -t proc none /proc
mount -t sysfs none /sys
/bin/busybox --install -s
exec /bin/sh
In the kernel .config I have:
在内核 .config 我有:
CONFIG_INITRAMFS_SOURCE="../initramfs.cpio"
CONFIG_INITRAMFS_ROOT_UID=0
CONFIG_INITRAMFS_ROOT_GID=0
CONFIG_BLK_DEV_INITRD=y
CONFIG_BLK_DEV_RAM=y
CONFIG_BLK_DEV_RAM_COUNT=1
CONFIG_BLK_DEV_RAM_SIZE=32768
Kernel builds and the uImage size is larger depending on the initramfs size, so I know the image is being packed. However I get this output when I boot:
内核构建并且 uImage 大小取决于 initramfs 大小,所以我知道图像正在被打包。但是,当我启动时,我得到了这个输出:
console [netcon0] enabled
netconsole: network logging started
omap_rtc omap_rtc: setting system clock to 2000-01-02 00:48:38 UTC (946774118)
Warning: unable to open an initial console.
Freeing init memory: 1252K
mmc0: host does not support reading read-only switch. assuming write-enable.
mmc0: new high speed SDHC card at address e624
mmcblk0: mmc0:e624 SU08G 7.40 GiB
mmcblk0: p1
Kernel panic - not syncing: Attempted to kill init!
[<c000d518>] (unwind_backtrace+0x0/0xe0) from [<c0315cf8>] (panic+0x58/0x188)
[<c0315cf8>] (panic+0x58/0x188) from [<c0021520>] (do_exit+0x98/0x6c0)
[<c0021520>] (do_exit+0x98/0x6c0) from [<c0021e88>] (do_group_exit+0xb0/0xdc)
[<c0021e88>] (do_group_exit+0xb0/0xdc) from [<c0021ec4>] (sys_exit_group+0x10/0x18)
[<c0021ec4>] (sys_exit_group+0x10/0x18) from [<c00093a0>] (ret_fast_syscall+0x0/0x2c)
From that output, it does not look like it is even trying to extract the CPIO archive as initramfs. I expect to see this printk output, which is present in linux code init/initramfs.c:
从该输出中,看起来它甚至没有尝试将 CPIO 存档提取为 initramfs。我希望看到这个 printk 输出,它存在于 linux 代码 init/initramfs.c 中:
printk(KERN_INFO "Trying to unpack rootfs image as initramfs...\n");
I tried the filesystem once booting is complete (using chroot) and it works fine... so I believe the filesystem/libraries are sane.
我在启动完成后尝试了文件系统(使用 chroot)并且它工作正常......所以我相信文件系统/库是正常的。
Could anyone give me some pointers as to what I may have incorrect? Thanks in advance for any assistance!
任何人都可以给我一些关于我可能不正确的提示吗?在此先感谢您的帮助!
采纳答案by dag
I figured it out. I will post the answer in case anyone else has this issue.
我想到了。如果其他人有这个问题,我会发布答案。
I was missing a console device, this line was the clue:
我缺少一个控制台设备,这一行是线索:
Warning: unable to open an initial console.
After adding printk's so that I better understood the startup sequence, I realized that console device is opened prior to running the init script. Therefore, the console device must be in the initramfs filesystem directly, and we cannot rely on the devtmpfs mount to create that.
添加printk's以便我更好地理解启动顺序后,我意识到在运行init脚本之前打开了控制台设备。因此,控制台设备必须直接位于 initramfs 文件系统中,我们不能依赖 devtmpfs 挂载来创建它。
I think when the init script ran the shell was trying to open the console and failed, that's why the kernel was outputting:
我认为当 init 脚本运行时,shell 试图打开控制台并失败了,这就是内核输出的原因:
Kernel panic - not syncing: Attempted to kill init!
Executing the folowing commands from within the /dev directory of initramfs on the kernel build machine will generate the required device nodes:
从内核构建机器上 initramfs 的 /dev 目录中执行以下命令将生成所需的设备节点:
mknod -m 622 console c 5 1
mknod -m 622 tty0 c 4 0
After re-CPIO archiving the filesystem and rebuilding the kernel, I finally have a working filesystem in initramfs that the kernel will boot.
在重新 CPIO 归档文件系统并重建内核之后,我终于在 initramfs 中有一个内核将启动的工作文件系统。