是否可以在不创建 initrd 映像的情况下启动 Linux 内核?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6405083/
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
Is it possible to boot the Linux kernel without creating an initrd image?
提问by Neel
As I understand, initrd is a small image that is loadable in the RAM. It is used to boot a complete kernel with all the loadable modules. As part of the process, we need the vmlinuz kernel image which is a renamed version of bzImage.
据我了解,initrd 是一个可加载到 RAM 中的小图像。它用于引导包含所有可加载模块的完整内核。作为该过程的一部分,我们需要 vmlinuz 内核映像,它是 bzImage 的重命名版本。
Is it possible to boot the kernel without creating the initrd image?
是否可以在不创建 initrd 映像的情况下引导内核?
采纳答案by datenwolf
initrd/initramfs is optional and not a requirement. bzImage is the pure kernel image and can be booted directly by the bootloader. However it might be neccesary to execute some tasks (loading filesystem modules, drivers for disk access, mounting the root file system from some exchangeable media without fixed name/path, etc.) that would usually require access to a filesystem and userspace tools.
initrd/initramfs 是可选的,不是必需的。bzImage 是纯内核映像,可以由引导加载程序直接引导。然而,可能需要执行一些通常需要访问文件系统和用户空间工具的任务(加载文件系统模块、磁盘访问驱动程序、从一些没有固定名称/路径的可交换媒体安装根文件系统等)。
That's what initramfsis for: It is a CPIO archive that gets attached to the kernel image (the kernel image is the container for the initramfs not other way round) either in the kernel image itself, or by the bootloader at boot time.
这就是initramfs的用途:它是一个 CPIO 存档,它附加到内核映像(内核映像是 initramfs 的容器,而不是其他方式)在内核映像本身中,或者在引导时由引导加载程序附加。
That CPIO archive contains an initial rootfs with the modules required to setup all devices to access the proper root filesystem and some programs to identify those devices, load the modules, do some other startup tasks remount the proper root file system to / and start /sbin/init
该 CPIO 存档包含一个初始 rootfs,其中包含设置所有设备以访问正确的根文件系统所需的模块和一些程序来识别这些设备、加载模块、执行一些其他启动任务,将正确的根文件系统重新挂载到 / 并启动 /sbin /在里面
initrdis similar, with the main difference that it is an filesystem image, that may be and usually is compressed. The kernel must have support for the filesystem used built in and will mount this image as the initial /.
initrd类似,主要区别在于它是一个文件系统映像,它可能并且通常被压缩。内核必须支持内置使用的文件系统,并将此映像挂载为初始 /。
Since CPIO is simpler by several orders of magnitudes, initramfs is prefered over initrd, as this saves both the requirement for any filesystem modules being built in and also makes initramfs creation easier. Instead of having to create an ext2 image, loopdevice mount and populate it, it boils down to a simple archive creation, not unlike using tar.
由于 CPIO 简单了几个数量级,initramfs 比 initrd 更受欢迎,因为这既节省了对任何内置文件系统模块的要求,也使 initramfs 的创建更容易。它不必创建 ext2 映像、loopdevice 挂载和填充它,而是归结为一个简单的存档创建,与使用 tar 不同。
However if you compile your kernel with all required drivers and modules built into the kernel image, and your root file system device has a fixed name in the system you don't need a initramfs as the kernel can do things by itself then.
但是,如果您使用内核映像中内置的所有必需驱动程序和模块编译内核,并且您的根文件系统设备在系统中具有固定名称,则您不需要 initramfs,因为内核可以自己做事。
回答by Douglas Leeder
The initrd contain the modules required to understand the root filesystem, and thus be able to access the normal store of kernel modules.
initrd 包含理解根文件系统所需的模块,因此能够访问内核模块的正常存储。
If your kernel is compiled with all that code built-in, rather than as modules, then an initrd shouldn't be required.
如果您的内核是使用所有内置代码而不是作为模块编译的,则不需要 initrd。
回答by MarkR
Yes, you can boot a system without an initrd image.
是的,您可以在没有 initrd 映像的情况下启动系统。
initrd image is either a gzipped ramdisc image, or (more commonly nowadays) a gzipped .cpio image.
initrd 映像要么是一个 gzip 压缩的 ramdisc 映像,要么(现在更常见)一个 gzip 压缩的 .cpio 映像。
In the latter case, the .cpio is expanded into a filesystem called initramfs.
在后一种情况下,.cpio 被扩展为一个名为 initramfs 的文件系统。
If the .cpio image isn't present, the kernel uses a built-in image instead, which contains just a few special files (such as /dev/console, /dev/null and a few directories), but no binaries.
如果 .cpio 映像不存在,内核会使用内置映像代替,其中仅包含一些特殊文件(例如 /dev/console、/dev/null 和一些目录),但不包含二进制文件。
The kernel then uses some built-in logic and command-line options to try to find and mount is "real" root filesystem, which is mounted "over" the initramfs and therefore hides it.
然后内核使用一些内置的逻辑和命令行选项来尝试查找和挂载是“真正的”根文件系统,它是挂载在 initramfs 上的,因此将其隐藏。
This "legacy" boot system is mostly not used in modern distributions.
这种“传统”引导系统在现代发行版中大多不使用。