Why does the root file system boot into ramdisk?

I am studying the boot process on Linux. I came across this sentence: "RAM is several orders of magnitude higher than on a floppy disk, so the operating system works quickly from ramdisk"

In any case, the kernel will load the root file system into RAM to execute it. So my question is, why do we need ramdisk to load the root file system if the kernel loads the root file system in RAM?

+4
source share
2 answers

The documentation for SUSE Linux gives a good explanation of why Linux boots from RAMDisk:

Once the Linux kernel has been booted and the root file system (/) programs can be started and additional kernel modules can be integrated to provide additional functions. To install the system root file, certain conditions must be met. The kernel needs the appropriate drivers to access the device on which the root file system is located (especially SCSI drivers). The kernel should also contain the code necessary to read the system file (ext2, reiserfs, romfs, etc.). It is also possible that the root file system is already encrypted. In this case, a password is required to mount the file system.

For the SCSI driver problem, the number of different solutions is possible. The kernel may contain all imaginary drivers, but this may be a problem, because different drivers may conflict with each other. Also, the core will become very large because of this. Another possibility is to provide different cores, each one containing only one or more SCSI drivers. This method has a problem that a large number of different cores are needed, then the problem is increased in different ways optimized cores (Athlon optimization, SMP). The idea of ​​loading the SCSI driver as a module leads to a common problem solved by the concept of the initial ramdisk: starting user programs even before the root file system is installed.

This prevents a potential chicken or egg situation where the root file system cannot be booted up until there is access to the device on which it is located, but this device cannot be accessed before the root file system is booted:

The initial ramdisk (also called initdisk or initrd) exactly solves the problems described above. The Linux kernel provides the ability to have a small file system loaded onto a RAM disk and run programs there before actually installing the root file system. The initrd is loaded by the bootloader (GRUB, LILO, etc.) ..). To download data from bootable media, bootloaders only need a BIOS. If the bootloader can load the kernel, it can also load the initial ramdisk. Special drivers are not required.

Of course, RAMDisk is not absolutely necessary for the boot process. For example, you can compile a kernel containing all the necessary hardware drivers and modules to load at startup. But, apparently, this is too much work for most people, and RAMDisk was a simpler and more scalable solution.

+8
source

The reason most Linux distributions use ramfs (initramfs) at boot is because its contents can be included in the kernel file or provided by the bootloader. Therefore, they are available immediately at boot, without having to load their kernel from somewhere.

This allows the kernel to run user space programs, for example, configure devices, load modules, configure this excellent RAID array containing all file systems, or even ask the user for a password for their encrypted root file system.

When this configuration is complete, the first script, which is called only exec () s / sbin / init from the root file system (now configured and available).

I have seen quite a few systems in which drivers for disk controllers and rootfs are loaded through modules in initramfs, and are not included in the kernel image.

You do not need to strictly download initramfs - if your kernel image contains all the drivers needed to access the root files, and you do not need any special configuration or user input (for example, RAID arrays or encrypted file systems) to install it. Often you can directly run / sbin / init from 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, built-in and such) can use ramfs as the root file system when the actual root file system is on media that can be deleted or not writable (CD, Flash MTD, etc. ) ,.

+5
source

All Articles