I have not been able to get pivotroot to work on my WL-520gU at the point where dhkaufman put it (before "LOGGER=" in /etc/init.d/rcS). With the serial cable, I can see that it is putting out messages to just the point before where it says "Please press enter to activate this console". The boot process doesn't complete and the only way out is to reflash.
So I have tried to combine dhkaufman's code with the process used by forest_gump, putting the pivot root into /etc/init.d/done, after everything else has been done. This appears to do the pivotroot, but with the caveats mentioned in the thread.
The packages installed are kmod-usb-core kmod-usb-storage kmod-usb2 kmod-fs-ext2 kmod-fs-ext3 kmod-usb-ohci e2fsprogs. openssh-sftp-server is not required but is small and makes it easier to copy files to the router.
I have mounted the usb drive, formatted as ext3, on a directory named "usb". Here is the code I used to format the drive and copy the internal flash to it (assuming that the drive is /dev/sda1 and partitioned as linux).
umount /dev/sda1
mkfs.ext3 /dev/sda1
mkdir -p /tmp/root
mount -o bind /rom /tmp/root
mount /dev/sda1 /usb
cp /tmp/root/* /usb -a
sync
echo "This is usb drive /dev/sda1 to be mounted on /usb" > /usb/sda1.dsk
umount /tmp/root
umount /usb
Here is df output with no usb drive plugged in:
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/root 1920 1920 0 100% /rom
tmpfs 6784 32 6752 0% /tmp
tmpfs 512 4 508 1% /dev
/dev/mtdblock3 1152 204 948 18% /jffs
mini_fo:/jffs 1920 1920 0 100% /
I put the call to pivotroot into /etc/init.d/done (and enabled it)
START=95
boot() {
[ -d /tmp/root ] && {
lock /tmp/.switch2jffs
firstboot switch2jffs
lock -u /tmp/.switch2jffs
}
# process user commands
[ -f /etc/rc.local ] && {
sh /etc/rc.local
}
# pivotroot to usb, if available -- added
/etc/init.d/pivotroot
# set leds to normal state
. /etc/diag.sh
set_state done
}
Here is my pivotroot code:
# using some of dhkaufman's code from
# https://forum.openwrt.org/viewtopic.php?id=21377
# look for usb drive as /dev/sda1; if found, unmount, e2fsck, if no error, boot
DRIVE=`ls /dev/sda1`
if [ -z $DRIVE ]; then
echo No partitions, skipping pivotroot
else
umount $DRIVE
e2fsck -p $DRIVE
fsstat=$?
echo e2fsck status is $fsstat
if [ $fsstat -eq 2 ]; then
echo Corrected errors on $DRIVE, need to reboot
sleep 5
reboot
elif [ $fsstat -eq 1 ]; then
echo Corrected errors on $DRIVE
elif [ $fsstat -gt 2 ]; then
echo No usable filesystem on $DRIVE
fi
echo Mounting $DRIVE
mount -t ext3 $DRIVE /usb
mt=$?
if [ $mt -eq 0 ]; then
if [ -x /usb/sbin/init -a -d /usb/jffs -a -d /usb/usb ]; then
echo Found OpenWRT root on $DRIVE
# Side-effect - leave /usb mounted
else
echo "Missing /sbin/init, /jffs, or /usb (mount status was $mt)"
[ -x /usb/sbin/init ] || echo Failed -x /sbin/init
[ -d /usb/usb ] || echo Failed -x /usb
[ -d /usb/jffs ] || echo Failed -x /jffs
umount $DRIVE
fi
else
echo mount status is $mt
fi
fi
#if everything looks ok, do the pivot root
[ -x /usb/sbin/init ] && {
mount -o move /proc /usb/proc && \
pivot_root /usb /usb/usb && {
mount -o move /usb/dev /dev
mount -o move /usb/tmp /tmp
mount -o move /usb/jffs2 /jffs2 2>&-
mount -o move /usb/sys /sys 2>&-
}
}
Here is the output from df when the device is booted with the usb drive in:
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/root 1920 1920 0 100% /usb/rom
tmpfs 6784 32 6752 0% /tmp
tmpfs 512 0 512 0% /dev
/dev/mtdblock3 1152 208 944 18% /usb/jffs
mini_fo:/jffs 1920 1920 0 100% /usb
/dev/sda1 1924720 42988 1783960 2% /
Is anything evidently wrong with this?
A couple of problems. I would be stuck on this process as implemented without the serial cable. When I tried to log in, I kept getting "Access denied". Using the serial console, I ran "passwd" and set it to the same thing that I used for the device without the usb drive. Then I could get in with the normal ssh client (putty, in my instance). What causes this and how can it be avoided so that this process could be followed by someone without a serial cable?
Second problem: the date isn't correct. ntpclient is running with the correct paramaters, but the date is wrong--based on Unix zero date. How can this be fixed?
root@wl63:~# date
Wed Dec 31 19:10:30 EST 1969
root@wl63:~# ps | grep ntpclient
754 root 832 S /usr/sbin/ntpclient -i 600 -s -l -D -p 123 -h 0.openw
New packages are going to the usb drive. I did "opkg update" and "opkg install nano", and could use nano. After rebooting without the usb drive, I couldn't use nano, which is good because that indicates that it wasn't installed to the internal flash.
So, this method is close, but not perfect. Any suggestions would be appreciated.