[ solved ] geexbox with rootfs inside initrd

Home Forums Miscellaneous [ solved ] geexbox with rootfs inside initrd

Viewing 15 posts - 1 through 15 (of 15 total)
  • Author
    Posts
  • #2067
    rubiki
    Member

    hello from Chongqing

    too strange? write reply and you can not see it

     

    hi, now with 2.0.1 it’s NTFS ok, thanks.

    and , I want to put the rootfs in the initrd, (so no need to find rootfs , easy for boot geexbox using iso or pxe or memory only)

    I tried to unpack initrd and put rootfs in the root of initrd,
    and then , when booting, set kernel parameter like this: kernel /vmliuz root=/dev/ram0

    but failed, just dropped to the command shell “can not find squashfs”

    then, in the command shell, I tried to mount rootfs manualy:

    mount -t squashfs /rootfs /squashfs
    ./init
    exec switch_root /newroot /sbin/init

    and then, it just works. XBMC appears, and I can play everything.

    so, put rootfs in initrd should work, but the kernel parameter is wrong.
    what should it be , other than  “root=/dev/ram0” , if I put rootfs into initrd ?

    #2072
    tomlohave
    Keymaster

    You need to modify init inside initrd for this.

    #2073
    tomlohave
    Keymaster

    in file init inside initrd : add:
    – line 87 :
    [ “$ROOT” = initrd ] && ROOTFS=”/rootfs” && ROOTFSI=”initrd” && unset ROOT

    – line 137 :
    [ “$ROOTFSI” = initrd ] && ROOT=”initrd” && mount -t squashfs /$ROOTFS /squashfs >/dev/null 2>&1
    # …otherwise just scan the block devices for rootfs

    and boot with
    root=initrd

    not tested ….

    mark as solved

    #2082
    rubiki
    Member

    it works. thank you.

    #2086
    tomlohave
    Keymaster

    😉

    #2999
    Don_Manuel
    Participant

    I tried this solution, but I could only reproduce the results of the first posting. When I looked at my init script, neither line 87 nor line 137 make any sense. My understanding of the script is too weak as to figure out myself, where these two magic lines will help.

    Hopefully the following code posting shows up right, as you could point to the right lines to insert that code (as you see I found yet out how to move rootfs to an arbitrary folder, but I need that big initrd in order to boot from PXE):
    #!/bin/sh

    dbg_echo () {
    [ "$QUIET" = yes ] || echo $*
    return
    }

    # install busybox symlinks
    /bin/busybox --install -s

    export PATH=/sbin:/bin

    # mount required filesystems
    busybox mount -t proc none /proc
    busybox mount -t sysfs none /sys

    # prepare /dev
    mount -t devtmpfs devtmpfs /dev
    echo '/bin/mdev' > /proc/sys/kernel/hotplug
    mdev -s

    # splash
    /bin/ply-image /plymouth/splash.png

    # parse kernel cmdline
    for arg in $(cat /proc/cmdline); do
    case $arg in
    root=*)
    ROOT="${arg#root=}"
    ;;
    data=*)
    DATA="${arg#data=}"
    ;;
    init=*)
    INIT="${arg#init=}"
    ;;
    quiet)
    QUIET=yes
    ;;
    persistent)
    PERSISTENT=yes
    ;;
    initshell)
    echo "Dropping to shell as requested"
    exec sh
    ;;
    esac
    done

    # try to mount the rootfs specified in cmdline...
    if [ -n "$ROOT" ]; then
    dbg_echo -n "Trying root=$ROOT as requested..."
    if mount -o ro $ROOT /mnt >/dev/null 2>&1; then
    if mount -t squashfs /mnt/rootfs /squashfs >/dev/null 2>&1; then
    dbg_echo "found."
    else
    dbg_echo "failed, cannot mount squashfs."
    umount /mnt
    unset ROOT
    fi
    else
    dbg_echo "failed, cannot mount device."
    unset ROOT
    fi
    fi

    # ...otherwise just scan the block devices for rootfs
    if [ -z "$ROOT" ]; then
    dbg_echo "Scanning for root device:"
    cd /sys/block
    for i in 0 1 2 3 4 5 6 7 8 9; do
    for dev in *; do
    echo $dev | grep -q loop && continue
    echo $dev | grep -q ram && continue
    dbg_echo -n "[$i] Trying $dev..."
    if ! mount -o ro /dev/$dev /mnt >/dev/null 2>&1; then
    # check for removable devices not built with isohybrid support
    if [ $(cat /sys/block/$dev/removable) = 1 ]; then
    dbg_echo -n "[$i] Trying ${dev}1..."
    if ! mount -o rw /dev/${dev}1 /mnt >/dev/null 2>&1; then
    dbg_echo "failed, cannot mount device."
    continue
    fi
    else
    dbg_echo "failed, cannot mount device."
    continue
    fi
    fi
    if mount -t squashfs /mnt/images/geexbox/rootfs /squashfs >/dev/null 2>&1; then
    dbg_echo "found."
    FOUND_ROOTFS=yes
    break
    else
    dbg_echo "failed, cannot mount squashfs."
    umount /mnt
    fi
    done
    [ -n "$FOUND_ROOTFS" ] && break
    sleep 1
    done
    cd /
    fi

    [ -z "$INIT" ] && INIT=/bin/systemd

    if [ ! -x /squashfs/$INIT ]; then
    echo "Cannot find a valid root filesystem, dropping to shell"
    exec sh
    fi

    # setup aufs
    if [ "$PERSISTENT" = yes ]; then
    DATA=/mnt/casper-rw
    PERSISTENT_OPT="-o loop -t ext2"
    [ ! -f "$DATA" ] && unset DATA && unset PERSISTENT_OPT
    fi
    if [ -n "$DATA" ]; then
    if ! mount $PERSISTENT_OPT -o rw,noatime $DATA /rw; then
    echo "Cannot mount data partition, using tmpfs instead"
    unset DATA
    fi
    fi
    [ -z "$DATA" ] && mount -t tmpfs none /rw
    if ! mount -t aufs -o br=/rw:/squashfs none /newroot; then
    echo "Cannot mount aufs, dropping to shell"
    exec sh
    fi

    # move backed filesystems inside newroot otherwise aufs won't work properly
    mkdir -p /newroot/run
    mount -t tmpfs -o mode=0755,nosuid,nodev tmpfs /newroot/run
    mkdir -p /newroot/.data /newroot/.squashfs /newroot/.root
    mount --move /rw /newroot/.data
    mount --move /squashfs /newroot/.squashfs
    mount --move /mnt /newroot/.root
    mkdir -p /newroot/run/initramfs/bin /newroot/run/initramfs/sbin
    cp -P /bin/busybox /bin/sh /newroot/run/initramfs/bin/
    cp -P /bin/shutdown /newroot/run/initramfs/

    INIT_ARGS=`cat /proc/cmdline`

    # Reset kernel hotplugging
    echo "" > /proc/sys/kernel/hotplug
    umount /sys
    umount /dev
    umount /proc

    # Change to the new root partition and execute /sbin/init
    if ! exec /bin/busybox switch_root /newroot $INIT $INIT_ARGS; then
    echo "Failed, dropping to shell"
    /bin/busybox mount -t proc none /proc
    /bin/busybox mount -t sysfs none /sys
    exec sh
    fi

    Thank’s in the name of all fans of OmniBoot 🙂
    The next release will contain geexbox, the one or the other way.

    #3000
    tomlohave
    Keymaster

    Please, check your mail box

    #3840
    frescoraja
    Participant

    i’m sorry but how did you unpack the initrd?? it tells me it’s an xz compressed image and i can’t find anything about how to decompress that. thanks for any help!

    #3841
    frescoraja
    Participant

    so i ended up running the following command to unpack the initrd:

    xz -d initrd | gpio -i

    then i took the rootfs and put it into the root of the unpacked initrd folder

    now i need help with where to put the lines suggested above by tomlohave in the init script

    i don’t think line 87 and line 137 work, as someone mentioned before me.

    thanks for any guidance

    mkbootfs /initrd | xz -c > initrdnew

    #3842
    frescoraja
    Participant

    SORRY TO POST AGAIN,
    but here is where I THINK the new lines suggested by tomlohave go (or this is what i think the new init script will look like , including his changes)
    #!/bin/sh

    dbg_echo () {
    [ “$QUIET” = yes ] || echo $*
    return
    }

    # install busybox symlinks
    /bin/busybox –install -s

    export PATH=/sbin:/bin

    # mount required filesystems
    busybox mount -t proc none /proc
    busybox mount -t sysfs none /sys

    # prepare /dev
    mount -t devtmpfs devtmpfs /dev
    echo ‘/bin/mdev’ > /proc/sys/kernel/hotplug
    mdev -s

    # splash
    /bin/ply-image /plymouth/splash.png

    # parse kernel cmdline
    for arg in $(cat /proc/cmdline); do
    case $arg in
    root=*)
    ROOT=”${arg#root=}”
    ;;
    data=*)
    DATA=”${arg#data=}”
    ;;
    init=*)
    INIT=”${arg#init=}”
    ;;
    quiet)
    QUIET=yes
    ;;
    persistent)
    PERSISTENT=yes
    ;;
    initshell)
    echo “Dropping to shell as requested”
    exec sh
    ;;
    esac
    done
    [ “$ROOT” = initrd ] && ROOTFS=”/rootfs” && ROOTFSI=”initrd” && unset ROOT
    # try to mount the rootfs specified in cmdline…
    if [ -n “$ROOT” ]; then
    dbg_echo -n “Trying root=$ROOT as requested…”
    if mount -o ro $ROOT /mnt >/dev/null 2>&1; then
    if mount -t squashfs /mnt/rootfs /squashfs >/dev/null 2>&1; then
    dbg_echo “found.”
    else
    dbg_echo “failed, cannot mount squashfs.”
    umount /mnt
    unset ROOT
    fi
    else
    dbg_echo “failed, cannot mount device.”
    unset ROOT
    fi
    fi
    [ “$ROOTFSI” = initrd ] && ROOT=”initrd” && mount -t squashfs /$ROOTFS /squashfs >/dev/null 2>&1
    # …otherwise just scan the block devices for rootfs
    if [ -z “$ROOT” ]; then
    dbg_echo “Scanning for root device:”
    cd /sys/block
    for i in 0 1 2 3 4 5 6 7 8 9; do
    for dev in *; do
    echo $dev | grep -q loop && continue
    echo $dev | grep -q ram && continue
    dbg_echo -n “[$i] Trying $dev…”
    if ! mount -o ro /dev/$dev /mnt >/dev/null 2>&1; then
    # check for removable devices not built with isohybrid support
    if [ $(cat /sys/block/$dev/removable) = 1 ]; then
    dbg_echo -n “[$i] Trying ${dev}1…”
    if ! mount -o rw /dev/${dev}1 /mnt >/dev/null 2>&1; then
    dbg_echo “failed, cannot mount device.”
    continue
    fi
    else
    dbg_echo “failed, cannot mount device.”
    continue
    fi
    fi
    if mount -t squashfs /mnt/rootfs /squashfs >/dev/null 2>&1; then
    dbg_echo “found.”
    FOUND_ROOTFS=yes
    break
    else
    dbg_echo “failed, cannot mount squashfs.”
    umount /mnt
    fi
    done
    [ -n “$FOUND_ROOTFS” ] && break
    sleep 1
    done
    cd /
    fi

    [ -z “$INIT” ] && INIT=/bin/systemd

    if [ ! -x /squashfs/$INIT ]; then
    echo “Cannot find a valid root filesystem, dropping to shell”
    exec sh
    fi

    # setup aufs
    if [ “$PERSISTENT” = yes ]; then
    DATA=/mnt/casper-rw
    PERSISTENT_OPT=”-o loop -t ext2″
    [ ! -f “$DATA” ] && unset DATA && unset PERSISTENT_OPT
    fi
    if [ -n “$DATA” ]; then
    if ! mount $PERSISTENT_OPT -o rw,noatime $DATA /rw; then
    echo “Cannot mount data partition, using tmpfs instead”
    unset DATA
    fi
    fi
    [ -z “$DATA” ] && mount -t tmpfs none /rw
    if ! mount -t aufs -o br=/rw:/squashfs none /newroot; then
    echo “Cannot mount aufs, dropping to shell”
    exec sh
    fi

    # move backed filesystems inside newroot otherwise aufs won’t work properly
    mkdir -p /newroot/run
    mount -t tmpfs -o mode=0755,nosuid,nodev tmpfs /newroot/run
    mkdir -p /newroot/.data /newroot/.squashfs /newroot/.root
    mount –move /rw /newroot/.data
    mount –move /squashfs /newroot/.squashfs
    mount –move /mnt /newroot/.root
    mkdir -p /newroot/run/initramfs/bin /newroot/run/initramfs/sbin
    cp -P /bin/busybox /bin/sh /newroot/run/initramfs/bin/
    cp -P /bin/shutdown /newroot/run/initramfs/

    INIT_ARGS=`cat /proc/cmdline`

    # Reset kernel hotplugging
    echo “” > /proc/sys/kernel/hotplug
    umount /sys
    umount /dev
    umount /proc

    # Change to the new root partition and execute /sbin/init
    if ! exec /bin/busybox switch_root /newroot $INIT $INIT_ARGS; then
    echo “Failed, dropping to shell”
    /bin/busybox mount -t proc none /proc
    /bin/busybox mount -t sysfs none /sys
    exec sh
    fi

    PLEASE CORRECT ME IF I’M WRONG, I HAVE YET TO TEST THIS

    THANKS
    frescoraja

    #3844
    frescoraja
    Participant

    so, just to clarify:
    to unpack the initrd use

    xz -dc initrd | cpio -i

    move rootfs to root of unpacked initrd

    make changes to init

    repack initrd using :

    mkbootfs initrd/ | xz -z > newinitrd

    then put replace the old initrd with the new one, and remaster the iso..

    last but not least, when i want to remake the iso image, can i just use the following command taken from isolinux wiki???

    mkisofs -o output.iso \
    -b isolinux/isolinux.bin -c isolinux/boot.catalog \
    -no-emul-boot -boot-load-size 4 -boot-info-table \
    CD_root

    THANKS!

    #3845
    tomlohave
    Keymaster

    here is a working init for this :  init

    #3860
    frescoraja
    Participant

    i get the same error stilll:

    [0 -10] Trying sr0…..cp: can’t stat ‘/mnt//rootfs’ : no such file or directory
    failed, cannot mount squashfs.
    Cannot find a valid root filesystem, dropping to shell

    but from the shell i can mount rootfs

    why are there two “//” between mnt and rootfs? is that the problem? is that something in the init file?

    thanks again for the guidance

    #3861
    frescoraja
    Participant

    ok i figured out my problem .. . i copied and pasted from your file and it had some weird characters instead of ” ” around initrd
    and i also neglected to put root=initrd in my isolinux.cfg file
    thanks again for the help !!

    #3868
    tomlohave
    Keymaster

    no problem 🙂

Viewing 15 posts - 1 through 15 (of 15 total)
  • The topic ‘[ solved ] geexbox with rootfs inside initrd’ is closed to new replies.