OpenWrt Forum Archive

Topic: OpenWRT 8.09.2 booting from USB stick with NSLU2

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

Hi guys, flashed today 8.09.2 and spent some time reading several (outdated) topics but cannot get my nslu2 booting properly, hopefully can get a hint from you guys:

When I boot my nslu2 at this stage it shows the following  " df -h" :

root@OpenWrt:~# df -h
Filesystem                Size      Used Available Use% Mounted on
rootfs                    1.4M      1.4M         0 100% /
/dev/root                 1.4M      1.4M         0 100% /rom
/dev/mtdblock5            4.9M      1.1M      3.7M  23% /jffs
mini_fo:/jffs             1.4M      1.4M         0 100% /


These steps have been executed so far for Kamikaze 8.09-2

upslug2 -i openwrt-nslu2-squashfs.bin

telnet 192.168.1.1
vi /etc/config/network

config interface lan
        option ifname   eth0
        option proto      static
        option ipaddr    192.168.178.77
        option netmask 255.255.255.0
        option gateway 192.168.178.1
   
vi /etc/resolv.conf
    nameserver 192.168.178.1

vi /etc/hostname

passwd

/etc/init.d/network restart

Unplug LAN cable and put both pc/laptop and nslu2 on router
Open a new terminal and log in to kamikaze on new address specified
?
opkg update
opkg install e2fsprogs tune2fs fdisk kmod-usb-corekmod-usb2 kmod-scsi-core kmod-usb-storage kmod-fs-ext3
opkg remove -recursive ppp-mod-pppoe wireless-tools


vi /etc/modules.d/60-usb-storage ( for multicard readers )
    scsi_mod max_sci_luns=8
sd_mod
usb-storage


dmesg to see if usb device is registered:
Initializing USB Mass Storage driver...
usbcore: registered new interface driver usb-storage
USB Mass Storage support registered.

usb 3-2: new high speed USB device using ehci_hcd and address 2
usb 3-2: configuration #1 chosen from 1 choice
scsi0 : SCSI emulation for USB Mass Storage devices
usb-storage: device found at 2
usb-storage: waiting for device to settle before scanning
scsi 0:0:0:0: Direct-Access     Kingston DataTraveler 2.0 PMAP PQ: 0 ANSI: 0 CCS
sd 0:0:0:0: [sda] 1007616 512-byte hardware sectors (516 MB)
sd 0:0:0:0: [sda] Write Protect is off
sd 0:0:0:0: [sda] Mode Sense: 23 00 00 00
sd 0:0:0:0: [sda] Assuming drive cache: write through
sd 0:0:0:0: [sda] 1007616 512-byte hardware sectors (516 MB)
sd 0:0:0:0: [sda] Write Protect is off
sd 0:0:0:0: [sda] Mode Sense: 23 00 00 00
sd 0:0:0:0: [sda] Assuming drive cache: write through
sda: sda1
sd 0:0:0:0: [sda] Attached SCSI removable disk
usb-storage: device scan complete
kjournald starting.  Commit interval 5 seconds
EXT3 FS on sda1, internal journal
EXT3-fs: mounted filesystem with ordered data mode.


fdisk -l ( should show /dev/sda1 )
fdisk /dev/sda
( make EXT3 partition without any swap )
reboot

umount /dev/sda1   
mke2fs -j /dev/sda1
tune2fs -c0 -i0 /dev/sda1
( if reboot executed: umount -f /home )
mount -t ext3 /dev/sda1 /mnt
mkdir /tmp/root
mount -o bind /rom /tmp/root
cp /tmp/root/* /mnt -a
umount /tmp/root
umount /mnt


vi /etc/init.d/pivotroot
#!/bin/sh
boot_dev="/dev/sda1"
/sbin/hotplug2 --override -persistent --max-children 1 --no-coldplug &

for module in usbcore ehci-hcd scsi_mod usb-storage jbd ext3; do {
        insmod $module
}; done

killall hotplug2


# mount the usb stick
sleep 10s
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/mnt && {
                mount -o move /mnt/dev /dev
                mount -o move /mnt/tmp /tmp
                mount -o move /mnt/jffs /jffs 2>&-
                mount -o move /mnt/sys /sys 2>&-
        }
}


chmod +x /etc/init.d/pivotroot

vi /etc/init.d/rcS

#!/bin/sh                                                                       
# Copyright (C) 2006 OpenWrt.org                                               
                                                                               
run_scripts() {                                                                 
        for i in /etc/rc.d/$1*; do                                             
                [ -x $i ] && $i $2 2>&1                                         
        done | $LOGGER                                                         
}                                                                               
                                                                               
LOGGER="cat"                                                                   
[ -x /usr/bin/logger ] && LOGGER="logger -s -p 6 -t sysinit"                   
                                                                               
#                                                                               
# Switch to pivoroot if available                                               
#                                                                               
if [ "$2" == "boot" -a -x /etc/init.d/pivotroot ] ; then                       
      echo "[`date`]: Pivot root log created." > /tmp/pivotroot.log             
      /etc/init.d/pivotroot >> /tmp/pivotroot.log                               
fi                                                                             
                                                                               
if [ "$1" = "S" ]; then                                                         
        run_scripts "$1" "$2" &                                                 
else                                                                           
        run_scripts "$1" "$2"                                                   
fi                                                                             



cat /tmp/pivotroot.log
oot@OpenWrt:~# cat /tmp/pivotroot.log
[Sun Feb 14 15:02:32 UTC 2010]: Pivot root log created.
root@OpenWrt:~#


root@OpenWrt:~# ls -last /etc/init.d/pivotroot
   1 -rwxr-xr-x    1 root     root          895 Feb 14 14:52 /etc/init.d/pivotroot
root@OpenWrt:~#


Like to know what I am doing wrong here as when I execute the pivotroot manually things start to roll:

root@OpenWrt:~# /etc/init.d/pivotroot         
insmod: cannot insert '/lib/modules/2.6.26.8/usbcore.ko': File exists (-1): File exists
insmod: cannot insert '/lib/modules/2.6.26.8/ehci-hcd.ko': File exists (-1): File exists
insmod: cannot insert '/lib/modules/2.6.26.8/scsi_mod.ko': File exists (-1): File exists
insmod: cannot insert '/lib/modules/2.6.26.8/usb-storage.ko': File exists (-1): File exists
insmod: cannot insert '/lib/modules/2.6.26.8/jbd.ko': File exists (-1): File exists
insmod: cannot insert '/lib/modules/2.6.26.8/ext3.ko': File exists (-1): File exists

root@OpenWrt:/mnt/root# cat /tmp/pivotroot.log
[Sun Feb 14 15:02:32 UTC 2010]: Pivot root log created.
root@OpenWrt:/mnt/root#

root@OpenWrt:/mnt/root# df -h
Filesystem                Size      Used Available Use% Mounted on
rootfs                  470.9M     14.7M    431.9M   3% /
/dev/root                 1.4M      1.4M         0 100% /mnt/rom
/dev/mtdblock5            4.9M      1.1M      3.7M  23% /mnt/jffs
mini_fo:/jffs             1.4M      1.4M         0 100% /mnt
/dev/sda1               470.9M     14.7M    431.9M   3% /
root@OpenWrt:/mnt/root#


When I don't execute steps from "  vi /etc/init.d/pivotroot "  and below I get:
root@OpenWrt:~# df -h
Filesystem                Size      Used Available Use% Mounted on
rootfs                    1.4M      1.4M         0 100% /
/dev/root                 1.4M      1.4M         0 100% /rom
/dev/mtdblock5            4.9M      1.1M      3.7M  23% /jffs
mini_fo:/jffs             1.4M      1.4M         0 100% /
/dev/sda1               470.9M     14.7M    431.9M   3% /home
root@OpenWrt:~#



All I am trying to achieve is to boot from USB Stick, write all settings and packages to  USB stick instead of flash so I can build my own little system. Did things changes since 8.09.2?

Please awaiting your answers!

updated working sequence for me, steps shown as below were taken.
Currently thinking of better way of removing symbolic link to /var and which other redundant packages I can remove from the nslu2


apt-get install upslug2
download http://downloads.openwrt.org/kamikaze/ver/ixp4xx/ openwrt-nslu2-squashfs.bin
sudo su
upslug -i openwrt-nslu2-squashfs.bin


telnet 192.168.1.1
passwd

vi /etc/config/network
    config interface lan
                    option ifname        eth0
                    option proto        static
                    option ipaddr        192.168.178.77
                    option netmask    255.255.255.0
                    option gateway    192.168.178.1

echo "nameserver 192.168.178.1" > /etc/resolv.conf

/etc/init.d/network restart

touch /.ext3flash
echo "0" > /proc/sys/vm/swappiness

opkg update
opkg install kmod-fs-ext3 kmod-usb2 kmod-usb-storage fdisk e2fsprogs
opkg remove -recursive ppp-mod-pppoe wireless-tools
df -h
    Filesystem                Size      Used Available Use% Mounted on
    rootfs                    1.4M      1.4M         0 100% /
    /dev/root                 1.4M      1.4M         0 100% /rom
    mini_fo:/tmp/root         1.4M      1.4M         0 100% /tmp/root
    /dev/mtdblock5            4.9M      1.1M      3.8M  22% /jffs
    mini_fo:/jffs             1.4M      1.4M         0 100% /

( plug in usb disk if formatted )
df -h
    Filesystem                Size      Used Available Use% Mounted on
    rootfs                    1.4M      1.4M         0 100% /
    /dev/root                 1.4M      1.4M         0 100% /rom
    mini_fo:/tmp/root         1.4M      1.4M         0 100% /tmp/root
    /dev/mtdblock5            4.9M      1.1M      3.8M  22% /jffs
    mini_fo:/jffs             1.4M      1.4M         0 100% /
    /dev/sda1               470.9M     10.3M    436.3M   2% /home
   
   
( not formatted )
fdisk /dev/sda1
reboot

umount /dev/sda1
mkfs.ext3 /dev/sda1 ( take note of " Use tune2fs -c or -i to override " )
mount -t ext3 /dev/sda1 /mnt
mkdir /tmp/root
mount -o bind /rom /tmp/root
cp /tmp/root/* /mnt -a

rm /mnt/etc/resolv.conf ( to remove symbolic link to /tmp/resolv.conf )
echo "nameserver 192.168.178.1" > /mnt/etc/resolv.conf

mkdir /mnt/var2
cp -R /mnt/var/* /mnt/var2
umount /tmp
mv var2 var
cd /
umount /mnt
df -h
        Filesystem                Size      Used Available Use% Mounted on
        rootfs                    1.4M      1.4M         0 100% /
        /dev/root                 1.4M      1.4M         0 100% /rom
        /dev/mtdblock5            4.9M      1.1M      3.8M  23% /jffs
        mini_fo:/jffs             1.4M      1.4M         0 100% /

vi /etc/init.d/pivotroot
#!/bin/sh
boot_dev="/dev/sda1"
/sbin/hotplug2 --override --persistent --max-children 1 --no-coldplug &
for module in usbcore ehci-hcd scsi_mod usb-storage jbd ext3 ; do {
        insmod $module
        }; done
       
        # this may need to be higher if your disk is slow to initialize
        sleep 4s
        # mount the usb stick
        mount "$boot_dev" /mnt
        # if everything looks ok, do the pivot root
killall hotplug2
        [ -x /mnt/sbin/init ] && {
                mount -o move /proc /mnt/proc && \
                pivot_root /mnt /mnt/mnt && {
                mount -o move /mnt/dev /dev
                mount -o move /mnt/tmp /tmp
                mount -o move /mnt/jffs2 /jffs2 2>&-
                mount -o move /mnt/sys /sys 2>&-
          }
}


chmod 755 /etc/init.d/pivotroot
ln -s /etc/init.d/pivotroot /etc/rc.d/S10pivotroot


vi /etc/init.d/rcS
        #!/bin/sh
        # Copyright (C) 2006 OpenWrt.org
       
        run_scripts() {
            for i in /etc/rc.d/$1*; do
                [ -x $i ] && $i $2 2>&1
            done | $LOGGER
        }
       
        if [ $2 == "boot" -a -x /etc/init.d/pivotroot ] ; then
                /etc/init.d/pivotroot > /tmp/pivotroot.log
        fi
       
        LOGGER="cat"
        [ -x /usr/bin/logger ] && LOGGER="logger -s -p 6 -t sysinit"
       
        if [ "$1" = "S" ]; then
            run_scripts "$1" "$2" &
        else
            run_scripts "$1" "$2"
        fi
       
       
echo "Booted off internal flash" >> /etc/banner


reboot


telnet 192.168.178.77 ( ssh does not work now if all went fine )
passwd
df -h:
    Filesystem                Size      Used Available Use% Mounted on
    rootfs                  470.9M     14.6M    432.0M   3% /
    /dev/root                 1.4M      1.4M         0 100% /mnt/rom
    /dev/mtdblock5            4.9M      1.1M      3.8M  23% /mnt/jffs
    mini_fo:/jffs             1.4M      1.4M         0 100% /mnt
    /dev/sda1               470.9M     14.6M    432.0M   3% /
   
touch /.ext3flash
echo "0" > /proc/sys/vm/swappiness

opkg update
opkg install procps -force-overwrite
opkg install tune2fs usbutils unzip bzip2
tune2fs -c0 -i0 /dev/sda1

Hmm still not satisfied but guess I am learning:
Few remaining questions regarding booting off USB Stick:


If I remove /etc/fstab in order to remove symolic link to tmp and recreate fstab as below this should not do any harm, I am asking as default setting is sync which I made async as the stick stays on the nslu2 and noatime to limit writes
/etc/fstab -  /dev/sda1       /home   ext3    noauto,rw,async,noatime  0       0



When pivotroot has been created and I restart from stick I notice that usually dev/sda1 gets mounted twice, how can I get rid of that behaviour?
/dev/sda1               470.9M     16.5M    430.1M   4% /mnt/home
/dev/sda1               470.9M     16.5M    430.1M   4% /

OR

/dev/sda1               470.9M     14.6M    432.0M   3% /mnt/mnt/sda1
/dev/sda1               470.9M     14.6M    432.0M   3% /



For some reason I cannot keep these settings as these reset all the time on reboot, how to avoid this?
echo "0" > /proc/sys/vm/swappiness ( after reboot back to 60 )
echo "2" > /proc/cpu/alignment ( after reboot back to 0 )



When I install vsftp after pivotroot, booting off usb stick, I cannot get the vsftpd running while rebooting the slug. Is it correct this needs to be configured before the pivotroot is in place so in other words make it work in flash before moving on to boot from usb?

vi /etc/vsftpd.conf
      background=YES
    listen=YES
    anonymous_enable=NO
    local_enable=YES
    write_enable=YES
    local_umask=022
    check_shell=NO
    use_localtime=YES
    xferlog_enable=NO
    session_support=NO
    connect_from_port_20=YES
    chroot_local_user=YES
    chroot_list_enable=YES
    chroot_list_file=/etc/vsftpd.chroot_list
    ls_recurse_enable=YES

echo "root" > /etc/vsftpd.chroot_list
chmod 644 /etc/vsftpd.conf
ln -s /etc/init.d/vsftpd /etc/rc.d/S50vsftpd
/etc/init.d/vsftpd enable
/etc/init.d/vsftpd start

starting manually on prompt vsftpd runs fine " 2311 root      20   0   808  204  148 S  0.0  0.7   0:00.00 vsftpd "

The discussion might have continued from here.