boot - 为什么根文件系统被加载到ramdisk中?

标签 boot ramdisk rootfs

我正在研究Linux的启动过程。我遇到过这样一句话“RAM 比软盘快几个数量级,因此 ramdisk 的系统运行速度很快”

无论如何,内核都会将根文件系统加载到 RAM 中来执行它。所以我的问题是,如果内核将根文件系统加载到 RAM 中,为什么我们需要 ramdisk 来加载根文件系统?

最佳答案

documentation for SUSE Linux 很好地解释了为什么 Linux 使用 RAMDisk 启动:

As soon as the Linux kernel has been booted and the root file system (/) mounted, programs can be run and further kernel modules can be integrated to provide additional functions. To mount the root file system, certain conditions must be met. The kernel needs the corresponding drivers to access the device on which the root file system is located (especially SCSI drivers). The kernel must also contain the code needed to read the file system (ext2, reiserfs, romfs, etc.). It is also conceivable that the root file system is already encrypted. In this case, a password is needed to mount the file system.

For the problem of SCSI drivers, a number of different solutions are possible. The kernel could contain all imaginable drivers, but this might be a problem because different drivers could conflict with each other. Also, the kernel would become very large because of this. Another possibility is to provide different kernels, each one containing just one or a few SCSI drivers. This method has the problem that a large number of different kernels are required, a problem then increased by the differently optimized kernels (Athlon optimization, SMP). The idea of loading the SCSI driver as a module leads to the general problem resolved by the concept of an initial ramdisk: running user space programs even before the root file system is mounted.

这可以防止潜在的先有鸡还是先有蛋的情况,即在可以访问根文件系统所在的设备之前无法加载根文件系统,但在加载根文件系统之前又无法访问该设备:

The initial ramdisk (also called initdisk or initrd) solves precisely the problems described above. The Linux kernel provides an option of having a small file system loaded to a RAM disk and running programs there before the actual root file system is mounted. The loading of initrd is handled by the boot loader (GRUB, LILO, etc.). Boot loaders only need BIOS routines to load data from the boot medium. If the boot loader is able to load the kernel, it can also load the initial ramdisk. Special drivers are not required.

当然,RAMDisk 并不是启动过程所必需的。例如,您可以编译一个内核,其中包含启动时加载的所有必需的硬件驱动程序和模块。但显然这对大多数人来说工作量太大,而 RAMDisk 被证明是一个更简单、更具可扩展性的解决方案。

关于boot - 为什么根文件系统被加载到ramdisk中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4192736/

相关文章:

c++ - 引导序列中的多线程应用程序 - C++/Debian

c# - 有没有办法引导用托管语言编写的代码?

linux - buildroot rootfs 可以使用 opkg 安装 angstrom 包吗?

linux - 在 buildroot 生成的图像中更新根文件系统

c - 在 Windows 8 上使用 C 读取引导扇区

linux-kernel - 引导加载程序如何将内核命令行传递给内核?

performance - 是否可以使用 Imdisk 获得持久性 RAM 磁盘?

java - 将 JDK 放在 ramdisk 上如何提高 IDE 性能?

android-studio - RamDisk 上的 Android Studio

linux - ARM Linux 引导的一些细节