OpenWrt Forum Archive

Topic: HOWTO: Boot WGT634U off a USB external partition

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

I do understand there are ways to make a device to boot off of a USB2 memory stick. However, since OpenWRT SVN trunk has gone under a lot of changes, some of the existing approaches may no longer work due to recent changes on mount_root. So, I decided to post my configurations (based on approach by dhkauffman as shown on his blog). To do this, I have modified several files that I provided below.

Below is my /etc/config/fstab, /etc/init.d/rcS scripts file, my modified /etc/init.de2fsck scripts file (from e2fsck package), and the modified /etc/init.d/pivotroot scripts file derived from dhkauffman's blog. My modification implements switch statements and makes use of /dev/sd*. It is by no means complete and may contain bugs; however, it works just fine on my WGT634U device without any problem, yet. So, please use it at your own discretions and please do let's know how it goes. I have all these files included under my openwrt-svn-trunk/files/etc/init.d directory so that they will be incorporated into the firmware during the build process.

For my WGT634U device, I compile the OpenWRT to include cfdisk and swap-utils packages (both under Utilities -> disc sub menu) into the firmware mainly because they are indispensable utilities for me to create needed partitions. To make my WGT634U device to boot off a USB2 external partition, I have used an old Patriot 512MB USB2 memory stick to achieve the task. It comes with two physical partitions, i.e. sda (~480MB) and sdb (~25MB). So, the swap partition is on /dev/sdb1. Before I can use this USB memory stick, it needs to be partitioned and formatted. I used cfdisk /dev/sda to create a primary partition (/dev/sda1) with Type 83 and cfdisk /dev/sdb to create a swap partition (/dev/sdb1) with Type 82. Then, I used mkfs.ext3 -L "WGT634U/OpenWRT" /dev/sda1 to format the /dev/sda1 as ext3 partition with "WGT634U/OpenWRT" as its label and mkswap -L "Swap" /dev/sdb1 to create a swap partition on /dev/sdb1 with "Swap" as its label. If you decide to use a swap partition and it is on /dev/sda2, please make the necessary changes to replace /dev/sdb1 with /dev/sda2 on all occasions, this includes the contents on /etc/config/fstab file, too.

After I have flashed the firmware to my WGT634U device, I do the following (at first boot) to make my device to boot with the new firmware:

1. Insert a USB2 memory stick to the USB2 port on the device. Assuming the USB2 memory stick already has been properly partitioned as above.

2. If the device is mounted after the USB2 memory stick is inserted and it contains some (important) data, additional and/or necessary precaution steps must be taken to insure the data has been backed up before reformatting the partition (requires to unmount the partition).

3. Once the partition is formatted, temporarily mount it, i.e. mount /dev/sda1 /usb/sda1, on any mount point of your choice. Then, copy the root contents of /tmp/root directory to the /dev/sda1 partition, i.e. cp -a /tmp/root/* /usb/sda1. NOTE: /tmp/root partition is ONLY available at the 1st boot (after the device is flashed with a new firmware, AFAIK). Be sure to create a /usb/sda1 under /usb/sda1, i.e. mkdir -p /usb/sda1/usb/sda1. On my OpenWRT SVN trunk, I have cireated the files/usb/sda1 directory so that it will be included into a newly built firmware.

4. Once the root contents have been copied to /dev/sda1 partition, do a unmount /usb/sda1 before executing a reboot. This is not necessary, but just as a precaution step to ensure the partition is cleanly unmounted before the reboot.

5. Now, you can execute reboot to shutdown and boot your device through its USB2 external partition.

6. After your device has finished booting and is ready, you can telnet into your device to check the /tmp/pivoroot.log file to see any problems.

/etc/config/fstab

cconfig mount
        option target   /usb/sda1
        option device   /dev/sda1
        option fstype   ext3
        option options  rw,sync
        option enabled  1

config swap
        option device   /dev/sdb1
        option enabled  1

/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"

#
# Improved from http://oldwiki.openwrt.org/UsbStorageHowto.html
# Switch the root filesystem to USB, if present
# DHK 7/14/09
#

#
# Modified by Mazilo 02/06/2010
#
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

/etc/init.d/e2fsck

#!/bin/sh /etc/rc.common
# Copyright (C) 2008 OpenWrt.org
# Vasilis Tsiligiannis <acinonyxs@yahoo.gr>

START=15

e2fsck() {
        local args
        local cfg="$1"

        config_get device "$cfg" device
        [ -b "$device" ] || return 0

        config_get fstype "$cfg" fstype

        case "$fstype" in
                ext2|ext3|ext4)
                        #
                        # Look for a mounted (USB) partition and dismount it
                        #
                         if grep -q $device /proc/mounts; then
                                echo "$device is mounted. No checking perfomed"
                        else
                                echo "Checking $device partition"
                                /usr/sbin/e2fsck -y "$device"
                                local status="$?"

                                case "$status" in
                                        0|1) continue;;
                                        2) reboot;;
                                        4) echo "e2fsck ($device): Uncorrected errors.";;
                                        *) echo "e2fsck ($device): Error ($status). Check not complete.";;
                                esac
                        fi;;
                *) echo "$fstype filesystem type on $device isn't supported"
                        ;;
        esac
}

start() {
        config_load fstab
        config_foreach e2fsck mount
}

/etc/init.d/pivotroot

#!/bin/sh

# From http://oldwiki.openwrt.org/UsbStorageHowto.html - DHK 7/14/09
#
# Greatly enhanced to select among (maybe) several USB Mass Storage devices
# Assumes that the root fs will be on an ext3 filesystem in partition 1,
# and looks for /flash and /jffs in the root directory. Also assumes that
# mounting and checking each candidate device is harmless. Runs e2fsck
# over partitions before mounting them; note that this causes spurious
# date-related complaints every time, since time has not been synchronized
# yet at the time pivotroot is run.
#
# Output from this script is stashed at /tmp/pivotroot.log.
#
# DHK 7/23/2009
#

#
# Modified to use switch statements by Mazilo 02/06/2010
#
echo "[`date`]: Pivot root in action"

#
# Flag is true
#
flag=1

#
# Partitions mount point
#
mp=/usb
pm=/proc/mounts

#
# Looking for available partitions on the system
#
parts=`ls /dev/sd[a-z][0-9]`

if [ -z "$parts" ]; then
        echo "[`date`]: No partitions found. Skipping pivotroot"
else
        #
        # Set Power LED flashing while we look for OpenWRT root
        #
        if [ -f /etc/diag.sh ]; then
                LED=1
                . /etc/diag.sh
                POW=`cat /proc/diag/led/power`
                set_led power f
        fi

        for part in $parts
        do
                #
                # Look for a mounted (USB) partition and dismount it
                #
                # CAUTION: Make sure your system has 'file' package
                #    installed or else the following won't be able to check
                #    the filesystem type on your USB partition and your
                #    USB partition won't get mounted.
                #
                fstype=`file -s $part | awk '{ print $5 }'`

                if grep -q $part $pm; then
                        echo "[`date`]: Umount $part ($fstype filesystem)"
                        umount $part
                fi

                #
                # Look for a partition type of a USB memory stick
                #
                disc=`echo $part|sed -e 's#[[:digit:]]##g'`
                partid=`fdisk -l $disc|awk -vP=$part '$1==P {if ( $2 == "*" ) {print $6} else {print $5}}'`

                #
                # Check/auto clean the (USB) partition
                #
                case "$partid" in
                  83)   echo "[`date`]: pivotroot checking $part"
                        e2fsck -y $part
                        flag=1;
                        status=$?;;
                  *)    echo "[`date`]: Filesystem on $part isn't supported"
                        flag=0;
                        status=99;;
                esac

                echo "[`date`]: e2fsck status is $status"

                case "$status" in
                  0|1)  echo "[`date`]: No filesystem errors and/or corrections on $part"
                        md=$mp/`basename $part`
                        [ -d $md ] || (echo "[`date`]: Creating $md directory";mkdir -p $md)
                        mount -t $fstype $part $md
                        local status=$?
                        mtype=`awk -vP="$part" '$1==P {split($4,A,","); print A[1]}' $pm`
                        echo "[`date`]: Mounting $part on $md as $mtype filesystem"

                        #
                        # Create local $md$md directory if doesn't exist
                        #
                        [ -d $md$md ] || mkdir -p $md$md

                        case "$status" in
                            0)  if [ -x $md/sbin/init -a -d $md/jffs -a -d $md$md ]
                                then
                                        echo "[`date`]: Found OpenWRT root on $part"
                                        flag=1;
                                        break;
                                else
                                        echo "[`date`]: Non-OpenWRT partition ($status)"
                                        [ -x $md/sbin/init ] || echo "[`date`]: Failed -x $md/sbin/init"
                                        [ -d $md/jffs ] || echo "[`date`]: Failed -x $md/jffs"
                                        [ -d $md$md ] || echo "[`date`]: Failed -x $md$md"
                                        echo "[`date`]: Dismount $part partition"
                                        umount $part;
                                        flag=0;
                                fi;;
                            *)  echo "[`date`]: Mount status is $status"
                                continue;;
                        esac
                        continue;;
                    2)  echo "[`date`]: Filesystem errors corrected on $part. System reboots"
                        reboot;;
                    4)  echo "[`date`]: e2fsck $part [E($status)]: Warning! Filesystem errors left ncorrected"
                        flag=0;
                        continue;;
                    8)  echo "[`date`]: e2fsck $part [E($status)]. Operational error"
                        flag=0;
                        continue;;
                   16)  echo "[`date`]: e2fsck $part [E($status)]. Usage/syntax error"
                        flag=0;
                        continue;;
                   32)  echo "[`date`]: e2fsck $part [E($status)]. Operation cancelled"
                        flag=0;
                        continue;;
                   99)  echo "[`date`]: e2fsck $part [E($status)]. Un-supported partition type"
                        flag=0;
                        continue;;
                   128) echo "[`date`]: e2fsck $part [E($status)]. Shared library error"
                        flag=0;
                        continue;;
                    *)  echo "[`date`]: e2fsck $part [E($status)]. Check not complete"
                        flag=0;
                        continue;;
                esac
        done

        #
        # if everything looks ok, do the pivot root
        #
        if [ -x $md/sbin/init -a $flag = 1 ]; then
                echo "[`date`]: Mount (move) /proc -> $md/proc"
                mount -o move /proc $md/proc
                echo "[`date`]: Pivot root $md -> $md$md"
                pivot_root $md $md$md && for ff in dev tmp jffs rom sys
                do
                        echo "[`date`]: Mount (move) $md/$ff -> /$ff"
                        mount -o move $md/$ff /$ff
                done
        fi

        #
        # Restore Power LED to previous state
        #
        [ $LED -eq 1 ] && set_led power $POW
fi

EDIT: Since I posted the above pivotroot scripts, a lot of readers here have found some bugs, i.e. truncations 1/2 by dhkauffman/denken, logical error in if statement by kunfoo, etc., and made some contributions/suggestions, i.e. checking partition type using awk by Tommie, local /usb/<part>/usb/<part> creation + correctly locating partition type field for both bootable and/or non-bootable partition by mactalla, etc., to improve the scripts. Thanks.

(Last edited by mazilo on 14 Mar 2010, 02:46)

@Mazilo

Good stuff, thanks for posting. One note: it looks like your pivotroot script has gotten truncated along the right margin.

It's good to have a working example from trunk. It looks like the differences between trunk and 8.09 that may have been tripping up @lizby and others are that that the device naming has changed, but also that devices are getting auto-mounted, which would certainly prevent e2fsck running and confuse my pivotroot. I remember having problems with automounting in White Russian, too.

dhkaufman wrote:

One note: it looks like your pivotroot script has gotten truncated along the right margin.

LOL, you are right! Thanks for pointing that out and I have now fixed those truncation along the right margin.

Thank you both!

I just did this on my router and it works much better than simply using the USB as storage that I tried earlier.  I did have to modify the pivotroot script to get it to work for me, though.  In case it matters, I've done this on a DIR-825 B1 running trunk from a week or so ago.

The changes I made:

First of all, I had to insmod the USB modules as per dhkaufman's original script with the exception that usbcore wouldn't load until I had also loaded nls_base.  Then a 10s sleep; I guess my USB drive is one of the slower ones to initialize.

So this goes early in the script (before listing the partitions):

# install needed modules for usb and the ext3 filesystem
# We could defer loading the filesystem modules until we know there's a useful partition.
# **NOTE** for usb2.0 replace "uhci" with "ehci_hcd"
# **NOTE** for ohci chipsets replace "uhci" with "usb-ohci"
# **NOTE** for WL-500gP usb-uhci not usb-ohci
echo -n "pivotroot loading kernel modules: "
for module in nls_base usbcore ehci-hcd scsi_mod sd_mod usb-storage ext2 jbd ext3 ; do {
  echo -n "$module "
  insmod $module
}; done
echo
# this may need to be higher if your disk is slow to initialize
sleep 10s

Next, for "Look for a partition type of a USB memory stick" perhaps it's a version difference or something I'm not sure, but I needed the 5th not 6th element from fdisk -l to get the partition ID (6th gives me the name "Linux" which the script didn't handle).

partid=`fdisk -l $disc|grep $part|awk '{ print $6 }'`

becomes

partid=`fdisk -l $disc|grep $part|awk '{ print $5 }'`

Next, the partition type is looked up from /proc/mounts, but this is only populated for partitions that are mounted.  At this point my USB drive is not listed.  So instead of specifying a -t type, I omit it and let me be auto-detected.  Unfortunately this mounts my ext3 partition as ext2.  I'm not sure how to correctly find the partition type before mounting.  Does yours actually show up in /proc/mounts before mounting it?

mount -t $fstype $part $md

becomes

mount $part $md

My last change was to also move /sys when pivoting.  My wireless requires that to function.

mount -o move /sys $md/sys

Gets added with the other mount -o move lines.

I'm not clear what the correct procedure is for upgrades.  To prepare for this we copied /rom to the flash drive and then built up from there.  When we upgrade, we'll flash the image to the router's storage, but then do we need to copy the new rom to our USB?  Or can we get away with just re-installing all the packages on the USB so we don't lose our config files?

mactalla wrote:

Next, the partition type is looked up from /proc/mounts, but this is only populated for partitions that are mounted.  At this point my USB drive is not listed.  So instead of specifying a -t type, I omit it and let me be auto-detected.  Unfortunately this mounts my ext3 partition as ext2.  I'm not sure how to correctly find the partition type before mounting.  Does yours actually show up in /proc/mounts before mounting it?

mount -t $fstype $part $md

becomes

mount $part $md

Update: By adding one more dependency (opkg install file) we can get the partition information directly from the block device.

mtype=`cat /proc/mounts|grep $part|awk '{ print $4 }'|cut -d, -f 1`

becomes

fstype=`file -s $part | awk '{ print $5 }'`

And the mount command remains your original one.  The echo just before it should use the fstype var instead of mtype.  It looks like mtype was meant to turn into fstype but got missed in a place or two.

My USB drive is mounted ext3 with this change.

mactalla wrote:
partid=`fdisk -l $disc|grep $part|awk '{ print $6 }'`

becomes

partid=`fdisk -l $disc|grep $part|awk '{ print $5 }'`

I only tested my scripts with the version of OpenWRT from SVN trunk which may have a newer version of fdisk utility on busybox and whose output may be different from the fdisk utility on the version of OpenWRT you use.

Next, the partition type is looked up from /proc/mounts, but this is only populated for partitions that are mounted.

You are right that the mount statement should be executed before the mtype statement. For instance, the original code is as follows:

                        mtype=`cat /proc/mounts|grep $part|awk '{ print $4 }'|cut -d, -f 1
                        [ -d $md ] || mkdir -p $md
                        echo "[`date`]: Mounting $part on $md as $mtype filesystem"
                        mount -t $fstype $part $md

And, the correct order should be:

                        [ -d $md ] || mkdir -p $md
                        mount -t $fstype $part $md
                        mtype=`cat /proc/mounts|grep $part|awk '{ print $4 }'|cut -d, -f 1
                        echo "[`date`]: Mounting $part on $md as $mtype filesystem"

This way, the mounting mode will get printed out to the /tmp/pivotroot.log file.

My last change was to also move /sys when pivoting.  My wireless requires that to function.

mount -o move /sys $md/sys

Gets added with the other mount -o move lines.

I have modified the pivotroot scripts to work with OpenWRT from SVN trunk and not from OpenWRT Kamikaze 8.09.2 trunk. Also, my WGT634U is missing a WiFi card and I have turned it into a switch with five ports. So, I wouldn't know this until you reported above. Thank you for your feedback.

mactalla wrote:

I'm not clear what the correct procedure is for upgrades.  To prepare for this we copied /rom to the flash drive and then built up from there.  When we upgrade, we'll flash the image to the router's storage, but then do we need to copy the new rom to our USB?

Oops, I forgot to address this one.

When you perform an upgrade, the process will ONLY upgrade the new firmware to the FLASH space on soldered on the device. As such, one also needs to perform the copy steps to upgrade the USB partition.

Or can we get away with just re-installing all the packages on the USB so we don't lose our config files?

If you just want to upgrade packages and not Linux OS, I don't see why not. For me who continuously checks out and compiles the latest SVN trunk, I prefer to perform an upgrade to the FLASH and then copy to the USB partition to avoid any incompatibilities, YMMV.

mazilo wrote:

Next, the partition type is looked up from /proc/mounts, but this is only populated for partitions that are mounted.

You are right that the mount statement should be executed before the mtype statement. For instance, the original code is as follows:

                        mtype=`cat /proc/mounts|grep $part|awk '{ print $4 }'|cut -d, -f 1
                        [ -d $md ] || mkdir -p $md
                        echo "[`date`]: Mounting $part on $md as $mtype filesystem"
                        mount -t $fstype $part $md

And, the correct order should be:

                        [ -d $md ] || mkdir -p $md
                        mount -t $fstype $part $md
                        mtype=`cat /proc/mounts|grep $part|awk '{ print $4 }'|cut -d, -f 1
                        echo "[`date`]: Mounting $part on $md as $mtype filesystem"

This way, the mounting mode will get printed out to the /tmp/pivotroot.log file.

How does the script then determine $fstype?  If I understand correctly, $fstype will be set if the drive was already auto-mounted and then the script notes the filesystem type before unmounting it and continuing with the analysis.  My router doesn't hit that code path, so $fstype is still the default fstype (or the previous fstype if it did actually loop over multiple partitions... oops). 

mazilo wrote:

My last change was to also move /sys when pivoting.  My wireless requires that to function.

mount -o move /sys $md/sys

Gets added with the other mount -o move lines.

I have modified the pivotroot scripts to work with OpenWRT from SVN trunk and not from OpenWRT Kamikaze 8.09.2 trunk. Also, my WGT634U is missing a WiFi card and I have turned it into a switch with five ports. So, I wouldn't know this until you reported above. Thank you for your feedback.

I'm also running SVN trunk b/c 8.09.2 doesn't have support for my router.  But I'm on a ar71xx platform and versions may change between snapshots, so it's quite possible we will hit small differences.

mazilo wrote:

When you perform an upgrade, the process will ONLY upgrade the new firmware to the FLASH space on soldered on the device. As such, one also needs to perform the copy steps to upgrade the USB partition.

Does that copy step not overwrite some of the config files that have default values in /rom?  Is it enough to make a backup of /etc/config/* and /etc/firewall.user then copy the new /rom and then restore the backed up files?

Again, thank you for your script.  It made it much easier to get this working than the wiki smile

mactalla wrote:

How does the script then determine $fstype?

At the beginning of the pivotroot scripts, I have set the default fstype=ext3. You can change this on your pivotroot file. I know this isn't a slick way to do this, but that is my limit. The BUSYBOX has a findfs utility, but I don't know how to use it. I tried findfs LABEL='WGT634U/OpenWRT' to no avail (where 'WGT634U/OpenWRT' is the label of my USB partition). I hope someone will come up with a better solution to auto detect a partition. Until then, I am pretty much content with the existing approach.

Does that copy step not overwrite some of the config files that have default values in /rom?  Is it enough to make a backup of /etc/config/* and /etc/firewall.user then copy the new /rom and then restore the backed up files?

Yes and the copy step will overwrite any existing data on the USB partition. That's why I mentioned in my post to perform a backup on the USB partition before the upgrade. For me, most of the changes I made on the USB partition are scripts files and they are updated on my local openwrt-svn-trunk/files directory. So, they will be included into the next firmware build. FYI, I always reformat my USB partition before the upgrade. For my Asterisk configurations, I manually tar the conf and astdb files, then use scp to copy the tarred files to my Linux machine.

It made it much easier to get this working than the wiki smile

Thanks to dhkauffman who provides the original pivotroot scripts file which I believe makes a USB partition booting process easier to understand and to implement.

mazilo wrote:
mactalla wrote:

How does the script then determine $fstype?

At the beginning of the pivotroot scripts, I have set the default fstype=ext3. You can change this on your pivotroot file. I know this isn't a slick way to do this, but that is my limit. The BUSYBOX has a findfs utility, but I don't know how to use it. I tried findfs LABEL='WGT634U/OpenWRT' to no avail (where 'WGT634U/OpenWRT' is the label of my USB partition). I hope someone will come up with a better solution to auto detect a partition. Until then, I am pretty much content with the existing approach.

That's what my modification here does (from my earlier post):

mactalla wrote:

fstype=`file -s $part | awk '{ print $5 }'`

'file' needs to be installed (package name is 'file')

mazilo wrote:

Does that copy step not overwrite some of the config files that have default values in /rom?  Is it enough to make a backup of /etc/config/* and /etc/firewall.user then copy the new /rom and then restore the backed up files?

Yes and the copy step will overwrite any existing data on the USB partition. That's why I mentioned in my post to perform a backup on the USB partition before the upgrade. For me, most of the changes I made on the USB partition are scripts files and they are updated on my local openwrt-svn-trunk/files directory. So, they will be included into the next firmware build. FYI, I always reformat my USB partition before the upgrade. For my Asterisk configurations, I manually tar the conf and astdb files, then use scp to copy the tarred files to my Linux machine.

I see.  I'll experiment with it when I do an update.

mazilo wrote:

It made it much easier to get this working than the wiki smile

Thanks to dhkauffman who provides the original pivotroot scripts file which I believe makes a USB partition booting process easier to understand and to implement.

Yes.  My thanks to him, as well.

Thx for scripts smile

As I can see in few codeblocks perheaps after edit there is no closing '`'

it should be

mtype=`cat /proc/mounts|grep $part|awk '{ print $4 }'|cut -d, -f 1`

not

mtype=`cat /proc/mounts|grep $part|awk '{ print $4 }'|cut -d, -f 1

BTW:I'm using DIR-825 with yesterday snapshot and mactalla's fixes were needed.

BTW2: Which package will provide set_led and /proc/diag/* ? (To be honest i don't need it but I would like to know) smile

You can shorten that to:

mtype=`awk -vP="$part" '$1==P { split($4,A,","); print A[1] }' /proc/mounts`

Its far more precise and does not require additional processes other than the awk.

(Last edited by Tommie on 11 Feb 2010, 01:50)

Tommie wrote:

You can shorten that to:

mtype=`awk -vP="$part" '$1==P { split($4,A,","); print A[1] }' /proc/mounts`

Cool and I like it! Thanks for sharing.

denken wrote:

As I can see in few codeblocks perheaps after edit there is no closing '`'

Thanks for pointing out the flaw and I fixed it now.

So far I'm a little stuck, someone could give me a hint on this?

I have done all so far from the original post, but modded it just to fit my system.
I copied /tmp/root to my /dev/sda1 mounted on /mnt/sda1
when I look at the log it fails here:

root@poseidonwrt:/# cat /tmp/pivotroot.log 
[Thu Jan  1 00:00:12 UTC 1970]: Pivot root log created.
[Thu Jan  1 00:00:12 UTC 1970]: Pivot root in action
pivotroot loading kernel modules: nls_base usbcore ehci-hcd scsi_mod sd_mod usb-storage ext2 jbd ext3 
[Thu Jan  1 00:00:28 UTC 1970]: pivotroot checking /dev/sda1
Superblock last mount time is in the future.  Fix? yes

Superblock last write time is in the future.  Fix? yes

/dev/sda1 has gone 49710 days without being checked, check forced.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information

/dev/sda1: ***** FILE SYSTEM WAS MODIFIED *****
/dev/sda1: 759/63360 files (0.1% non-contiguous), 11006/253015 blocks
[Thu Jan  1 00:00:34 UTC 1970]: e2fsck status is 0
[Thu Jan  1 00:00:34 UTC 1970]: No filesystem errors and/or corrections on /dev/sda1
[Thu Jan  1 00:00:34 UTC 1970]: Mounting /dev/sda1 on /usb/sda1 as rw filesystem
[Thu Jan  1 00:00:34 UTC 1970]: Non-OpenWRT partition (0)
[Thu Jan  1 00:00:34 UTC 1970]: Failed -x /usb/sda1/usb/sda1
[Thu Jan  1 00:00:34 UTC 1970]: Dismount /dev/sda1 partition
root@poseidonwrt:/#

Somehow the script fails on recognizing my usb installation...

Thanks in advance!

jeroenimo wrote:

So far I'm a little stuck, someone could give me a hint on this?

...
[Thu Jan  1 00:00:34 UTC 1970]: Non-OpenWRT partition (0)
[Thu Jan  1 00:00:34 UTC 1970]: Failed -x /usb/sda1/usb/sda1
...

Somehow the script fails on recognizing my usb installation...

Thanks in advance!

Add the (empty) directory "/usb/sda1" to your USB stick and try again.

mactalla wrote:

Add the (empty) directory "/usb/sda1" to your USB stick and try again.

My god, it was soooo easy!!

mactalla you are great!

So my contribution to this:

My fonera 2.0 with USB 2.0 now happily runs of a USB stick.

What I needed to do was this:

to /etc/init.d/pivotroot I added this before the partitioning listing:

# install needed modules for usb and the ext3 filesystem
# We could defer loading the filesystem modules until we know there's a useful partition.
# **NOTE** for usb2.0 replace "uhci" with "ehci_hcd"
# **NOTE** for ohci chipsets replace "uhci" with "usb-ohci"
# **NOTE** for WL-500gP usb-uhci not usb-ohci
echo -n "pivotroot loading kernel modules: "
for module in nls_base usbcore ehci-hcd scsi_mod sd_mod usb-storage ext2 jbd ext3 ; do {
  echo -n "$module "
  insmod $module
}; done
echo
# this may need to be higher if your disk is slow to initialize
sleep 10s

Also after I copied the /tmp/root/* to /mnt/sda1/ I had to mkdir -p /mnt/sda1/usb/sda1

For the rest one should just follow the thread and edit accordingly like the persons here already added to fit your system..

I have only one issue, and that is that USB seems broken after the pivot_root

Nothing mounts I can't mount a second USB stick, I'll have a look in to it when I reflash my fonera 2.0 to a newer trunk

I also have a wifi stick which I like to use as a second wireless interface, this has worked, but since the pivotroot it no longer loads the modules
I'll keep you posted

mactalla wrote:
jeroenimo wrote:

So far I'm a little stuck, someone could give me a hint on this?

...
[Thu Jan  1 00:00:34 UTC 1970]: Non-OpenWRT partition (0)
[Thu Jan  1 00:00:34 UTC 1970]: Failed -x /usb/sda1/usb/sda1
...

Somehow the script fails on recognizing my usb installation...

Thanks in advance!

Add the (empty) directory "/usb/sda1" to your USB stick and try again.

Thanks for pointing this out. I have edited to include this on my original post.

jeroenimo wrote:

I have only one issue, and that is that USB seems broken after the pivot_root

Nothing mounts I can't mount a second USB stick, I'll have a look in to it when I reflash my fonera 2.0 to a newer trunk

Once an OpenWRT partition is found and mounted, the scripts exits to perform pivot mounts. You may want to add more to the scripts to search for additional USB partitions to mount after the pivot mounts.

I also have a wifi stick which I like to use as a second wireless interface, this has worked, but since the pivotroot it no longer loads the modules

If it is a FON2100 unit, it should have a 2nd built in WiFi module. IIRC, someone on this forum had done this before to enable the 2nd WiFi module.

mazilo wrote:
jeroenimo wrote:

I have only one issue, and that is that USB seems broken after the pivot_root

Nothing mounts I can't mount a second USB stick, I'll have a look in to it when I reflash my fonera 2.0 to a newer trunk

Once an OpenWRT partition is found and mounted, the scripts exits to perform pivot mounts. You may want to add more to the scripts to search for additional USB partitions to mount after the pivot mounts.

Now that seems weird to me, why wouldn't a usb drive after pluging it in not automount? after the pivot_root the init script is run again isn't it?
I'm quite new to this all, sorry for my ignorance..

jeroenimo wrote:
mazilo wrote:

I also have a wifi stick which I like to use as a second wireless interface, this has worked, but since the pivotroot it no longer loads the modules

If it is a FON2100 unit, it should have a 2nd built in WiFi module. IIRC, someone on this forum had done this before to enable the 2nd WiFi module.

I have a Fon 2.0 which is a Fon 2200 and as far as I know only has a single atheros chipset, but you might be right, I'll do some research

jeroenimo wrote:
mazilo wrote:
jeroenimo wrote:

I have only one issue, and that is that USB seems broken after the pivot_root

Nothing mounts I can't mount a second USB stick, I'll have a look in to it when I reflash my fonera 2.0 to a newer trunk

Once an OpenWRT partition is found and mounted, the scripts exits to perform pivot mounts. You may want to add more to the scripts to search for additional USB partitions to mount after the pivot mounts.

Now that seems weird to me, why wouldn't a usb drive after pluging it in not automount? after the pivot_root the init script is run again isn't it?

As I pointed out before, pivotroot scripts doesn't have the ability to mount partitions other than the 1st encountered OpenWRT filesystem on an external USB partition. This original idea/feature suffices to my needs and is from dhkauffman's blog as excerpted below for your convenience:

excerpted from dhkauffman's blog wrote:

Since my USB sticks can move around, I search through all the available disk partitions to find one that looks like an OpenWRT system. That means I may try to mount filesystems and have them fail, but this is pretty safe. Eventually I’ll find the right filesystem, and if not I’ll boot off flash. I do assume that the filesystem will be on partition 1, and that it will be an ext3 filesystem.

If you need additional features, i.e. mount additional partitions, feel free to modify/taylor the pivoroot scripts file to your needs.

I found the problem on mounting the usb stick...

apparently the power from the usb port is not sufficient to power 2 usb sticks, I added a powered usbhub and now the usbstick mounts without any problem ;-)

This is my first posting, so first of all hello everybody! I am new to OpenWRT and this thread is exactly what I was looking for, so many thanks to the threadstarter and all the contributors. However, I think I found a bug in the pivotroot script.

if [ -x $md/sbin/init -a $flag ]; then

The test expression will always return true as long as $flag has a value, no matter if 1 or 0 (of course only if $md/sbin/init is executable). I think this was not the intention of the author. The following should work:

[ -x $md/sbin/init -a "$flag" = "1" ]

I also crippled this beautiful script to suit my own needs, as I only use 1 USB drive with one root and one swap partition. Maybe someone has use for it, so here it is:

#!/bin/sh
#
# This script is derived from the work of DHK and Mazilo
#
# Output from this script is stashed at /tmp/pivotroot.log.
#
# kunfoo 2010/02/22
#

usb_root=/dev/sda1
usb_root_type=ext2
usb_root_opts="rw,sync,noatime,nodiratime,errors=remount-ro"
mp=/mnt/usb          # mount point for usb_root
old_root=/old_root
ok=0                 # only pivot_root if everything is ok

#
# Set Power LED flashing
#
if [ -f /etc/diag.sh ]; then
   LED=1
   . /etc/diag.sh
   POW="`cat /proc/diag/led/power`"
   set_led power f
fi

#
# first make sure that all needed modules were loaded
#
for module in usbcore ehci-hcd scsi_mod sd_mod usb-storage ext2; do
   echo -n "$module "
   insmod $module
done
sleep 5s            # make sure that USB drive is initialized and ready

[ -b $usb_root ] || { echo "[`date`]: Error! USB root partition not found"; exit 1; }
[ -d $mp ] || mkdir -p $mp

#
# umount usb_root if mounted and run e2fsck on it
#
grep -q $usb_root /proc/mounts && umount $usb_root
e2fsck -y $usb_root
status=$?
echo "[`date`]: e2fsck status is $status"
case "$status" in
   0|1)  echo "[`date`]: No filesystem errors and/or corrections on $part"
         echo "[`date`]: Mounting $usb_root on $mp"
         mount -t $usb_root_type -o $usb_root_opts $usb_root $mp || { echo "[`date`]: Error $? while mounting $usb_root"; exit 1; }
         ok=1  # ready to pivot_root
         ;;
   2)    echo "[`date`]: Filesystem errors corrected on $part. System reboots"
         reboot;;
   4)    echo "[`date`]: e2fsck $part [E($status)]: Warning! Filesystem errors left uncorrected"
         ;;
   8)    echo "[`date`]: e2fsck $part [E($status)]. Operational error"
         ;;
   16)   echo "[`date`]: e2fsck $part [E($status)]. Usage/syntax error"
         ;;
   32)   echo "[`date`]: e2fsck $part [E($status)]. Operation cancelled"
         ;;
   128)  echo "[`date`]: e2fsck $part [E($status)]. Shared library error"
         ;;
   *)    echo "[`date`]: e2fsck $part [E($status)]. Check not complete"
esac

#
# if everything looks ok, do the pivot root
#
[ -d $mp$old_root ] || mkdir -p $mp$old_root
if [ -x $mp/sbin/init -a "$ok" = "1" ]; then
   echo "[`date`]: Mount (move) /proc -> $mp/proc"
   mount -o move /proc $mp/proc
   mount -o move /sys $mp/sys
   echo "[`date`]: Pivot root $mp -> $mp$old_root"
   pivot_root $mp $mp$old_root && {
      echo "[`date`]: Mount (move) $old_root/dev /dev"
      mount -o move $old_root/dev /dev
      echo "[`date`]: Mount (move) $old_root/tmp /tmp"
      mount -o move $old_root/tmp /tmp
      echo "[`date`]: Mount (move) $old_root/jffs /jffs"
      mount -o move $old_root/jffs /jffs 2>&-
      echo "[`date`]: Mount (move) $old_root/rom /rom"
      mount -o move $old_root/rom /rom 2>&-
   }
fi

#
# Restore Power LED to previous state
#
[ "$LED" = "1" ] && set_led power $POW

The discussion might have continued from here.