Wednesday, December 16, 2015

OpenWrt 15.05 Chaos Calmer on TL MR3020 with rootfs on external usb drive

The latest version of OpenWrt is quite bulky. Although it feats neatly within TL-MR3020's 4MB flash, doesn't leave enough space to install the modules required to shift the root file system to an external drive.

My TL-MR3020 with FT232RL board to access its serial console
and a USB hub with a flash drive in one of its slots.

In previous versions of OpenWRT, you had 840KB of space left on internal 4MB flash to install the essential kernel modules for usb, usb mass storage and ext4 which are all essential for mounting USB flash drive. My Weather Station used TL-MR3020 flashed with OpenWrt 12.09 and used this methods.
In the latest version just about a few hundred kilobytes are left after flashing the image which aren't enough to install the modules required for mounting USB flash drives. So we have to resort to the following steps:

  1. Open up your TL-MR3020 and solder in a USB-UART (FT232RL) board to gain access to its serial port.
  2. Install the toolchain for compiling OpenWRT on your 64-bit Ubuntu Laptop
  3. Compile OpenWrt for TL-MR3020 on your ubuntu laptop. While doing so, we will include the modules required for mounting flash drives and leave out the bulky modules like LuCI web interface that can be installed later on the rootfs which has been relocated to USB flash drive)
  4. Connect your TL-MR3020 to your laptop using Ethernet cable and flash the newly compiled image
  5. Disconnect the ethernet cable between TL-MR3020 and your laptop and connect a USB cable to the soldered USB-UART board to gain access to TL-MR3020's Serial console
  6. Issue commands to TL-MR3020 using PuTTY over Serial and configure it to connect to your WiFi router as client.
  7. Issue commands to TL-MR3020 using PuTTY (over serial or over WiFi) and configure it to mount external USB flash drive as rootfs.
  8. Issue commands to TL-MR3020 using PuTTY (over serial or over WiFi) and configure it to install LuCI and other essential modules that had been left behind when you compiled the image for OpenWrt.
  9. Done. Now you can access your router using your browser as well.

  1. Open up your TL-MR3020 and solder in a USB-UART (FT232RL) board to gain access to its serial port. To do this refer to this image for the pin out. (You only need access to TX, RX and GND):
    Note the location of RX, TX and GND.
    Connect this to a SparkFun FTDI Basic Breakout - 3.3V Board
    Make sure to use only the 3.3V FTDI board
    Make sure you connect TX on TL-MR3020 to RX on FT232RL and
    RX on TL-MR3020 to TX on FT232RL.
    GND on MR3020 will connect to GND on FT232RL
  2. Install the OpenWrt toolchain on your 64-bit Ubuntu laptop.
    Instructions to do this are in my blog post here. The blog post covers how to install toolchain for Attitude Adjustment - a previous version of OpenWrt. In the current case we need to perform this process for the latest version - Chaos Calmer. So please replace all the URLs that point to tools for Attitude Adjustment to that of Chaos Calmer. The respective URLs for Chaos Calmer are at the end of the blog post.
  3. Compile OpenWrt for TL-MR3020 on your ubuntu laptop:
    1. Download to your 64-bit Ubuntu box
    2. Extract the archive:
      bzcat OpenWrt-ImageBuilder-15.05-ar71xx-generic.Linux-x86_64.tar.bz2  | tar -xvf -
    3. Go into the folder and run:
      make image PROFILE=TLMR3020 PACKAGES="blkid block-mount kmod-fs-ext4 kmod-usb2 kmod-usb-uhci kmod-usb-ohci kmod-usb-storage"
  4. Connect Router to laptop using LAN cable. (If you have a new router, use web console to first flash a generic OpenWRT image of some previous version which is known to work fine. Look here on how to do that. Once that is done, use the OpenWrt webpage to flash the new custom compiled image.) Flash the following image using OpenWrt's web console  ~/OpenWrt-ImageBuilder-15.05-ar71xx-generic.Linux-x86_64/bin/ar71xx/openwrt-15.05-ar71xx-generic-tl-mr3020-v1-squashfs-factory.bin
  5. Disconnect the ethernet cable and connect to your router using a USB cable from your laptop to FT232RL board that you soldered to your TL-MR3020. Now use PuTTY or minicom to gain access to console on your router. Look here on how to configure your router to connect to your home WiFi as a client.
  6. Once the router has successfully connected to your home WiFi, you can either continue using serial console or use PutTTY or SSH over WiFi. Issue commands to the router and mount the external flash drive and shift the rootfs to it:
    1. We need to check the path where MR3020 has mounted the flash drive. Execute the command
      ls /dev/sd*
      to know the path. In my case this was /dev/sdb1. In your case it could be /dev/sda1. Use this path in the following steps wherever required.
    2. The remaining steps required to move the rootfs to the flash drive have been taken from this page here. Mount the USB stick and copy the flash /overlay to the USB stick by executing the following four commands in succession:
      1. mkdir -p /mnt/usb
      2. mount /dev/sdb1 /mnt/usb
      3. tar -C /overlay -cvf - . | tar -C /mnt/usb -xvf -
      4. vi /etc/config/fstab
      5. The last of the above four commands will open a text editor. Press I to insert and modify the file. The should look like this:
        config 'mount'
                option target   /overlay
                option device   /dev/sdb1
                option fstype   ext4
                option options  rw,sync
                option enabled  1
                option enabled_fsck 0
      6. After editing the file press Escape on your keyboard followed by colon (:) and then type "wq!" and press Enter to save the file.
        Reboot the router and check if you have gained the extra space of the USB flash drive using the command df -h
         _______                     ________        __
        |       |.-----.-----.-----.|  |  |  |.----.|  |_
        |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
        |_______||   __|_____|__|__||________||__|  |____|
                  |__| W I R E L E S S   F R E E D O M
        CHAOS CALMER (15.05, r46767)
          * 1 1/2 oz Gin            Shake with a glassful
          * 1/4 oz Triple Sec       of broken ice and pour
          * 3/4 oz Lime Juice       unstrained into a goblet.
          * 1 1/2 oz Orange Juice
          * 1 tsp. Grenadine Syrup
        root@OpenWrt:/# df -h
        Filesystem                Size      Used Available Use% Mounted on
        rootfs                    7.2G     17.0M     
        6.8G   0% /
        /dev/root                 2.3M      2.3M         0 100% /rom
        tmpfs                    14.0M     72.0K     14.0M   1% /tmp
        /dev/sdb1                 7.2G     17.0M      6.8G   0% /overlay
        overlayfs:/overlay        7.2G     17.0M      6.8G   0% /
        tmpfs                   512.0K         0    512.0K   0% /dev
  7. Next install the packages which we had left out while compiling OpenWrt. Make sure your TL-MR3020 is connected to home WiFi and therefore the internet and issue these commands to it over PuTTY/SSH:

    opkg update
    opkg install luci
    opkg install kmod-usb-serial-ftdi kmod-usb-acm kmod-usb-serial curl coreutils-stty usbutils bash nano grep getopt ip-full 

    This will install LuCI the web interface as well as few other useful utilities for your IoT projects.
  8. Use web browser to visit from your laptop (use a LAN cable connected between your laptop and TL-MR3020 and your laptop's WiFi must be off)
    Configure whatever your TL-MR3020's settings to whatever you want to.


ram kumar said...

Hi, I followed the same step and built and flashed, sda1 is showing when I list but when I try to mount Im getting following error, please help

root@OpenWrt:~# mount /dev/sda1 /mnt/usb
mount: mounting /dev/sda1 on /mnt/usb failed: Invalid argument

ram kumar said...


Worked after these steps
opkg install kmod-usb-storage block-mount block-hotplug kmod-fs-ext4 kmod-fs-vfat kmod-nls-cp437 kmod-nls-iso8859-1
mkdir -p /mnt/usb
mount -t vfat /dev/sda1 /mnt/usb

Thanks a lot, love your blog and work

Anurag Chugh said...

@ram kumar,

Thanks for the compliments! Alos, many thanks for the update as well, I have been playing around and blogging about OpenWrt for quite sometime now. I always used to wonder if developers/hobbyist found my blog useful. Comments and updates from readers like you help keep me motivated to keep blogging about what I do. Thank you again.

Dr.crazy said...

Very Good.

Post a Comment