Sunday, November 17, 2013

TP-Link MR3020 ExtRoot and other tips

The following is my working representation of an extroot implementation on a bleeding edge openwrt version r38886 on a mr3020 router with a 16gb flash drive running as root on a usb hub.

I have decided to use the extroot method because the bleeding edge image only leaves about a half of a megabyte of space left for packages.  And once you run out of space, there's almost no recovery option at this point because you're in a catch 22.  If you try to remove packages, it required temporary space in the overlay directory, which it doesn't have because of prior package installations used up all of that extra space.
So reimage your router and immediately do the following before installing any more packages, storage is minimal on this device.
You have 2 choices for extroot, an Overlay boot or a Root boot.  Overlay holds all of the packages kind of like an external hard drive for your router.  Root holds your entire root directory including all settings associated with the filesystem.  This is kind of unique because you could potentially have 2 completely different OS setups for your router without modifying anything, simple plug-n-play os.
For example, I use my router in my car with 2 different wifi usb adapters attached preconfigured to two different modes of adapter settings.  This means the /etc/config/network and the /etc/config/wireless files are tailored for the setup, which are a pain to begin with.  If i use the router on the go with tethering and tftp booting, reconfiguring these settings are an even bigger pain.  So you could essentially boot two different flash drives with the router configured for the two different environments with no additional configuration, as long your router is configured to boot to root.

Following these exact instructions in here http://wiki.openwrt.org/doc/howto/extroot#openwrt.12.09.attitude.adjustment

or follow my instructions below...

format a usb flash drive with 2 partitions of your choice, you can do this on the device itself but I wanted to make sure that the partitions formatted correctly so I used my ubuntu linux distro with gparted just to be safe since I know that works.
I have a 16gb sandisk flash drive model number SDCZ33-0160G-B35 partitioned to 2gb of swap as sda2 and the remainder storage of ext4 as sda1.  Be aware of where your partitions are (example: ext4 as sda1 and swap as sda2), the partition locations matter!!!

on the openwrt device ssh and install the following packages required for usb communication and storage:

opkg install block-mount kmod-usb-storage kmod-fs-ext4

then reboot
and run the following:
(the follwing lines mount the ext4 partition to a directory.  Make a temporary directory for the root or overlay filesystem.  By binding the directory you are not interfering with active memory currently running on your system.  Then on line 3, a complete duplicate of the root filesystem is made and copied to the ext4 partition of the usb flash drive which is mounted on /mnt/sda1.   Then unmounted.)
(Also, if anyone has used chroot before, the following process should look familiar)

#this is not a runnable line!: Change "mount --bind / /tmp/cproot" to "mount --bind /Overlay /tmp/cproot" for overlay copy instead of the root filesystem.#

mkdir /mnt/sda1
mount /dev/sda1 /mnt/sda1
mkdir -p /tmp/cproot
mount --bind / /tmp/cproot
tar -C /tmp/cproot -cvf - . | tar -C /mnt/sda1 -xf -
umount /tmp/cproot

Make sure your fstab looks EXACTLY as below.  Depending on your MR3020 configuration and usb flash drive, it may not settle in time for the fstab to initiate it as a root file system.  Therefore the line in this config file that needs the most attention is the one containing delay_root.  This is for an overlay extension.  If you want a root extension (also called pivot root), change the option target to '/' in config mount.

__________________________

vim /etc/config/fstab

config global

option anon_swap '1'
option anon_mount '1'
option auto_swap '1'
option auto_mount '1'
option delay_root '10'
option check_fs '0'

config mount

option device '/dev/sda1'
option target '/'
option fstype 'ext4'
option options 'rw,sync'
option enabled '1'
option enabled_fsck '0'


config swap

option device '/dev/sda2'
option enabled '1'

_____________________________

Reboot, and it should be all booted up from the flash drive like magic.  But you won't know the difference unless if you run df -h.

Luci is NOT going to work after performing a snapshot so do the following to get your web interface back up and running.  *** due to a bug as of 06/17/2014, luci-ssl is required for uhttpd to start properly
opkg update
opkg install luci
opkg install luci-ssl
/etc/init.d/uhttpd enable
/etc/init.d/uhttpd start

You may also encounter an issue where luci would not be able to find the theme that gets preinstalled with luci.  This is due to a misconfiguration with the bootstrap theme package where it does not update the luci config file in /etc/config/.  To fix, simply add the following to the end of the luci file:

config internal themes 
        option  OpenWrt '/luci-static/openwrt.org'  
        option  Bootstrap '/luci-static/bootstrap'

Since luci doesn't provide a great way for upgrading packages, here is the alternative:
opkg update
for pkg in `opkg list-upgradable | cut -d' ' -f1 | grep -v Multiple`; do opkg upgrade $pkg; done

if there is an instance where you need to get back to stock, run the mr3020 failsafe or if you have internet access and ssh/telnet access to the router (like I have needed on multiple occasions), run this (assuming you're using squashfs):

"firstboot" (this is like a fresh install of OpenWrt)

or

cd /tmp
wget http://downloads.openwrt.org/attitude_adjustment/12.09/ar71xx/generic/openwrt-ar71xx-generic-tl-mr3020-v1-squashfs-factory.bin
mtd -r write openwrt-ar71xx-generic-tl-mr3020-v1-squashfs-factory.bin firmware
(this completely reflashes the router using the supplied bin file)

3 comments:

  1. root@ASKYLab:~# df -h
    Filesystem Size Used Available Use% Mounted on
    rootfs 28.8M 7.1M 21.7M 25% /
    /dev/root 1.8M 1.8M 0 100% /rom
    tmpfs 61.7M 60.0K 61.7M 0% /tmp
    /dev/mtdblock8 28.8M 7.1M 21.7M 25% /overlay
    overlayfs:/overlay 28.8M 7.1M 21.7M 25% /
    tmpfs 512.0K 0 512.0K 0% /dev
    /dev/sdb1 6.8G 32.6M 6.4G 0% /mnt/sdb1
    root@ASKYLab:~#

    ReplyDelete
    Replies
    1. I used Buffalo WZR-HP-AG300H,but I can't boot from sdb1 ~
      Could help me to how to troubleshooting it ? Tks ~

      config 'swap'
      option device '/dev/sdb5'
      option enabled '1'

      config 'mount'
      option target '/mnt'
      option device '/dev/sdb1'
      #option uuid '3b3d1be5-99ff-4962-9142-995aae522c0a'
      option fstype 'ext4'
      option options 'rw,sync'
      option enabled '1'
      option enabled_fsck '0'
      option is_rootfs '0'

      Delete
    2. Hi there!
      Could you display your entire /etc/config/fstab file? or is that the whole file?

      Delete