如何编译一个"hello world" /init 进程?



我正在努力学习如何为Linux构建一个最小的initramfs。我设置了CONFIG_INITRAMFS_SOURCE="asd",创建了asd目录,里面有一个使用gcc -fpic -static main.c -o init编译的init文件。在内核日志中,我得到了以下错误:

Run /init as init process                                                                                  
Failed to execute /init (error -8)                                                                         

这是输入源代码:

int main() {
printf("Hello, world!n");
for(;;);
}

我做错了什么?

它与defconfig内核和CONFIG_INITRAMFS_SOURCE集一起工作。在目录中,我必须使节点dev/console

mkdir dev
sudo mknod --mode=0600 dev/console c 5 1

在qemu中运行-kernel linux*/arch/x86_64/boot/bzImage之后,调用init之后显示Hello, world!

相关内容

最新更新