LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 12-30-2010, 02:00 PM   #1
anidev
LQ Newbie
 
Registered: Nov 2010
Location: Virginia, USA
Distribution: Ubuntu
Posts: 9

Rep: Reputation: 0
Question Confused over how initial ramdisks work


Hello,

I know that an initial ramdisk contains drivers and modules required for accessing hardware before the root partition can be mounted. If the initial ramdisk is stored on the root partition, then how is it accessed, if the initial ramdisk is required to mount the root partition? Wouldn't statically compiling the drivers required for accessing the root partition defeat the purpose of the initial ramdisk?

Thanks!
 
Old 12-30-2010, 04:31 PM   #2
stress_junkie
Senior Member
 
Registered: Dec 2005
Location: Massachusetts, USA
Distribution: Ubuntu 10.04 and CentOS 5.5
Posts: 3,873

Rep: Reputation: 331Reputation: 331Reputation: 331Reputation: 331
The initrd is not ALWAYS required in order to access the root partition. Most initrds are not required at all. I think that distribution developers put them in there just to make it easier to create a system where an initrd IS required.

The only time that you really need an initrd is when the boot loader cannot directly load the Linux kernel. These situations include
1) using an encrypted root partition
2) using a software or fake RAID device for the root partition

That's it. If your system does not use either of the two mentioned characteristics then you don't really need an initrd. Your boot loader could just boot the Linux kernel image.

As to your second question,
Quote:
If the initial ramdisk is stored on the root partition, then how is it accessed, if the initial ramdisk is required to mount the root partition?
In these cases the initrd must reside on a partition that can be accessed by the boot loader software. That is why you can specify a different partition for the /boot directory. If your root partition is on a software RAID partition then your /boot partition must be on a non-RAIDed partition. If your root partition is encrypted then your /boot partition must reside on an unencrypted partition.

(The initrd generally resides in /boot.)

That's basically it.

Last edited by stress_junkie; 12-30-2010 at 04:36 PM.
 
Old 12-30-2010, 06:46 PM   #3
phil.d.g
Senior Member
 
Registered: Oct 2004
Posts: 1,192

Rep: Reputation: 101Reputation: 101
Quote:
Originally Posted by anidev View Post
If the initial ramdisk is stored on the root partition, then how is it accessed, if the initial ramdisk is required to mount the root partition? Wouldn't statically compiling the drivers required for accessing the root partition defeat the purpose of the initial ramdisk?

Thanks!
The initrd image can be read from the drive because it isn't done by the kernel, the boot loader does it. The kernel can load modules from the initrd environment because it has already been read into memory.

An initrd is optional. Most things you can compile directly into the kernel. If you compiled your own kernel and compiled modules for your hardware and file system direct then you can do away with your initrd.

I think most distros compile a small kernel and use initrds because generating an initrd with the required drivers is quite fast, recompiling the kernel to include the support directly is very slow. For most distros, you will need the initrd to boot your system using the default kernel.

On the other hand, I can't remember software RAID and the encryption stuff as modules only, meaning that you can probably compile them direct and do away with the initrd even with an encrypted file system or software RAID. However, it has been 4 or 5 years since I last compiled a kernel.

EDIT

I'm probably wrong on the encryption front, but only because the initrd will have shell scripts for prompting for the passphrase and unlocking the drive. The actual kernel modules may still be able to be compiled directly

Last edited by phil.d.g; 12-30-2010 at 06:49 PM.
 
Old 12-31-2010, 03:49 PM   #4
lumak
Member
 
Registered: Aug 2008
Location: Phoenix
Distribution: Arch
Posts: 799
Blog Entries: 32

Rep: Reputation: 109Reputation: 109
if the modules you need to boot the system are compiled into the kernel you do not need an initial ram disk. However, generic kernels with everything compiled as modules do not function this way. Generally you custom build a kernel to avoid an initial ram disk.

HOWEVER,
If you use encrypted partitions, you need an initial ramdisk that will allow you to unlock the partitions before it continues with the boot up.
 
Old 12-31-2010, 09:21 PM   #5
Kenny_Strawn
Senior Member
 
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Blog Entries: 62

Rep: Reputation: 55
I think it would be interesting to see what happens if you packed a GUI along with all its dependencies into the initrd and then hard-code it into the "init" script in its top level directory as such that it runs in kernel space without a problem.
 
Old 01-01-2011, 12:28 PM   #6
anidev
LQ Newbie
 
Registered: Nov 2010
Location: Virginia, USA
Distribution: Ubuntu
Posts: 9

Original Poster
Rep: Reputation: 0
Thanks, everyone, for the informative replies!

So now my understanding is that initrds are a way to quickly load drivers and modules for the kernel, faster than it would be if statically compiled. Is this more or less correct?
 
Old 01-01-2011, 01:24 PM   #7
crosstalk
Member
 
Registered: Jul 2010
Distribution: Gentoo, Debian, Mint, Xubuntu
Posts: 150

Rep: Reputation: 35
I don't think it's as much about load time as having a small kernel.

Without an initrd, all the drivers for all supported systems that are necessary to access the root filesystem must by build in (the kernel can't find modules until a filesystem is mounted with the modules on it). This will create an unnecessarily large kernel, using up excess RAM while the machine runs.

By using an initrd, after the initial boot, before much else is loaded, the initrd is discarded and the kernel is as small as possible.

An initrd is also necessary if you're dealing with a root filesystem that the kernel cannot mount on its own, such as an encrypted volume (you need a userspace to ask for the password) or a loopback-mounted root filesystem sitting on another filesystem (like Ubuntu's Wubi).

I hope this clears things up.
 
Old 01-01-2011, 03:27 PM   #8
Kenny_Strawn
Senior Member
 
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Blog Entries: 62

Rep: Reputation: 55
http://www.linuxquestions.org/questi...e-initrd-3471/
 
  


Reply

Tags
initrd, purpose


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
default number of ramdisks frozenQueue Linux - Kernel 1 09-21-2010 10:58 PM
Why must all ramdisks be of the same size? sonajiso Linux - General 1 11-18-2006 10:35 PM
How Can I Get My Internet To Work :confused: at6498 Debian 2 05-22-2005 03:22 PM
2.6 initrd ramdisks warhorse Linux - General 1 10-05-2004 02:14 PM
Linux 2.6.0, bootsplash, ramdisks Likosin Linux - General 7 12-25-2003 09:46 AM


All times are GMT -5. The time now is 06:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration