This howto explains how to use mini_fo filesystem to mount the USB disk over the existing root.
Original root would be used read-only and all modifications would be redirected to the USB disk
This has been tested on ASUS WL-500gp with WhiteRussian 0.9.
1. Prepare USB disk with ext3 (For more details see: http://wiki.openwrt.org/UsbStorageHowto )
2. Create file /sbin/inflate_root with following content
# Edit the variables to fit your needs:
DSK_DEV="/dev/scsi/host0/bus0/target0/lun0/part1" #Device for your disk
DSK_MOUNT="/mnt/dsk007" #Mount point for your disk
OVERLAY_DIR="${DSK_MOUNT}/root_overlay" #Directory on your disk that would be used by mini_fo to store the modified files
TMP_ROOT="/tmp/inflated_root" #Temporary directory used to mount the merged root
OLD_ROOT="/mnt/oldroot" #Where the original root would be saved
ROM=$(awk '/squashfs/ {print $2; exit;}' /proc/mounts)
JFFS=$(awk '/jffs2/ {print $2; exit;}' /proc/mounts)
[ -d "$DSK_MOUNT" ] || mkdir -p "$DSK_MOUNT" || exit 1
mount $DSK_DEV $DSK_MOUNT || exit 2
[ -d "$OVERLAY_DIR" ] || mkdir -p "$OVERLAY_DIR" || exit 3
#copy the changes from /jffs to my disk if not already done
ls $OVERLAY_DIR/*/META_* 2>/dev/null >&2 || {
cp -prd $JFFS/* "$OVERLAY_DIR"
}
[ -d "$TMP_ROOT" ] || mkdir -p "$TMP_ROOT" || exit 4
# do the overlay mount
mount -t mini_fo -o "base=$ROM,sto=$OVERLAY_DIR" "$ROM" "$TMP_ROOT" || exit 5
[ -d "${TMP_ROOT}/${OLD_ROOT}" ] || mkdir -p "${TMP_ROOT}/${OLD_ROOT}" || exit 6
# pivot root - unfortunatelly pivot_root needs to be run before init
mount -o move /proc "$TMP_ROOT/proc" && \
pivot_root "$TMP_ROOT" "${TMP_ROOT}/${OLD_ROOT}" && {
mount -o move "$OLD_ROOT/dev" /dev
mount -o move "$OLD_ROOT/tmp" /tmp
mount -o move "$OLD_ROOT/jffs" /jffs 2>&-
mount -o move "$OLD_ROOT/$DSK_DEV" "$DSK_DEV"
}
3. Make the file executable
chmod +x /sbin/inflate_root
4. Check if it is working and reboot
/sbin/inflate_root
mount
df
dd if=/dev/zero of=/test bs=1k count=128k
rm /test
reboot
5. Because the pivot_root only changes the root for current process we need to execute the script before init.
So we will prepare our own version of init ;-).
Be careful from now on - if you screw up you'll brick your router !!!
rm /sbin/init
6. Create new /sbin/init
#!/bin/sh
# Make sure we have all required modules loaded
for module in usbcore uhci scsi_mod sd_mod usb-storage jbd ext3; do {
insmod $module
}; done
sleep 4s
/sbin/inflate_root
exec /bin/busybox init
7. Make it executable
chmod +x /sbin/init
8. Cross your fingers and reboot ;-)
if you bricked the router - reflash ;-(
C.U. PeZ