OpenWrt Forum Archive

Topic: Boot from USB stick with kamikaze on WL500gP kernel 2.6 not possible

The content of this topic has been archived on 15 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

hi

i want to boot from usbstick with kamikaze kernel 2.6

this is my try in /sbin/init

#!/bin/sh

for module in usbcore ehci-hcd ohci-hcd scsi_mod sd_mod usb-storage ext2 ; do {
        insmod $module
}; done

# mount the usb stick
sleep 4s
boot_dev="/dev/sda1"
mount "$boot_dev" /mnt
# if everything looks ok, do the pivot root
[ -x /mnt/sbin/init ] && {
        mount -o move /proc /mnt/proc && \
        pivot_root /mnt /mnt/rom && {
                mount -o move /rom/dev /dev
#                umount /root/oldroot/tmp
        }
}

exec /bin/busybox init

...

this doesnt work .. but the drive is usable when the system is up....

greets
puchu

Maybe you should wait a little bit longer than 4 secs? I'm using 10 secs on my WGT634U & WL-500gx, and it works fine...
Additionally I'm using /dev/scsi/host0/bus0/target0/lun0/part<n> instead of /dev/sda<n>

but u are for shure on a 2.4 kernel ... devices in 2.6 are not named /dev/scsi/host0/bus0/target0/lun0/part<n> any more ...

but i found a solution ....
maybe this isnt needed but it seems to work
2.6 device manager like udev or hotplug2 ... therefor i start it .... but i dont much about hotplug2 rules and there for all partitions or mounted into the all root in /tmp/sda* .. thats why i umnount /dev/sda1 .... but i think this isnt needed.......

# mount the usb stick

        /sbin/hotplug2 --persistent &
        echo /sbin/hotplug-call > /proc/sys/kernel/hotplug
for module in usbcore ehci-hcd ohci-hcd scsi_mod sd_mod usb-storage ext2 ; do {
        insmod $module
}; done

sleep 10s
boot_dev="/dev/sda1"
umount $boot_dev
mount "$boot_dev" /mnt
# if everything looks ok, do the pivot root
[ -x /mnt/sbin/init ] && {
        mount -o move /proc /mnt/proc && \
        pivot_root /mnt /mnt/rom && {
                mount -o move /rom/dev /dev
        }
}

exec /bin/busybox init

took me a long time to figure out what it needs to start um my sys from hd with a 2.6 kernel ....

greets

Usually /dev/sda is only a link to /dev/scsi/...

I explicitly disable hotplug before boot from usb, and it works both on a 2.4 kernel (wl-500gx) and a 2.6 kernel (wgt634u).

I modify /etc/preinit (opposed to /sbin/init), my code is based on the code from Olegs FW for the wl-500 series.

can u post your preinit please?

I added the function usb_boot and it's called later on.
tmpfs is not used, because I want a presistent tmp directory on the usb disk. And it saves ram too.
You could load only selected kernel modules, but it does't hurt if moduled are not available, already load or compiled in.

#!/bin/sh
# Copyright (C) 2006 OpenWrt.org

. /etc/functions.sh
. /etc/diag.sh

usb_boot() {
    set +x

    # get the boot device
    boot_dev=/dev/scsi/host0/bus0/target0/lun0/part2

    # short-cut
    if [ -z "$boot_dev" ]; then
      return
    fi

    # disable hotplug
    echo > /proc/sys/kernel/hotplug

    # if your root is fat/vfat
    insmod nls_base
    insmod fat
    insmod vfat

    insmod ext2
    insmod jbd
    insmod ext3

    # load modules for usb storage
    insmod usbcore
    insmod ohci-hcd
    insmod uhci-hcd
    insmod ehci-hcd
    insmod scsi_mod
    insmod sd_mod
    insmod usb-storage

    # wait for initialization to complete
    echo "Waiting for 10 seconds for USB devices..."
    sleep 10s
    echo "Finished waiting."

    # trying to mount new rootfs if it exists
    mount -t ext3 -o rw,noatime $boot_dev /mnt || mount -t ext2 -o rw,noatime $boot_dev /mnt

    # enable hotplug
    echo /sbin/hotplug > /proc/sys/kernel/hotplug

    if [ -d /mnt/mnt ]; then
            echo "USB boot disk successfully mounted"
            cd /mnt

            pivot_root . mnt

            mount none /proc -t proc
            mount none /dev -t devfs
            mkdir -p /dev/pts
            mount none /dev/pts -t devpts
            mount none /proc/bus/usb -t usbfs
            mount none /sys -t sysfs

            umount /mnt/proc
            umount /mnt/dev

#           size=$(awk '/Mem:/ {l=5242880;print((s=$2/2)<l)?$2-l:s}' /proc/meminfo)
#           mount none /tmp -t tmpfs -o size=$size

            exec chroot . sbin/init <dev/null >dev/null 2>&1
    fi

    # if something fails
    cd /

    # unmount everything
    umount /mnt
}

failsafe() {
        lock /tmp/.failsafe

        echo "0 1 2 3 4 5u*" > /proc/switch/eth0/vlan/0/ports

        set_state failsafe
        [ -x "/usr/sbin/nvram" ] && {
                [ "$(nvram get boot_wait)" != "on" ] && {
                        nvram set boot_wait=on
                        nvram commit
                }
        }

        netmsg 192.168.1.255 "Entering Failsafe!"
        telnetd -l /bin/login <> /dev/null 2>&1

        ash --login
        lock -u /tmp/.failsafe
}

export PATH=/bin:/sbin:/usr/bin:/usr/sbin
mount none /proc -t proc

usb_boot

size=$(awk '/Mem:/ {l=5242880;print((s=$2/2)<l)?$2-l:s}' /proc/meminfo)
mount none /tmp -t tmpfs -o size=$size

insmod diag
set_state preinit
trap 'FAILSAFE=true' USR1
echo '/sbin/hotplug.failsafe' > /proc/sys/kernel/hotplug

ifname=eth0

# hardware specific overrides
case "$(cat /proc/diag/model)" in
        "Linksys WAP54G V1") ifname=eth1;;
        "ASUS WL-HDD") ifname=eth1;;
        "ASUS WL-300g") ifname=eth1;;
        "ASUS (unknown, BCM4702)") ifname=eth1;;
esac

insmod switch-core
insmod switch-robo || insmod switch-adm || rmmod switch-core

ifconfig $ifname 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255 up

[ -d /proc/switch/eth0 ] && {
        echo 1 > /proc/switch/eth0/reset

        # this would be easier if we blasted the message across all ports
        # but we don't want packets leaking across interfaces
        for port in $(seq 0 4); do {
                echo "$port 5u*" > /proc/switch/eth0/vlan/0/ports
                netmsg 192.168.1.255 "Press reset now, to enter Failsafe!"
        }; done
} || netmsg 192.168.1.255 "Press reset now, to enter Failsafe!"

sleep 2

eval ${FAILSAFE:+failsafe}

lock -w /tmp/.failsafe
set_state preinit
echo /sbin/hotplug > /proc/sys/kernel/hotplug

ifconfig $ifname 0.0.0.0 down

mount_root
exec /sbin/init

hi

thanks ... look good .. but i dont have /dev/scsi/host0/bus0/target0/lun0/part2 ...
i dont even have  /dev/scsi

but you are shure that u have on a 2.6 kernel /dev/scsi?

greets

BusyBox v1.2.1 (2006.12.15-11:51+0000) Built-in shell (ash)
Enter 'help' for a list of built-in commands.

  _______                     ________        __
|       |.-----.-----.-----.|  |  |  |.----.|  |_
|   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
|_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
KAMIKAZE (bleeding edge, r5895) -------------------
  * 10 oz Vodka       Shake well with ice and strain
  * 10 oz Triple sec  mixture into 10 shot glasses.
  * 10 oz lime juice  Salute!
---------------------------------------------------
root@xxxx:~# mount
/dev/root on /mnt type jffs2 (ro)
/dev/scsi/host0/bus0/target0/lun0/part1 on / type ext3 (rw,noatime,data=ordered)
none on /proc type proc (rw)
none on /dev type devfs (rw)
none on /dev/pts type devpts (rw)
none on /proc/bus/usb type usbfs (rw)
none on /sys type sysfs (rw)
none on /tmp type tmpfs (rw)
root@xxxx:~# cat /proc/version
Linux version 2.6.19.1 (yyyy@xxxx) (gcc version 3.4.6 (OpenWrt-2.0)) #1 Sat Dec 23 23:56:38 CET 2006
root@xxxx:~# ls /dev -l
crw-------    1 root     root       5,   1 Jan 11 14:32 console
drwxr-xr-x    1 root     root            0 Jan  1  1970 discs
crw-rw-rw-    1 root     root       1,   7 Jan  1  1970 full
crw-r-----    1 root     root       1,   2 Jan  1  1970 kmem
crw-r--r--    1 root     root       1,  11 Jan  1  1970 kmsg
srw-rw-rw-    1 root     root            0 Jan  1  2000 log
crw-r-----    1 root     root       1,   1 Jan  1  1970 mem
drwxr-xr-x    1 root     root            0 Jan  1  1970 mtd
drwxr-xr-x    1 root     root            0 Jan  1  1970 mtdblock
crw-rw-rw-    1 root     root       1,   3 Jan  1  1970 null
crw-r-----    1 root     root       1,   4 Jan  1  1970 port
crw-------    1 root     root     108,   0 Jan  1  1970 ppp
crw-rw-rw-    1 root     root       5,   2 Apr  2 12:08 ptmx
drwxr-xr-x    2 root     root            0 Jan  1  2000 pts
crw-r--r--    1 root     root       1,   8 Jan  1  1970 random
lr-xr-xr-x    1 root     root           10 Jan  1  2000 root -> mtdblock/2
drwxr-xr-x    1 root     root            0 Jan  1  1970 scsi
drwxr-xr-x    1 root     root            0 Jan  1  1970 shm
drwxr-xr-x    1 root     root            0 Jan  1  1970 tts
crw-rw-rw-    1 root     root       5,   0 Jan  1  1970 tty
crw-r--r--    1 root     root       1,   9 Jan  1  1970 urandom
crw-rw-rw-    1 root     root       1,   5 Jan  1  1970 zero

Are you sure, all required kernel modules are successfully loaded? What does lsmod say?

(Last edited by MMCM on 2 Apr 2007, 11:12)

hi

maybe u have devfs in the kernel? i dont ....

here is my output .... and sda* is not a symlink as it seems to me ....


mount
rootfs on / type rootfs (rw)
/dev/root on /rom/rom type squashfs (ro)
none on /proc type proc (rw)
none on /rom/tmp type tmpfs (rw)
none on /sys type sysfs (rw)
tmpfs on /dev type tmpfs (rw)
none on /dev/pts type devpts (rw)
/dev/mtdblock4 on /rom/jffs type jffs2 (rw)
/jffs on /rom type mini_fo (rw)
/dev/sda1 on / type ext2 (rw)
/dev/sda3 on /mnt/data type ext2 (rw,sync,noatime)
/dev/sda4 on /mnt/share type ext2 (rw,sync,noatime)
/dev/mtdblock2 on /tmp/mtdblock2 type squashfs (ro)

cat /proc/version
Linux version 2.6.19.2 (puchu@tux) (gcc version 4.1.2) #1 Sun Apr 1 20:51:21 CEST 2007


ls -ls /dev/
   0 lrwxrwxrwx    1 root     root           58 Jan  1  2000 1-1:1.0 -> /dev/scsi/host0/target0:0:0/0:0:0:0/bus0/target0/lun0/part
   0 lrwxrwxrwx    1 root     root           58 Jan  1  2000 bConfigurationValue -> /dev/scsi/host0/target0:0:0/0:0:0:0/bus0/target0/lun0/part
   0 lrwxrwxrwx    1 root     root           58 Jan  1  2000 bDeviceClass -> /dev/scsi/host0/target0:0:0/0:0:0:0/bus0/target0/lun0/part
   0 lrwxrwxrwx    1 root     root           58 Jan  1  2000 bDeviceProtocol -> /dev/scsi/host0/target0:0:0/0:0:0:0/bus0/target0/lun0/part
   0 lrwxrwxrwx    1 root     root           58 Jan  1  2000 bDeviceSubClass -> /dev/scsi/host0/target0:0:0/0:0:0:0/bus0/target0/lun0/part
   0 lrwxrwxrwx    1 root     root           58 Jan  1  2000 bMaxPacketSize0 -> /dev/scsi/host0/target0:0:0/0:0:0:0/bus0/target0/lun0/part
   0 lrwxrwxrwx    1 root     root           58 Jan  1  2000 bMaxPower -> /dev/scsi/host0/target0:0:0/0:0:0:0/bus0/target0/lun0/part
   0 lrwxrwxrwx    1 root     root           58 Jan  1  2000 bNumConfigurations -> /dev/scsi/host0/target0:0:0/0:0:0:0/bus0/target0/lun0/part
   0 lrwxrwxrwx    1 root     root           58 Jan  1  2000 bNumInterfaces -> /dev/scsi/host0/target0:0:0/0:0:0:0/bus0/target0/lun0/part
   0 lrwxrwxrwx    1 root     root           58 Jan  1  2000 bcdDevice -> /dev/scsi/host0/target0:0:0/0:0:0:0/bus0/target0/lun0/part
   0 lrwxrwxrwx    1 root     root           58 Jan  1  2000 bmAttributes -> /dev/scsi/host0/target0:0:0/0:0:0:0/bus0/target0/lun0/part
   0 lrwxrwxrwx    1 root     root           58 Jan  1  2000 bus -> /dev/scsi/host0/target0:0:0/0:0:0:0/bus0/target0/lun0/part
   0 lrwxrwxrwx    1 root     root           58 Jan  1  2000 configuration -> /dev/scsi/host0/target0:0:0/0:0:0:0/bus0/target0/lun0/part
   0 crw-r--r--    1 root     root       5,   1 Apr  2 14:25 console
   0 lrwxrwxrwx    1 root     root           58 Jan  1  2000 devnum -> /dev/scsi/host0/target0:0:0/0:0:0:0/bus0/target0/lun0/part
   0 lrwxrwxrwx    1 root     root           58 Jan  1  2000 driver -> /dev/scsi/host0/target0:0:0/0:0:0:0/bus0/target0/lun0/part
   0 lrwxrwxrwx    1 root     root           58 Jan  1  2000 ep_00 -> /dev/scsi/host0/target0:0:0/0:0:0:0/bus0/target0/lun0/part
   0 crw-r--r--    1 root     root       1,   7 Jan  1  2000 full
   0 lrwxrwxrwx    1 root     root           58 Jan  1  2000 idProduct -> /dev/scsi/host0/target0:0:0/0:0:0:0/bus0/target0/lun0/part
   0 lrwxrwxrwx    1 root     root           58 Jan  1  2000 idVendor -> /dev/scsi/host0/target0:0:0/0:0:0:0/bus0/target0/lun0/part
   0 crw-r--r--    1 root     root       1,   2 Jan  1  2000 kmem
   0 crw-r--r--    1 root     root       1,  11 Jan  1  2000 kmsg
   0 srw-rw-rw-    1 root     root            0 Jan  1  2000 log
   0 lrwxrwxrwx    1 root     root           58 Jan  1  2000 maxchild -> /dev/scsi/host0/target0:0:0/0:0:0:0/bus0/target0/lun0/part
   0 crw-r--r--    1 root     root       1,   1 Jan  1  2000 mem
   0 crw-r--r--    1 root     root      90,   0 Jan  1  2000 mtd0
   0 crw-r--r--    1 root     root      90,   1 Jan  1  2000 mtd0ro
   0 crw-r--r--    1 root     root      90,   2 Jan  1  2000 mtd1
   0 crw-r--r--    1 root     root      90,   3 Jan  1  2000 mtd1ro
   0 crw-r--r--    1 root     root      90,   4 Jan  1  2000 mtd2
   0 crw-r--r--    1 root     root      90,   5 Jan  1  2000 mtd2ro
   0 crw-r--r--    1 root     root      90,   6 Jan  1  2000 mtd3
   0 crw-r--r--    1 root     root      90,   7 Jan  1  2000 mtd3ro
   0 crw-r--r--    1 root     root      90,   8 Jan  1  2000 mtd4
   0 crw-r--r--    1 root     root      90,   9 Jan  1  2000 mtd4ro
   0 brw-r--r--    1 root     root      31,   0 Jan  1  2000 mtdblock0
   0 brw-r--r--    1 root     root      31,   1 Jan  1  2000 mtdblock1
   0 brw-r--r--    1 root     root      31,   2 Jan  1  2000 mtdblock2
   0 brw-r--r--    1 root     root      31,   3 Jan  1  2000 mtdblock3
   0 brw-r--r--    1 root     root      31,   4 Jan  1  2000 mtdblock4
   0 crw-r--r--    1 root     root       1,   3 Jan  1  2000 null
   0 crw-r--r--    1 root     root       1,   4 Jan  1  2000 port
   0 lrwxrwxrwx    1 root     root           58 Jan  1  2000 product -> /dev/scsi/host0/target0:0:0/0:0:0:0/bus0/target0/lun0/part
   0 crw-rw-rw-    1 root     root       5,   2 Apr  2 14:37 ptmx
   0 drwxr-xr-x    2 root     root            0 Jan  1  2000 pts
   0 crw-r--r--    1 root     root       1,   8 Jan  1  2000 random
   0 brw-r--r--    1 root     root       8,   0 Jan  1  2000 sda
   0 brw-r--r--    1 root     root       8,   1 Jan  1  2000 sda1
   0 brw-r--r--    1 root     root       8,   2 Jan  1  2000 sda2
   0 brw-r--r--    1 root     root       8,   3 Jan  1  2000 sda3
   0 brw-r--r--    1 root     root       8,   4 Jan  1  2000 sda4
   0 drwxr-xr-x    2 root     root           40 Jan  1  2000 shm
   0 lrwxrwxrwx    1 root     root           58 Jan  1  2000 speed -> /dev/scsi/host0/target0:0:0/0:0:0:0/bus0/target0/lun0/part
   0 lrwxrwxrwx    1 root     root           58 Jan  1  2000 subsystem -> /dev/scsi/host0/target0:0:0/0:0:0:0/bus0/target0/lun0/part
   0 crw-r--r--    1 root     root       5,   0 Apr  2 14:29 tty
   0 crw-r--r--    1 root     root       4,  64 Jan  1  2000 ttyS0
   0 crw-r--r--    1 root     root       4,  65 Jan  1  2000 ttyS1
   0 lrwxrwxrwx    1 root     root           58 Jan  1  2000 uevent -> /dev/scsi/host0/target0:0:0/0:0:0:0/bus0/target0/lun0/part
   0 crw-r--r--    1 root     root       1,   9 Jan  1  2000 urandom
   0 lrwxrwxrwx    1 root     root           58 Jan  1  2000 usb_device:usbdev1.2 -> /dev/scsi/host0/target0:0:0/0:0:0:0/bus0/target0/lun0/part
   0 lrwxrwxrwx    1 root     root           58 Jan  1  2000 usb_endpoint:usbdev1.2_ep00 -> /dev/scsi/host0/target0:0:0/0:0:0:0/bus0/target0/lun0/part
   0 crw-r--r--    1 root     root     189,   0 Jan  1  2000 usbdev1.1
   0 crw-r--r--    1 root     root     186,   0 Jan  1  2000 usbdev1.1_ep00
   0 crw-r--r--    1 root     root     186,   0 Jan  1  2000 usbdev1.1_ep81
   0 crw-r--r--    1 root     root     189,   1 Jan  1  2000 usbdev1.2
   0 lrwxrwxrwx    1 root     root           58 Jan  1  2000 usbdev1.2_ep00 -> /dev/scsi/host0/target0:0:0/0:0:0:0/bus0/target0/lun0/part
   0 crw-r--r--    1 root     root     186,   1 Jan  1  2000 usbdev1.2_ep02
   0 crw-r--r--    1 root     root     186,   1 Jan  1  2000 usbdev1.2_ep81
   0 lrwxrwxrwx    1 root     root           58 Jan  1  2000 version -> /dev/scsi/host0/target0:0:0/0:0:0:0/bus0/target0/lun0/part
   0 lrwxrwxrwx    1 root     root            8 Jan  1  2000 zero -> /dev/pts
root@xxxxx:/dev# ls -ls /dev/scsi
ls: /dev/scsi: No such file or directory

dont know whats going on ......

greets

talked to some developers .... they mean ... devfs was replaced by hotplug2 in 2.6.19.2 and therefor no /dev/scsi any more.....

Which openwrt release are you running? I checked my "youngest" wgt634u, it's running r6447 with kernel 2.6.19.2 and /dev/scsi is still there. And USB boot is working...
So udev must have been intruduced some time later after the 2.6.19.2 kernel.

Looking at your output, I assume USB boot is working now?

If it's working, would you post your script here, so others running udev can use it?

hi,

rev 6794 is mine ......
and udev isnt used ... hotplug2 is used .. a stripped version of udev .....

i changed something..... and it took me a long time because there is nearly no info on this ... or i couldnt find it .....

first you have to disable the entry for hotplug2 in /etc/init.d/boot ...... otherwise it would start two times .... it is initialized in preinit by my script.....

-snippet-----

        # manually trigger hotplug before loading modules
        for iface in $(awk -F: '/:/ {print $1}' /proc/net/dev); do
                /usr/bin/env -i ACTION=add INTERFACE="$iface" /sbin/hotplug-call net
        done

#       /sbin/hotplug2 --persistent &
        echo /sbin/hotplug-call > /proc/sys/kernel/hotplug
-snippet ----

so and in preinit you do this .....


###########################
ifconfig $ifname 0.0.0.0 down
mount_root
usb=0
# mount the usb stick

        /sbin/hotplug2 --persistent &
        echo /sbin/hotplug-call > /proc/sys/kernel/hotplug
        for module in usbcore ehci-hcd ohci-hcd scsi_mod sd_mod usb-storage ext2 ; do {
                insmod $module
        }; done

        sleep 10s
        boot_dev="/dev/sda1"
        mount "$boot_dev" /mnt
        # if everything looks ok, do the pivot root
        [ -e /mnt/usb.boot ] && [ -x /mnt/sbin/init ] && {
        mount -o move /proc /mnt/proc && \
        pivot_root /mnt /mnt/rom && {
                mount -o move /rom/dev /dev
                mount -o move /rom/rom/sys /sys
                umount /rom/tmp
                usb=1
        }
}

#no usbstick or no boot from it wanted
[ $usb -eq 0 ] && {
        umount /mnt
}

exec /sbin/init

#####

another test i implemented is ..... there has to be a file called "usb.boot" in / on the bootdisk (sda1) .. only do "touch usb.boot" on sda1.....
i do this because if i dont want to boot from the disk i delete the file and reboot smile

this script took me a long time ... i dont have a serial console and therefore i had to guess whats wrong when the sys didnt come up ... but i did it smile


and one other disadvantage is that all usb partitions get mounted in /tmp/sda* and in /rom/tmp/sda* .... first mounted before the pivot_root and then mounted again
when moving the /sys fs .....

this can be avoided by deleting all lines in /etc/hotplug.d/block/01-mount .....

greets

(Last edited by puchu on 3 Apr 2007, 12:28)

The discussion might have continued from here.