为什么将根文件系统加载到ramdisk中? [英] Why is the root filesystem is loaded into a ramdisk?

查看:493
本文介绍了为什么将根文件系统加载到ramdisk中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究Linux中的启动过程.我碰到了这样一句话:"RAM比软盘快几个数量级,因此从ramdisk可以快速进行系统操作"

I am studying the boot process in Linux. I came across this sentence "RAM is several orders of magnitude faster than a floppy disk, so system operation is fast from a ramdisk"

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

The kernel will anyway load the root filesystem in RAM for executing it. So my question why do we need a ramdisk for loading the the root filesystem, if the kernel loads the root file system into RAM ?

推荐答案

The documentation for SUSE Linux provides a good explanation of why Linux is booted with a RAMDisk:

Linux内核发布后, 引导和根文件系统(/) 安装后,程序可以运行并 其他内核模块可以是 集成以提供额外的 功能. 要挂载根文件 系统,必须满足某些条件 遇见.内核需要 相应的驱动程序来访问 根文件系统所在的设备 位于(尤其是SCSI 驱动程序). 内核还必须包含 读取文件所需的代码 系统(ext2,reiserfs,romfs等). 也可以想到,根 文件系统已被加密.在 在这种情况下,需要输入密码 挂载文件系统.

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.

对于SCSI驱动程序的问题, 许多不同的解决方案是 可能的.内核可以包含所有 可以想象的驱动程序,但这可能是 一个问题,因为不同的驱动程序 可能会相互冲突.还, 内核会变得很大 因为这.另一种可能性 是提供不同的内核,每个内核 一个仅包含一个或几个SCSI 司机.这种方法有问题 大量不同 内核是必需的,那么一个问题 通过不同的优化而增加 内核(Athlon优化,SMP). 将SCSI驱动程序加载为 模块导致一般问题 通过最初的概念解决 ramdisk:运行用户空间程序 甚至在根文件系统不存在之前 已安装.

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.

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

This prevents a potential chicken-or-egg situation where the root file system cannot be loaded until the device on which it is located can be accessed, but that device can't be accessed until the root file system has been loaded:

初始虚拟磁盘(也称为initdisk或initrd)精确地解决了上述问题. Linux内核提供了一个选项,可以将一个小的文件系统加载到RAM磁盘上,然后在实际的根文件系统安装之前在其中运行程序. initrd的加载由引导加载程序(GRUB,LILO等)处理. ).引导加载程序仅需要BIOS例程即可从引导介质加载数据. 如果引导加载程序能够加载内核,则它也可以加载初始虚拟磁盘.不需要特殊的驱动程序.

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被证明是一个更简单,可扩展性更高的解决方案.

Of course, a RAMDisk is not strictly necessary for the boot process to take place. For example, you could compile a kernel that contained all necessary hardware drivers and modules to be loaded at startup. But apparently this is too much work for most people, and the RAMDisk proved to be a simpler, more scalable solution.

这篇关于为什么将根文件系统加载到ramdisk中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆