# initrd vs initramfs

## lenos

Hi!

I play around with a liveCD based on gentoo. I upgraded from gentoo-2004.x -> gentoo-2005.1-r1 and suddenly my liveCD doesn't boot anymore. I build the kernel using genkernel.

The kernel message I get is:

"Could not find ramdisk image: initramfs"

I use isolinux as CD boot loader and the entry in isolinux.cfg looks like this:

label qnds

  kernel vmlinuz

  append initrd=initramfs ramdisk_size=65535 prompt_ramdisk=0 rw root=/dev/ram0 vga=normal

The initramfs file is placed in the same location where I placed the initrd file earlier when it all worked.

I figured out it has to do with initramfs being used in the newer gentoo release but I can't find any descent docs on how to use initramfs (really, I tried googling...) I found a post in this forum on how to build the initramfs image but it seems some vital information is still missing since the kernel can't find the image, or perhaps finds it and discards it for some reason.

I also found the kernel option INITRAMFS_SOURCE but I don't want to have to rebuild the kernel every time I change something in the initramfs image.

Any help appreciated, I'm stuck...

----------

## fuzzythebear

Of course you will need to tweak .. but this is how i got it working 

title Gentoo Linux 2.6.14-r3 AUTO

root (hd0,1)

kernel /kernel-genkernel-x86-2.6.14-gentoo-r3 root=/dev/ram0 /linuxrcamdisk=8192 real_root=/dev/hda3 vga=791 splash=silent

initrd /initramfs-genkernel-x86-2.6.14-gentoo-r3

excuse the formatting .. but the kernel line is one line till splash=silent 

which was a personal choice.

hope that helps / works for you.

Fuzzy

----------

## fuzzythebear

bad formatting and then some .. 

i just saw .. didnt notice it while previewing sorry .. 

title Gentoo Linux 2.6.14-r3 AUTO

root (hd0,1)

kernel /kernel-genkernel-x86-2.6.14-gentoo-r3 root=/dev/ram0 init=/linuxrc ramdisk=8192 real_root=/dev/hda3 vga=791 splash=silent

initrd /initramfs-genkernel-x86-2.6.14-gentoo-r3

Fuzz

----------

## lenos

Thanks, but it didn't solve my problem.

The grub config file will not work for me since I use isolinux

I build my own initramfs (named initramfs, with proprietary init, startup scripts, ...) image so I can't use the gentoo prebuilt one

I tried changing my isolinux.cfg file to

```

default qnds

prompt 0

display message.txt

label qnds

  kernel vmlinuz

  append initrd=/initramfs ramdisk=8192 root=/dev/ram0 vga=791 splash=silent devfs=nomount 

```

kernel still complains about "Could not find ramdisk image: /initramfs"  (this time with the leading slash ahead).

I can't use the real_root kernel option since I don't know from which device the image is booted (it's a CDROM, could be located anywhere). The init code in the initramfs image determines the boot device instead and the initramfs never returns control to the kernel so as I see it there's no need for the real_root option. I just need the kernel to unpack and start the initramfs image and I'm good to go...

----------

## sundialsvc4

On your /boot directory, you must not only have the kernel-image but also the initramfs image.  It sounds like this second file does not exist, or is improperly named.  The file-name must be exactly correct, with particular attention paid to the placement of slashes...  reflecting the root-directory structure as seen by the boot loader and by the kernel during this phase of the boot.

There are therefore four things to check:   That the contents of the file are correct.  That the file is actually there.  That the boot loader can see it.  That the kernel has been correctly told to reference it. 

----------

## lenos

First of all, your post made me realize it's not the kernel but the boot loader who is complaining about not finding initramfs, thanks. I then renamed initramfs to initrd and then the boot loader (isolinux) finds it and loads it. The kernel starts executing and later complains about:

"Failed to execute /init"

"Kernel panic - not syncing: No init found. Try passing init= option to kernel."

1. The contents of the file I don't know how to check really. I built it using info from another post on this forum. Let's assume I put the contents at /tmp/contents then I use the following lines to build the image (I removed all error handling for clarity and use hardcoded path names instead of the symbolic ones I use in the script):

```

( cd /tmp/contents

   find . -print | cpio --quiet -o -H newc > /tmp/initramfs

   gzip -9 -c /tmp/initramfs > "isolinux directory"/initramfs

)

```

In /tmp/contents I've put

```

sbin/

  init        -- my init executable

init          -- symlinked to /sbin/init

linuxrc     -- symlinked to /sbin/init

initramfs  -- symlinked to /sbin/init

... a lot of other stuff of course like required libs and so on...

```

Some of the symlinks should satisfy the kernel... I also tried replacing the symlinks with actual copies of the /sbin/init file, same result.

2. When I step into the "isolinux directory" the initramfs file is there, together with the kernel image and isolinux.cfg. Don't know how to further check it out.

3. This one is sorted out now.

4. And how do I do that? There's the init= option and the root= option. No matter what I set init= to, I get the same error message. root= should be /dev/ram0 I guess?

Is there really no initramfs howto available? 

I also saw something about mkinitramfs but can't emerge it? Is this distro dependent?

----------

## lenos

I skipped initramfs, reverted to old initrd again. Still didn't work. Got an "No init found" error message. The problem was that I missed a library needed by my proprietary init. So the init binary (/sbin/init) was there but not the required lib. Not the best of error messages from the kernel, but why should things be easy...

----------

## Apropos

Read  /usr/src/linux/Documentation/early-userspace/README.  I have one in the latest linux-2.6.14-hardened-r1 source.  At the bottom it sort of explains the difference between an initrd and an initramfs.  I'm still trying to figure it out myself.  Hope it helps.

----------

## lenos

Thanks, I'll check it out. From what I've seen else where in forums "early userspace" seems to be a good idea but its benefits doesn't justify the hazzle of getting it to work. At least I fail to see what I personally gain from it, apart from some saved RAM perhaps. The liveCD I'm playing around with is targeted for older PC's which typically have 64MB+ RAM so a little wasted RAM is no big deal. 

I understand the kernel developer perspective though, where they want to "purify" the kernel and move stuff out to user space.

----------

## Apropos

Okay after actually reading your post thoroughly I think I see what may help.

I use both an initramfs cpio file built into the kernel and an initrd file in /boot.  The builtin initramfs is a cpio file with directories and whatnot for the splash screen.  It is compiled into the kernel.

I also use an initrd file stored in my /boot directory along with my kernel.  This is a filesystem (ext2) with evms_activate so I can see my root partition.  I notice above that you used cpio for what I think is an initrd file.

The kernel can read and use both at bootup.

So try this because this is what I do to modifiy my initrd in /boot.

First get the size of your directory tree:

```
du -s /tmp/contents
```

I assume from "ramdisk_size=65535" it is about 64k but I'll leave it up to you.  Since you never return control back to the kernel you are probably setting it to the size of all your ram but I don't know what else is using memory.

Add about 10% (ext2 overhead) to what you actually need (but not more than the space you have in ram) and create a file for your ext2 filesystem:

```
dd if=/dev/zero of=/tmp/initrd bs=1k count=64
```

Make an ext2 filesystem on that file:

```
mkfs.ext2 -b 1024 -F -v /tmp/initrd
```

If necessary load the loop module into the kernel:

```
modprobe loop
```

Mount the loop device at say /mnt/initrd using the new file /tmp/initrd:

```
mount /tmp/initrd /mnt/initrd -t ext2 -o loop
```

Double check your filesystem size to see if you have enough room for all your files (ext2 takes up some space):

```
df /dev/loop0
```

Copy your disk tree over to the newly mounted loop device:

```
cp -Rp /tmp/contents/* /mnt/initrd/
```

Unmount the loop device, gzip it and move it to /boot or wherever you kernel is:

```
umount /mnt/initrd

gzip /tmp/initrd

mv /tmp/initrd.gz /boot
```

I think that is it.  Good luck.

Edit:  I think the 64k might be 64M and that would change the dd command above to count=64000.

----------

## lenos

From my earlier post:

 *Quote:*   

> The problem was that I missed a library needed by my proprietary init. So the init binary (/sbin/init) was there but not the required lib.

 

That is, I didn't include a library which was required by the init code, hence the kernel couldn't find an init (or rather execute it). After putting the  library file in the initrd image it all worked and I was happy with that. But after reading your last post it struck me, why not try the initramfs approach again, now that the required library is in place. So I cpio:ed the same files (and added a symlink from /init -> /sbin/init since this is required in an initramfs image) and now the initramfs image works as well.

So everything was just a silly mistake   :Embarassed:  of forgetting a required library in the first place. But, as so often, you learn from your mistakes (silly or not) and now I know a lot more about "early userspace" than before   :Smile: 

Thanks for your help!

----------

