OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 7:07 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Initrd Explanation and Setup
PostPosted: Mon Mar 20, 2023 8:07 pm 
Offline
Member
Member

Joined: Tue Sep 13, 2022 9:29 pm
Posts: 61
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!


Top
 Profile  
 
 Post subject: Re: Initrd Explanation and Setup
PostPosted: Mon Mar 20, 2023 9:20 pm 
Offline
Member
Member

Joined: Sat Feb 04, 2012 5:03 pm
Posts: 111
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.


Top
 Profile  
 
 Post subject: Re: Initrd Explanation and Setup
PostPosted: Mon Mar 20, 2023 9:50 pm 
Offline
Member
Member

Joined: Tue Sep 13, 2022 9:29 pm
Posts: 61
Thank you so much for the reply! This is exactly what I was looking for!


Top
 Profile  
 
 Post subject: Re: Initrd Explanation and Setup
PostPosted: Tue Mar 21, 2023 6:07 pm 
Offline
Member
Member
User avatar

Joined: Fri Sep 03, 2021 5:20 pm
Posts: 92
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.

_________________
Writing a bootloader in under 15 minutes: https://www.youtube.com/watch?v=0E0FKjvTA0M


Top
 Profile  
 
 Post subject: Re: Initrd Explanation and Setup
PostPosted: Sun Mar 26, 2023 10:04 am 
Offline
Member
Member
User avatar

Joined: Sun Feb 20, 2011 2:01 pm
Posts: 110
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.

_________________
Whoever said you can't do OS development on Windows?
https://github.com/ChaiSoft/ChaiOS


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 72 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group