Page 1 of 1

Initrd Explanation and Setup

Posted: Mon Mar 20, 2023 8:07 pm
by FunnyGuy9796
I am curious what the initrd is and what it is specifically used for. I have searched the internet but could not really find anything related to the initrd in terms of operating system development. Basically, what is the purpose of it and how would it be set up? I know that the layout of an initrd is different for everyone because everyone's projects are different. However, I am wondering what a "template" initrd would look like. Thanks in advance!

Re: Initrd Explanation and Setup

Posted: Mon Mar 20, 2023 9:20 pm
by sounds
Here are a few quick resources.

https://developer.ibm.com/articles/l-initrd/

https://docs.kernel.org/admin-guide/initrd.html

https://en.wikipedia.org/wiki/Initial_ramdisk

That answers the question "how would it be set up?"

For the question "what is the purpose of it?" maybe you don't need more of an explanation, but I'll take a stab at it anyway -

Linux used to not need an initial ramdisk. (Technically you can still boot without one.) So it's interesting to think about what happens immediately after the kernel is done and has handed off control to the first process, typically named "init" but really it's whatever the kernel has been given.

Side note: if the kernel doesn't have an initial ramdisk, it'll load "/sbin/init" from the root device.

That is why an initial ramdisk came into being. If the root device is a USB flash drive, it may not have shown up yet. USB flash drives can take a looong time to become ready. There is the "rootwait" parameter which just has the kernel hang silently forever for the root to be ready.

The initial ramdisk wasn't common at first, but PXE boot, bootable USB drives, iSCSI and SAN were some places where an initial ramdisk were very much needed.

The initial ramdisk means that instead of specifying a root device (/dev/sda or something) the kernel can hand off control to code which can do whatever you want in terms of finding the root drive, or mounting a bunch of things before running /sbin/init, or whatever you need.

Typically the initial ramdisk will load kernel modules needed to get to a working system. As linux distros started including more and more modules, they adopted the initial ramdisk and it became commonly used.

Re: Initrd Explanation and Setup

Posted: Mon Mar 20, 2023 9:50 pm
by FunnyGuy9796
Thank you so much for the reply! This is exactly what I was looking for!

Re: Initrd Explanation and Setup

Posted: Tue Mar 21, 2023 6:07 pm
by BigBuda
sounds wrote:Linux used to not need an initial ramdisk. (Technically you can still boot without one.) So it's interesting to think about what happens immediately after the kernel is done and has handed off control to the first process, typically named "init" but really it's whatever the kernel has been given.
I have the masochistic tendency to customize the kernel in every Linux installation I do on my own computers so that I don't need neither Grub (by getting the UEFI to directly boot the kernel, but I still add a Grub entry to the UEFI for emergency purposes) nor an initrd, by recompiling the kernel with all the specific modules for my system. It does shave a few seconds off boot time.

Re: Initrd Explanation and Setup

Posted: Sun Mar 26, 2023 10:04 am
by bellezzasolo
BigBuda wrote:
sounds wrote:Linux used to not need an initial ramdisk. (Technically you can still boot without one.) So it's interesting to think about what happens immediately after the kernel is done and has handed off control to the first process, typically named "init" but really it's whatever the kernel has been given.
I have the masochistic tendency to customize the kernel in every Linux installation I do on my own computers so that I don't need neither Grub (by getting the UEFI to directly boot the kernel, but I still add a Grub entry to the UEFI for emergency purposes) nor an initrd, by recompiling the kernel with all the specific modules for my system. It does shave a few seconds off boot time.
The UEFI loader for my OS stores core system modules on the EFI system partition. Some key modules are hardcoded, and an INI file states what drivers to load from the filesystem. Primitive, but functional, it avoids the need for an initrd.