如何从内核源代码制作最小的可引导 linux(仅使用终端)?

Kes*_*thi 6 linux kernel initrd busybox

我想制作一个非常小的 linux 操作系统,它只有一个终端界面和基本的命令/应用程序(busybox 是我选择的命令/应用程序)。我不想在我的操作系统上安装安装选项。我只是希望它完全从 RAM 启动并运行。我打算使用 ISO-Linux 作为引导加载程序。没有网络,没有虚拟化支持,没有不必要的驱动程序等。我希望它是非常非常基本的操作系统。我已经从 kernel.org 下载了最新的稳定内核 (v4.5) 源代码并准备好了构建环境。

我的另一个困惑是,默认情况下内核是否具有任何用户界面(shell、终端等),我可以在其中键入命令并查看输出?

SHW*_*SHW 9

从技术上讲,您可以实现这一点。但是,内核没有任何内置的用户界面。

您需要按照以下步骤操作:

1. Create a initramfs with static busybox and nothing else.
This initramfs will have few necessary directories: like proc, sys, tmp, bin, usr, etc

2. Write a "/init" script, whose main job will be:
   a. mount the procfs,tmpfs and sysfs.
   b. Call busybox's udev i.e. mdev
   c. Install the busybox command onto virtual system by executing busybox install -s
   d. Calling /bin/sh

3. Source the initramfs directory while compiling the kernel. You can do so by flag: CONFIG_INITRAMFS_SOURCE

4. Compile your kernel.

5. Boot off this kernel and you will get the shell prompt with minimal things.
Run Code Online (Sandbox Code Playgroud)

不过,我以非常正式的方式写了上面的笔记。您可以按照自己的意愿对其进行微调。

更新:

按照此链接获取一些指南。