如果我从源代码构建 linux 内核,它是否默认包含 initramfs?

If I build linux kernel from source, does it contain initramfs inside by default?

我认为我必须在构建核心。但是如果我跳过这个过程而只构建内核,它是否包含一种默认的 initramfs?还是它有空的 initramfs? (网上很多例子都没有显示busybox程序..)

If I build linux kernel from source, does it contain initramfs inside by default?

是的,但它将是空的(默认情况下)。
Documentation/filesystems/ramfs-rootfs-initramfs.txt:

The 2.6 kernel build process always creates a gzipped cpio format initramfs
archive and links it into the resulting kernel binary.  By default, this
archive is empty (consuming 134 bytes on x86).

您可以使用内部或外部 cpio 存档填充 initramfs。
使用 CONFIG_INITRAMFS_SOURCE 指向一个 cpio 存档文件,它将被嵌入到内核映像中。
否则,可以使用旧的 initrd 机制在引导期间指定(外部)cpio 归档文件。
如果在启动时将 initrd/initramfs 传递给 arm64 内核,它必须完全驻留在 1 GB 对齐的物理内存中 window,最大 32 GB 的大小也完全覆盖内核映像。


cpio 存档需要包含一个 init 文件,以禁止进一步处理挂载根文件系统。如文件所示:

After extracting, the kernel checks to see if rootfs contains a file "init",
and if so it executes it as PID 1.  
If found, this init process is responsible for bringing the system the
rest of the way up, including locating and mounting the real root device (if
any).  
If rootfs does not contain an init program after the embedded cpio
archive is extracted into it, the kernel will fall through to the older code
to locate and mount a root partition, then exec some variant of /sbin/init
out of that.

可以构建 Busybox 以提供 init 文件。


附录

I had found CONFIG_INITRAMFS_SOURCE value in my old .config file (year 2013~2014) was set to just empty (set to " ").

一串单字space没有意义
您的意思是空字符串,如 "" 中的默认值吗? 默认值意味着不使用内核映像构建 initramfs 的存档。

Now I just now found CONFIG_RD_GZIP=y too in the file.

这只是启用 支持 以加载 gzip 编码的初始 ramdisk 或 cpio 缓冲区。它只是可以配置的几种可用压缩方法之一。还可能支持 bzip2、LZMA、XZ、LZO 和 LZ4。

显着的配置符号是 CONFIG_BLK_DEV_RAM,这将启用 RAM 磁盘支持。

At that time we put busybox120.gz file under arch/sparc/boot before doing linux 'make sImage'. so I guess when there is a .gz file under arch/sparc/boot, the kernel build system uses that .gz file as the initramfs.

不,简单地将文件存储在目录中不会导致包含在内核构建中。
由于未指定 initramfs 文件,因此最有可能使用该 busybox120.gz 文件的是 ramdisk。
档案通常以 .cpio.tar 文件扩展名命名。您的文件两者都没有,所以这可能意味着它不是档案。缺少存档扩展名可能意味着它是一个 image 文件,永远不会用于 ramfs,但可以用于 ramdisk(或 initrd)。
据我所知,initrd 的映像(或存档)由引导程序加载(参考:Using the initial RAM disk (initrd))而不是链接进来。

检查与该内核映像一起使用的内核命令行。
是否有指定 ramdisk 的参数,例如initrd=... and/or root=/dev/ram0?

请确保您没有混淆 initramfs 和 initrd。请参阅 Documentation/filesystems/ramfs-rootfs-initramfs.txtThe difference between initrd and initramfs?