# Can't get working system with custom initramfs[solved]

## tenspd137

Hi all,

I have been following the wiki at http://en.gentoo-wiki.com/wiki/Initramfs to create a custom initramfs that will mount my /usr directory since it sits in a lvm on top of raid1.  Following the wiki using the mdadm, lvm, and devtmpfs pieces, my script looks like this

```

mount -t proc none /proc

mount -t sysfs none /sys

mount -t devtmpfs none /dev

uuidabel_root || rescue_shell 

load_modules || rescue_shell #load raid1 module

mdadm --assemble --scan /dev/md0 #mdadm.conf is in /etc with correct Judi

lvm vgscan --mknodes

lvm vgcange -ay

mount -t ext4 -o ro /dev/mapper/datavg-usr /mnt/root/usr || rescue_shell

umount /proc

umount /sys

umount /dev 

exec switch_root /mnt/root /sbin/init

```

It keeps freezing at init-early.sh used greatest stack depth.  I was using qinqy and noticed it was defaulting, so I changed back to the default inittab instead of one made for qingy. My kernel does have the v86d initramfs compiled in, but that around't cause any problems - it never did when I used a dracut made initramfs which has stopped working since I was bit by udev-182.  (I tried ensuring that all the raid, lvm, and usrmount stuff was present with no luck and I can no longer down grade udev because of dependencies).

Aack - any ideas?Last edited by tenspd137 on Mon Apr 02, 2012 4:16 am; edited 1 time in total

----------

## greyspoke

Is that the whole of your /init?  You don't show what is in the uuidabel_root or load_modules functions, so it is not clear what is going on.

----------

## tenspd137

Sorry, I should have been more explicit - I took the functions straight from the tutorial, so I did not put those in.

```

!/bin/busybox sh

uuidlabel_root() {

    for cmd in $(cat /proc/cmdline) ; do

        case $cmd in

        root=*)

            dev=${cmd#root=}

            type=${dev%%=*}

            if [ $type = "LABEL" ] || [ $type = "UUID" ] ; then

                mount -o ro $(findfs "$dev") /mnt/root

            else

                mount -o ro ${dev} /mnt/root

            fi

            ;;

        esac

    done

}

load_modules() {

    MODULES="raid1.ko"

    MOD_PATH="/lib/modules"

    for MODULE in ${MODULES} ; do

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

    done

}

rescue_shell() {

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

    busybox --install -s

    exec /bin/sh

}

# Mount the /proc and /sys filesystems.

mount -t proc none /proc

mount -t sysfs none /sys

mount -t devtmpfs none /dev

# Do your stuff here.

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

# Mount the root filesystem.

uuidlabel_root || rescue_shell

load_modules || rescue_shell

mdadm --assemble --scan /dev/md0

lvm vgscan --mknodes

lvm vgchange -ay

mount -t ext4 -o ro /dev/mapper/datavg-usr /mnt/root/usr || rescue_shell

# Clean up.

umount /proc

umount /sys

umount /dev

# Boot the real thing.

exec switch_root /mnt/root /sbin/init

```

One thing that just occurred to me is that I did not create a usr directory (/mnt/root/usr) to mount to.  That might be it - it can't find /sbin/init because I might be overmounting datavg-usr over /mnt/root.  I will try that when I get back this afternoon.

----------

## greyspoke

Well if you think everyting else is set OK (your grub.vonf and having everything you need in your initramfs or busybox) you could add rescue_shell to your script just before the exec switch_root and then have a rummage around to see if everything is mounted right.  You don't need a /mnt/root/usr in your initramfs, your root filesystem will replace that with its own /usr directory to mount on.

----------

## tenspd137

Yeah - the extra usr directory does not make sense - doh!  I'll try adding the rescue_shell before exec and look at what is mounted.. Another thought - it looks as though the raid volume that my usr directory is on needs to resync- could the freeze be because it is waiting for that to finish?. I thought that was supposed to be transparent, but maybe not...

----------

## Hu

 *tenspd137 wrote:*   

> 
> 
> ```
>                 mount -o ro $(findfs "$dev") /mnt/root
> 
> ...

 Does /mnt/root exist? *tenspd137 wrote:*   

> 
> 
> ```
> load_modules() {
> 
> ...

 Did you include this module in the initramfs?  Why did you make it a module at all, if you need it for the entire life of the system?  Make it built-in instead.

----------

## tenspd137

I rebuilt the kernel and made raid1 a built-in and commented load_modules in my script.  /mnt/root does exist in my initramfs. I dropped into the rescue shell before the clean up portion and verified that /mnt/root contains my root directory and my datavg-usr vg is mounted to /mnt/root/usr.  Just for fun I tried running the last few commands in my script from the console with no luck.  I then removed the line to drop me into a rescue shell

the contents of my initramfs is

```

/init

/bin/busybox

/sbin

/sbin/mdadm

/sbin/lvm

/sys

/dev

/lib

/etc

/etc/mdadm.conf

/mnt/root

/root

/proc

```

I also checked that devtmpfs is enabled in my kernel and added sleep 10 after mounting devtmpfs.

Any other thoughts?  It seems that what I am doing is easy.  I can't be the only person on the planet with usr in a lvm on raid setup.  One thing I did notice is that there is a complaint about md0 having an unknown partition table, but my lvm stuff is still being found.

----------

## tenspd137

One thought - do I need to mount boot since it is on a separate partition?  My thought is no - that should all be handled with fstab or udev after switch_root in the script, but I have been known to be wrong

----------

## Hu

You do not need to mount boot in the initramfs.  You say that you ran the commands by hand.  Did they produce any output?

----------

## tenspd137

The answer lies here:

https://forums.gentoo.org/viewtopic-t-880149.html?sid=7de597df34c53ddac05ecde28596c507

It appears that when I set up my system, my stage3 tarball was affected by a bug that incorrectly setup some device nodes needed by used.  From what I understand, my install should have never worked but it did.

Now everything works and I know how to build my very own initramfs (bonus)

Thanks for taking the time to help me debug this.  I was searching for the wrong thing in google.  I found this after searching for busybox switch_root does nothing.

----------

