Why do we need initramfs and initrd

bootinitinitramfsinitrdkernel

For example we have exotic file system on the disk and in order to load system we need mount root filesystem. But we cannot because there is no suitable driver exists in kernel image.

Let me explain how I understand kernel and initrd.

  1. When kernel is compiled we can select different modules to be included into kernel image (one single file)
  2. For example my root filesystem is reiserfs and I have configured kernel not to include module for this filesystem
  3. In this case kernel doesn't know how to mount such filesystem and it needs some help -> so load initramfs into the memory
  4. Find proper module in ram fs (lib/modules or etc)
  5. Load this module to the kernel
  6. Now kernel can mount reiserfs it mounts and than unloads (frees) memory occupied by ramfs

Am I right ?

But I don't understand why do we need initramfs in every distro ( I have seen it in every distro I have ever installed) if most of specific drivers are already present in kernel image (single file) furthermore we only need drivers for filesystems when kernel boots other drivers can be loaded from the filesystem after it is mounted.

So is it really essential part of any distro ?

P.S What is used more often initramfs or initrd and why ?

Best Answer

The strength comes from all the other things you can do besides loading modules. Basically it gives you a userspace and the possibility of doing all the things you can do from that.

An example: I use an initrd to have an encrypted root fs, setting that up requires code that there's no point having in kernel.

The "Rationale" section of the Wikipedia page on initrd has more examples.

initramfs is a newer (but still fairly old) implementation of the same idea, but the name initrd has survived often to refer to the image used as the early user space.

A totally different reason I just thought of: Embedded devices, they may not have enough memory to cope with a kernel that includes everything.

Related Question