# initramfs confusion

## tenspd137

Hi all

I was trying to use an initramfs so I could mount drives using a LABEL=gentoo_root parameter.  I tried to follow the directions here:

https://forums.gentoo.org/viewtopic-t-850865.html?sid=d8eee5d0bd8e4282714c2937a4236ac6

and here:

http://en.gentoo-wiki.com/wiki/Initramfs

and my directory structure looks like this:

```

/usr/src/initramfs

find . | sort

.

./bin

./bin/busybox

./dev

./dev/console

./dev/hda

./dev/hda1

./dev/hda2

./dev/hda3

./dev/hdb

./dev/hdb1

./dev/null

./dev/sda

./dev/sda1

./dev/sdb

./dev/sdb1

./dev/sdc

./dev/sdc1

./dev/sdd

./dev/sdd1

./dev/sde

./dev/tty

./etc

./init

./lib

./mnt

./mnt/root

./proc

./root

./sbin

./sbin/mdev

./sys

```

with /sbin/mdev -> ../bin/busybox

and then I did 

find . -print0 | cpio --null -ov --format=newc | gzip -9 > /boot/labelinitramfs.gz 

I have tried with an external file

```

title Gentoo Linux 2.6.36-Gentoo

root (hd0,0)

kernel /boot/kernel-2.6.36-gentoo LABEL=gentoo_root

initrd /boot/labelinitramfs.gz

```

and /usr/src/initramfs compiled into the kernel

```

title Gentoo Linux 2.6.36-Gentoo

root (hd0,0)

kernel /boot/kernel-2.6.36-gentoo LABEL=gentoo_root

```

Either way I get a kernel panic that says it can't find /init - but it is there....

Even stranger, when I decided to go back, I commented out the initrd line in grub.conf but forgot to undo the LABEL=gentoo_root.  I also left:

```
 

LABEL=gentoo_boot       /boot           ext3            noatime 1 2

LABEL=gentoo_root       /               ext3            noatime         0 1

...

```

in /etc/fstab and everything booted back up.  So I am really confused as nothing seems to be working as I would expect.  The only thing I can think of is that it is ignoring LABEL and udev is doing something under the hood that I am unaware of.

Could anyone out there help me figure out how to make an initramfs such that/init is found so I can be sure I am mounting by label?  I am testing this out before I muck with a computer that has a HDD configuration that changes often.

Thanks for any help.

----------

## Hu

What is in /init in the initramfs?  What happens if you build an initramfs using the built-in support, instead of bolting one on at boot time?

----------

## tenspd137

So, I decided to try back to basics.  I went to the manual:

http://en.gentoo-wiki.com/wiki/Initramfs

and followed the directions up to Creating a Seperate File.  My init contains:

```

#!/bin/busybox sh

# Mount the /proc and /sys filesystems.

mount -t proc none /proc

mount -t sysfs none /sys

# Do your stuff here.

echo "This script mounts rootfs and boots it up, nothing more!"

# Mount the root filesystem.

mount -o ro /dev/sde3 /mnt/root

# Clean up.

umount /proc

umount /sys

# Boot the real thing.

exec switch_root /mnt/root /sbin/init

```

/dev/sde3 is now my root because I started using the new SATA/PATA drivers - it took me a while to figure that out, which is another reason I am looking at this - so I can boot by label and not have to worry what my drives are mounted as.  Anyway, no matter if I compile it in by specifying /usr/src/initramfs in the kernel menuconfig or if I try from a seperate file specified in grub.conf (initrd /boot/my-initramfs.cpio.gz)

I get:

Kernel Panic: Not syncing: No init found - try passing init= ...

(I tried that also) - no luck.

Not sure what I am missing.

Thanks.

----------

## whig

Unless overridden I think we need a /sbin/init. It can be a link to another location. In your list it is missing.

----------

## Goverp

Have you done chmod +x /usr/src/initramfs/init ?

----------

## systema encephale

Same problem here. I have a VMWare ESX 3.0.1 environment, where I can install Gentoo VMs with kernels not newer than 2.6.20. Apparently this is the only kernel version I've found that fully supports the SCSI controller. Also, I have to use the old Gentoo 2007 minimal install live cd, otherwise newer releases don't work. The kernel modules are the Fusion-MPT mptbase.ko, mptscsih.ko and mptspi.ko, that maybe have changed since 2.6.20.

I've created the initramfs in /usr/src/initramfs and followed the steps described in http://en.gentoo-wiki.com/wiki/Initramfs. My init script is

```
#!/bin/busybox sh

# Mount the /proc and /sys filesystems.

mount -t proc none /proc

mount -t sysfs none /sys

# Do your stuff here.

echo "This script mounts rootfs and boots it up, nothing more!"

load_modules || rescue_shell

# Mount the root filesystem.

mount -o ro /dev/sda1 /mnt/root || rescue_shell

# Clean up.

umount /proc

umount /sys

# Boot the real thing.

exec switch_root /mnt/root /sbin/init

rescue_shell() {

    echo "Something went wrong. Dropping you to a shell."

    busybox --install -s

    exec /bin/sh

}

load_modules() {

    MODULES="mptbase.ko mptscsih.ko mptspi.ko"

    MOD_PATH="/lib/modules"

    for MODULE in ${MODULES} ; do

        insmod -f ${MOD_PATH}/${MODULE}

    done

}
```

The modules are the ones generated from the 2.6.20. My root partition is actually /dev/sda1.

I created a cpio archive as well as set the /usr/src/initramfs in the kernel config. Like tenspd137, either way I get the kernel panic, not syncing, init not found error.

If I have to use kernel 2.6.20 I have also to downgrade udev, as the current version (151-r4) is not supported by kernels older than 2.6.25.

/usr/src/initramfs/init has 755 permissions.

Thanks

----------

## tenspd137

I tried linking /sbin/init -> /init - no luck.  I did chmod +x on /init.  It is as though the initramfs file is just totally being ignored.  I still tells me it can't find init or /sbin/init when I specify it.

Any other suggestions?  Could this be some sort of bug with the 2.6.36 kernel?  I dunno ---

----------

## Hu

I have used each of the last six major kernels (2.6.30, 2.6.31, etc.) with initramfs with no problems.  My initial process is /init and is part of the kernel image, as built by CONFIG_INITRAMFS_SOURCE.  It is activated automatically at boot, and transitions to my hard disk root filesystem after performing its work.  I have never seen a kernel ignore an initramfs in the manner reported here.

 *systema encephale wrote:*   

> Same problem here. I have a VMWare ESX 3.0.1 environment, where I can install Gentoo VMs with kernels not newer than 2.6.20. Apparently this is the only kernel version I've found that fully supports the SCSI controller.

 I believe there was a VMware bug that it misreported the number of SCSI controllers.  Kernels 2.6.20 and below ignored the bug.  Kernel 2.6.21 was affected, but I thought that newer versions had a patch to work around that.  Either way, I would expect that such an old bug should be fixed by now.  Is VMware ESX 3.0.1 the latest release of ESX server?

----------

## tenspd137

Sorry - just sort of grasping at straws.  I followed the manual except for changing the root drive to /dev/sde3, and it isn't working.  I don't know how to debug it or figure out what is happening.  I tried building it directly into the kernel and that did not work.  I am hesitant to do that because the only way I know to fix that is to rebuild without the image.  If I keep it as a seperate file, I can at least recover by commenting out the initrd line and add root=/dev/sde3 to the kernel line.

Thanks.

----------

## tenspd137

So - one thing I did find - if I omit the --format=newc option when making the cpio archive, I get a different result - it tells me it cant mount a file type / system.  So, could I be doing something wrong there?

Another question - is there some way I can slow the messages down at boot so I can actually see what is going on?

----------

## tenspd137

I stumbled across the dracut utility while trying to dig up more answers.  I tried it out and it appears to work - ie, I can mount by Label now.  I'd like to leave this open for now though because I still would like to know what I did wrong / why I can't get the instructions from the wiki page to work.

Thanks again!

----------

## Hu

Can you run (as root) chroot /usr/src/initramfs /bin/busybox sh successfully?  If not, what error does it print? *tenspd137 wrote:*   

> I don't know how to debug it or figure out what is happening.

 Without an equally broken setup, I cannot offer further advice on how to debug it.

 *tenspd137 wrote:*   

> I tried building it directly into the kernel and that did not work.

 That is good to know.  It suggests that your initscript or one of its dependencies is broken, rather than that you are packing it incorrectly.

 *tenspd137 wrote:*   

> I am hesitant to do that because the only way I know to fix that is to rebuild without the image.  If I keep it as a seperate file, I can at least recover by commenting out the initrd line and add root=/dev/sde3 to the kernel line.

 I no longer think building it in will solve your problem.  However, if you are concerned about having a kernel with the initramfs being more difficult to control, you could build two kernels and install both of them to /boot.

 *tenspd137 wrote:*   

> So - one thing I did find - if I omit the --format=newc option when making the cpio archive, I get a different result - it tells me it cant mount a file type / system.  So, could I be doing something wrong there?

 Yes.  Only one specific format is allowed.  By switching away from that format, you prevented the kernel from even unpacking your initramfs.

 *tenspd137 wrote:*   

> Another question - is there some way I can slow the messages down at boot so I can actually see what is going on?

 You might be able to achieve this with CONFIG_BOOT_PRINTK_DELAY.  You could also try using a higher resolution (e.g. framebuffer mode) so that more lines of text are visible.

----------

## tenspd137

No - as root, it tells me:

chroot: failed to run command `/bin/busybox sh': No such file or directory

which is odd, because it is there.  In fact, if I do just chroot /usr/src/initramfs, it tells me there is no /bin/bash - which is real odd and means I might have other issues.

----------

## tenspd137

After a little more digging - I found it meatn that I might not have the right libraries for bash in my directory I was chrooting into.  So I checked busybox:

ldd /bin/busybox

and got

linux-gate.so.1 =>  (0xb7834000)

	libm.so.6 => /lib/libm.so.6 (0x4a09b000)

	libpam_misc.so.0 => /lib/libpam_misc.so.0 (0x4a0c9000)

	libc.so.6 => /lib/libc.so.6 (0x49f3f000)

	libpam.so.0 => /lib/libpam.so.0 (0x4a537000)

	/lib/ld-linux.so.2 (0x49f1e000)

	libdl.so.2 => /lib/libdl.so.2 (0x4a0c3000)

Please correct me if I am wrong, but I set the static flag when I emerged it, so these libraries should not appear?  If so, then bb is not being built statically - I think.

----------

## tenspd137

Yup - that seem to be the problem - I just emerge -C busy box andre-emerged it this time adding -savedconfig to packages.use, so that only ipv6, mdev, and static were enabled.  After checking ldd and making sure it was static, I copied it to /usr/src/initramfs/bin/busybox and tried chrooting - worked this time.    Then I repackaged the initramfs archive and tried it out with:

qemu -kernel /boot/kernel-2.6.36-gentoo -initrd /boot/initramfs.cpio.gz

( I found that in the Linux Kernel Documentation, http://www.mjmwired.net/kernel/Documentation/filesystems/ramfs-rootfs-initramfs.txt , which I thought was a slick idea  :Smile:   I didn't have to reboot my computer)

Now it tries to kill init because it can't find sde3 - which is what I would expect.  I am going to try a reboot with it right now - be back in a minute...Last edited by tenspd137 on Sun Dec 05, 2010 12:14 am; edited 1 time in total

----------

## tenspd137

Works!  Thanks again for the hints - it would have taken me a very long time - if ever - before I stumbled across that.  I glossed over the part about using ldd to check busybox, I assumed that since I enabled static and disabled pam, all would be good - so I guess I didn't follow the directions to the letter.  Learned my lesson - next time I will be more cognizant of that.  I kind of put my faith in portage, which is 99.9% of the time okay to do.

Anyway, much appreciated.  no that I have anything against utilities like dracut, but sometimes it is nice to know what is going on.

Thanks so much again.

----------

## Hu

Good to see you got it working.  My first thought was that it would be a library linking issue, but I dismissed that because busybox is so often built statically and you were using it as your script interpreter.

----------

## systema encephale

Thanks to your suggestions I managed to build a correct initramfs and now I get busybox running the init script.

However, as I thought, it cannot load modules from another kernel version. At the moment I'm trying to load the 2.6.35-gentoo-r12 kernel with the mpt- modules from the 2.6.19 kernel (which are working for my hardware), but I cannot.

The actual error message is the following:

```
mptbase: version magic '2.6.19-gentoo-r5 SMP mod_unload 486 ' should be '2.6.35-gentoo-r12 SMP mod_unload PENTIUMIII '

insmod: can't insert '/lib/modules/mptbase.ko': invalid module format
```

and the same for mptscsih and mptspi modules.

Do you have any suggestions? I wouldn't use an initramfs if I didn't have to use external modules, otherwise I would have compiled everything into the kernel.

Thanks 1M

----------

## Hu

It is very unlikely that you will get those modules to work with that kernel version.  Even if you bypassed all the sanity checks and somehow forced the kernel to load those modules, I doubt that they would be compatible.  You should rebuild those modules with a modern kernel.

----------

## systema encephale

You're right Hu. Indeed I wanted to try compiling those modules from kernel 2.6.20 on a machine running 2.6.35. Do you think it could work?

----------

## Hu

You might be able to compile it, but I doubt you will get the modules to load unless they are from exactly the same kernel version.

----------

## systema encephale

What can I do then? Those modules from kernel 2.6.35 don't work for my hardware, if they did I wouldn't have needed an initramfs, I'd rather have compiled them into the kernel.

----------

## Hu

Run an old kernel (not recommended) or file a bug with the maintainer of the modules so that they can be fixed to work with your hardware.  Since they worked before, their failure now is a regression.

----------

## Mike81

Hi,

I am new in Gentoo. I am also working with VMware and need the Fusion MPT drivers on boot. In Debian, I would compile that driver as module and build an initrd file. It would work.

Genkernel created a initramsfs for me, which contains the drivers (I checked that), but on boot, the controller isn't accessible. My system won't boot, I need to open a shell and run the "modprobe mptspi" command so that Gentoo is able to mount the root fs and continue booting. So is that different in Gentoo?

Do I need to create such a custom initramfs with an own script? I like the generic kernels I know from Debian and other distributions, which are working out of the box or will it work as known from Debian, when I update my Gentoo, currently I am using 2007.0 with v2.6.19...

----------

## Hu

If you are new in Gentoo and using a 2007.0 system with a v2.6.19 kernel, I think you got off to a really bad start.  That configuration is so old that it will be extremely difficult to maintain.  How did you end up with such an old system if you are such a new user?

----------

## Mike81

 *Hu wrote:*   

> If you are new in Gentoo and using a 2007.0 system with a v2.6.19 kernel, I think you got off to a really bad start.  That configuration is so old that it will be extremely difficult to maintain.  How did you end up with such an old system if you are such a new user?

 I bought a book, which is recommended at gentoo.de. This book comes with a 2007.0 LiveCD, shows you the usage of the PORTAGE system and explains USE and KEYWORDs, problems when something will change (e.g. apache 2.0.5x to 2.2) and ends with the upgrade to 2008.0. The author is always mentioning, that you can upgrade every Gentoo system. In other distributions it becomes a real pain, but in Gentoo it should be different... so I thought starting with that book is a good start, because after that, I have done "everything" in Gentoo  :Wink: 

You have a different view?

Back to my question:

Will a current Gentoo behave differently? When I would build a current kernel on a current Gentoo, include the required Fusion MPT drivers as module and create a initramfs, would it work out of the box, like it is working on Debian? Actual I am not sure, if the "generic" thing is something new in the v2.6.2x series...

----------

## frostschutz

 *Quote:*   

> you can upgrade every Gentoo system

 

True.

 *Quote:*   

> you can upgrade every <insert distro name here> system

 

Also true.

That's where the trouble starts. Sometimes there just are changes that are not so simple. If you are an active Gentoo user who is updating very regularly, those changes will hit you one at a time, and it will hit all other users at the same time too, so if you should run into trouble you can go to the forums or IRC and the solution for the problem will be the first thing you see. So no problem there.

Unfortunately if you're from the past and upgrading from stone age to a modern system, you'll be hit by an entire pile of changes and problems that are so old that no one remembers how to solve them.

So yes sure you can do a stage1 install from when stage1 installs were still the norm with Gentoo. That was what, 5 years ago? And yes of course, you can upgrade from there. However that won't be a particularly enjoyable enterprise and you gain absolutely nothing from it.

So I recommend you put that book away (they tend to date out fairly quickly, unfortunately) and do a fresh install using a current stage and current docs as in the Gentoo handbook.

As for your initramfs problems, if there's nothing secret in it, can you upload your initramfs cpio archive somewhere? I'll have a look at it. Double check that the files are all in the right place and that all the binaries are actually executable, and static.

----------

## Mike81

 *frostschutz wrote:*   

> That's where the trouble starts. Sometimes there just are changes that are not so simple. If you are an active Gentoo user who is updating very regularly, those changes will hit you one at a time, and it will hit all other users at the same time too, so if you should run into trouble you can go to the forums or IRC and the solution for the problem will be the first thing you see. So no problem there.
> 
> Unfortunately if you're from the past and upgrading from stone age to a modern system, you'll be hit by an entire pile of changes and problems that are so old that no one remembers how to solve them.
> 
> So yes sure you can do a stage1 install from when stage1 installs were still the norm with Gentoo. That was what, 5 years ago? And yes of course, you can upgrade from there. However that won't be a particularly enjoyable enterprise and you gain absolutely nothing from it.
> ...

 

The last sentence irritate me. I have already read, that there were changes, but I have (currently) the opinion, that If I learn what changed, how it changed (maybe why something changed), that I will get a better understanding of the system.

Yes, sometimes, this may be frustrating, but in the end, I should really know Gentoo.

 *Quote:*   

> 
> 
> As for your initramfs problems, if there's nothing secret in it, can you upload your initramfs cpio archive somewhere? I'll have a look at it. Double check that the files are all in the right place and that all the binaries are actually executable, and static.

 Here is my  initramfs with the config.gz.

----------

