# to initrd or not to initrd

## syadnom

the question is, should one use an initrd as a general rule or not?  benefits? disadvantages?

i see than initrd can allow a more modular kernel because even necessary boot modules can be in the initrd eliminating the need to leave these in-kernel, but i dont see why these things should not be in the kernel as they are need for boot and would likely not be unloaded at any time.

also, does an initrd usually carry ALL of the system modules or just some?  i why would you not just put the filesystem the modules are located on in-kernel?

----------

## umbra obscura

IMHO it does not make much sense to compile drivers,filesystems etc as modules if they are required to mount to root filesystem. They never get unloaded and there is no way to unload them at all. (this is the general case. in a special case there might be reasons to do this). This is my own opintion, partially it is a matter of taste, but others might teach me something different

Sometimes you need a initrd - if you have to do some setup before the root filesystem can be mounted. A completely encrypted system (well, the /boot partition has to be left unencrypted) would be such a thing. The initrdn would then ask for a password, setup the root filesystem and start the system - something what cannot be done otherwise

----------

## Colonel Paneek

Hello,

I have a problem with getting the linuxrc in my initrd to execute. (This is my first attempt at setting up an initrd). I want to make my usb flash ram bootable, but VFS does not know about my root device (/dev/sda1) until something (usually udev) triggers the usb_storage module.

My BIOS detects the flash ram as a USB floppy drive.

My grub commands are:

root (fd1) 

kernel /boot/vmlinuz_scsi root=/dev/sda1

initrd /boot/usbinitrd.img

boot

But I don't see linuxrc run at all.

Here is my linuxrc:

#!/bin/nash

echo "Loading ehci-hcd.ko module"

insmod /lib/ehci-hcd.ko 

echo "Loading usb-storage.ko module"

insmod /lib/usb-storage.ko 

sleep 5

echo Mounting /proc filesystem

mount -t proc /proc /proc

echo Creating block devices

mkdevices /dev

echo Creating root device

mkrootdev /dev/root

echo 0x0100 > /proc/sys/kernel/real-root-dev

echo Mounting root filesystem

mount -o noatime --ro -t ext3 /dev/root /sysroot

pivot_root /sysroot /sysroot/initrd

umount /initrd/proc

*EDIT*

In case anyone has the same problem, the answer is that ramdisk and initrd support need to be turned on in the kernel and the kernel should be passed the following arguments:

root=/dev/ram0 rw init=/linuxrc

Ref /usr/src/linux/Documentation/initrd.txtLast edited by Colonel Paneek on Tue Apr 26, 2005 9:10 am; edited 1 time in total

----------

## jdgill0

 *syadnom wrote:*   

> the question is, should one use an initrd as a general rule or not?  benefits? disadvantages?

 

Most of the time I think using an initrd is primarily for the benefit of using an all-in-one kernel, i.e. you have just about everything and the kitchen sink added as modules into your kernel (think genkernel here).  For such a kernel, you likely have the drivers for the various filesystems, the nic, NFS, etc as modules and those modules would need loading before your filesystem is available through the mount process.

Another possibility for initrd is diskless machines, in particular network card support.  Most of the time it is just recommended to compile support for the NIC in the diskless node's kernel, but you might have a heterogeneous set of machines and would like to maintain a single kernel for all of them, in which case adding the various NIC drivers as modules makes sense.  You would then need to use an initrd to provide the NIC driver to the diskless node's kernel.

Otherwise, there really isn't any benefit to using an initrd. The end result of booting a machine with or without an initrd is the same. Also, having an initrd just adds one more unnecessary point of failure to contend with if you really don't need it. (IMHO)

----------

## syadnom

jdgill0,

thanks for the great reply.  that was what i was looking for.

----------

## a.b.

Hi! Currently using Debian, I'm going to trying Gentoo (The tarball is currently downloading) and I've got one question for which I didn't find an answer anywhere:

What are the pros and cons of creating an initrd vs. compiling in the necessary drivers? Or is there any difference at all?

EDIT: I'll have to spam you until that n00b label goes away!  :Very Happy: 

----------

## nixnut

merged above post here.

Don't spam please. Upgrade your search foo instead.

----------

## Sadako

The only drivers you need to compile in the kernel to avoid needing an initrd are the drivers you'll need to boot, that's all, and if you need them to boot then there isn't really any good reason not to compile them in.

initrd's are (at least for most desktop systems) just an unnecessary complication, unless using one provides something you really want/need, I wouldn't bother.

The binary distro's kind of have to use them because the need to build/supply generic kernels that will run on and supply drivers for a wide array of hardware, this isn't really required if/when you build the kernel yourself specifically for your system.

Edit; Damn you, nixnut!

----------

## a.b.

@nixnut: I did search. I just did not find.

@Hopeless: Thanks. It was what I expected, but I wasn't sure if it's correct.

----------

## nixnut

 *a.b. wrote:*   

> @nixnut: I did search. I just did not find.

 Which is why I said upgrade, not emerge   :Wink: 

tip: use google and append site:forums.gentoo.org to the search keywords.

----------

