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

发布于 2024-10-02 20:53:39 字数 155 浏览 6 评论 0原文

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

内核无论如何都会将根文件系统加载到 RAM 中以执行它。所以我的问题是,如果内核将根文件系统加载到 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"

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 root filesystem, if the kernel loads the root file system into RAM ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

所有深爱都是秘密 2024-10-09 20:53:39

SUSE Linux 的文档很好地解释了原因Linux 使用 RAMDisk 启动:

一旦 Linux 内核完成
引导和根文件系统 (/)
安装后,程序可以运行并且
进一步的内核模块可以是
集成以提供额外的
功能。 挂载根文件
系统必须具备一定的条件
遇见了。内核需要
相应的驱动程序来访问
根文件系统所在的设备
位于
(尤其是 SCSI
驱动程序)。 内核还必须包含
读取文件所需的代码
系统(ext2、reiserfs、romfs 等)。
也可以想象,根
文件系统已经加密。在
在这种情况下,需要输入密码
挂载文件系统。

针对SCSI驱动的问题,
不同解的数量是
可能的。内核可以包含所有
可以想象的驱动程序,但这可能是
一个问题,因为不同的驱动程序
可能会互相冲突。还,
内核会变得非常大
因为这。另一种可能
就是提供不同的内核,每个
仅包含一个或几个 SCSI
司机。这个方法有问题
即大量不同的
需要内核,然后出现问题
通过不同的优化增加
内核(Athlon 优化、SMP)。
加载SCSI驱动程序的想法
一个模块导致了一般问题
通过初始概念解决
ramdisk:运行用户空间程序
甚至在根文件系统之前
已安装。

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

初始 ramdisk(也称为 initdisk 或 initrd)正好解决了上述问题。 Linux 内核提供了一个选项,可以在安装实际根文件系统之前将小文件系统加载到 RAM 磁盘并在那里运行程序。 initrd 的加载由引导加载程序(GRUB、LILO 等)处理.)。引导加载程序只需要 BIOS 例程即可从引导介质加载数据。 如果引导加载程序能够加载内核,它还可以加载初始 ramdisk。不需要特殊的驱动程序。

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

The documentation for SUSE Linux provides a good explanation of why Linux is booted with a 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.

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:

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.

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.

苍景流年 2024-10-09 20:53:39

大多数Linux发行版在启动时使用ramfs(initramfs)的原因是因为它的内容可以包含在内核文件中,或者由引导加载程序提供。因此,它们在启动时立即可用,而无需内核从某个地方加载它们。

这允许内核运行用户空间程序,例如配置设备、加载模块、设置包含所有文件系统的漂亮 RAID 阵列,甚至要求用户输入其加密根文件系统的密码。

完成此配置后,仅从(现已配置且可用)根文件系统调用 exec()s /sbin/init 的第一个脚本。

我见过很多系统,其中磁盘控制器和 rootfs 的驱动程序本身是通过 initramfs 中的模块加载的,而不是包含在内核映像中。

您并不严格需要 initramfs 来启动 - 如果您的内核映像包含访问 rootfs 所需的所有驱动程序,并且您不需要任何特殊配置或用户输入(例如 RAID 阵列或加密文件系统)来启动挂载它后,通常可以直接从rootfs启动/sbin/init。

另请参阅:

http://www.kernel.org/doc/ Documentation/filesystems/ramfs-rootfs-initramfs.txt

http://www.kernel.org/doc/Documentation/initrd.txt" kernel.org/doc/Documentation/initrd.txt

作为旁注,某些系统(救援磁盘、嵌入式等)可能会使用 ramfs 作为根文件系统,而实际的根文件系统位于可能是已删除或不可写(CD、闪存 MTD 等)。

The reason that most Linux distributions use a ramfs (initramfs) when booting, is because its contents can be included in the kernel file, or provided by the bootloader. They are therefore available immediately at boot, without the kernel having to load them from somewhere.

That allows the kernel to run userspace programs that e.g. configure devices, load modules, setup that nifty RAID array that contains all filesystems or even ask the user for the password to his encrypted root filesystem.

When this configuration is done, the first script that is called just exec()s /sbin/init from the (now configured and available) root filesystem.

I have seen quite a few systems where the drivers themselvess for the disk controllers and the rootfs are loaded via modules in an initramfs, rather than being included in the kernel image.

You do not strictly need an initramfs to boot - if your kernel image contains all drivers necessary to access the rootfs and you don't need any special configuration or user input (like RAID arrays or encrypted filesystems) to mount it, it is often possible to directly start /sbin/init from the rootfs.

See also:

http://www.kernel.org/doc/Documentation/filesystems/ramfs-rootfs-initramfs.txt

http://www.kernel.org/doc/Documentation/initrd.txt

As a side note, some systems (rescue disks, embedded and such) may use a ramfs as the root filesystem when the actual root filesystem is in a medium that may be removed or is not writable (CD, Flash MTDs etc).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文