How to setup OpenWrt extroot, rootfs on USB storage

Here I’m going to share my experience with OpenWrt extroot on a TP-Link MR-3220 v2.4 router.

Though I did this on a MR-3220, this guide also applies to other routers like TP-Link WR703N, MR3020, D-Link DIR-505 etc etc. Just make sure you have downloaded the correct firmware for your router.

Probably you know all about it’s hardware specifications, here is a short recap again

  • AR9331-AL3A 400MHz SoC
  • 32 MB DDR RAM chip
  • 4 MB SPI NOR flash memory
  • One 10/100M ethernet WAN port
  • Four 10/100M ethernet switches
  • 150Mbps b/g/n Wi-Fi
  • One USB 2.0 port

Little about MR 3220 v2.4 hardware quality, I teared it apart within 1 hour of receiving, the hardware quality is average with average quality components.

Enough hardware introduction, lets start the main topic, installing OpneWrt and configuring extroot on a USB pendrive. OpwnWrt firmware installation is very easy through the web interface and openwrt extroot part is same for almost any other router too.

 

Which OpenWrt firmware version should I choose ?

This is one of the most important question, choosing the correct OpenWrt version is absolutely crucial. This router works perfectly with the latest OpenWrt trunk (Designated Driver), stable 15.05, 14.07 or 12.09 .

But OpenWrt is bloating day by day while limited NOR flash storage is not, the stable firmware is also bloated with LUCI web interface. The free JFFS2 space after installing OpenWrt is decreasing too. So you can’t install more than a few package with this limited space, that’s when putting extra files on a external drive is necessary.

After about 12-14 hour  experiment with various OpenWrt versions, I figured out that only OpenWrt 14.07 (Barrier Breaker) or earlier versions have the right amount of free JFFS2 space to install required bare minimal minimal packages to setup an extroot.

 

Which filesystem should I use for extroot ?

Another very important question, the official OpenWrt extroot guide says that you could any UNIX-like filesystem of your choice, forget about FAT32 or NTFS. But the reality is extroot is only and only possible with ext4/ext3 or ext2 filesystem. I tested with almost every slim (I mean which equips less NOR flash space) filesystem

  1. minix, not supported
  2. HFS, not supported
  3. HFS+, not supported
  4. JFS, not supported
  5. XFS, not sopported
  6. reiserfs, not supported

There are other UNIX-like filesystems like BTRFS, LVM2 PV , UFS etc. but none of them will fit in the 288 KB free JFFS2 space, so I didn’t tested them.

So the final choice is for a router with 4MB flash, choose only OpenWrt 14.07 or earlier and ext4 as extroot filesystem.

Request to OpenWrt pro users, if you had ever setup chroot with any other filesystem except ext4/ext3/ext2, please mention.

 

Installing OpenWrt on TP-Link MR3220

Assuming you have a PC running a Linux distribution, this is required for flashing the firmware and

Download the OpenWrt 14.07 firmware from here .

 wget -c https://downloads.openwrt.org/barrier_breaker/14.07/ar71xx/generic/openwrt-ar71xx-generic-tl-mr3220-v2-squashfs-factory.bin

WARNING: Do it at your own risk, event with great precautions there is a chance of bricking the router. If possible connect the router to an UPS before flashing it.

  1. Power on the router and connect a PC through a ethernet straight cable (patch cord) to one of four the LAN ports(the yellow ones).
  2. Open up a browser and go to this address; 192.168.0.1 to access the web interface and login. Username: admin Password: admin .
  3. Go to the System Tools > Firmware Upgrade choose the previously downloaded OpenWrt firmware with the Browse button and Hit the Upgrade button.
  4. Wait for few minutes to let the flashing complete and automatic reboot.

Installation is complete now your PC will automatically receive a different IP via DHCP.

 

Initial OpenWrt setup

For first time we have to use telnet to login into OpenWrt,

 telnet 192.168.1.1 

or if you don’t have telnet try this

 busybox telnet 192.168.1.1 

after login, change the password to enable ssh

 passwd root 

now exit from the telnet session with exit command and re-login with SSH,

 ssh [email protected] 

 

Installing necessary packages

At this step the router must be connected to the internet, you could use your existing DSL/cable internet for this purpose or share an existing connection from your PC. I personally did it by sharing my 3G connection with Network-Manager from my laptop.

Make sure that the router could connect to the internet

 ping -c 4 8.8.8.8 

Update opkg package repository

 opkg update 

Install necessary packages to support USB storage device

 opkg install kmod-usb-storage kmod-scsi-core block-mount 

Install ext4 filesystem kernel module

 opkg install kmod-fs-ext4 

That’s all, check free flash space with df -h , do not install anything more ! if you try to do so, any packages larger than 10KB will return no space left on device error.

OpenWrt df command

Now load all necessary kernel modules with modprobe command

modprobe sd_mod
modprobe usb-storage
modprobe ext4

or simply reboot the device with reboot command.

 

Partitioning the USB drive

Lets partition the USB drive, another question, how much space should I use for extroot partition ? Just 100-200 MB is more than enough, I allocated a 200 MB ext4 partition for extroot, you could use more if you wish.  I used Gparted for partitioning a 4 GB USB drive.

OpenWrt extroot disk partitioningNow safely remove the USB drive and plug it in the routers USB port.

 

Configuring the OpenWrt extroot

After plugging the USB drive, it should show up as a storage device under the /dev directory as /dev/sda1 , /dev/sda2 etc. Simply go through the commands bellow

Mount the USB drive, change /dev/sda2 according to yours

 mount /dev/sda2 /mnt 

Copy data from /overlay partition to the USB drive

 tar -C /overlay/ -c . -f - | tar -C /mnt/ -xf - 

Un-mount the USB drive

 sync && umount /dev/sda2 

Configure /etc/config/fstab to mount the USB drive as /overlay partition

 block detect > /etc/config/fstab 

Now edit the /etc/config/fstab with vi to mount the etxt4 partition (/dev/sda2) at /overlay partition at startup,

vi /etc/config/fstab 

have a look on a sample fstab configuration,

config 'global'
       option  anon_swap       '0'
       option  anon_mount      '0'
       option  auto_swap       '1'
       option  auto_mount      '1'
       option  delay_root      '5'
       option  check_fs        '0'

config 'mount'
       option  target  '/overlay'
       option  uuid    '7669178c-3f77-4fb1-b421-6ec6f61be672'
       option  enabled '1'

Set the target to /overlay, and change the option enabled line from 0 to 1 . Now enable the fstab service at startup

 /etc/init.d/fstab enable 

and check it

 readlink -f /etc/rc.d/*fstab 

reboot the router with the reboot command

 reboot 

 

Check if the extroot is working or not

After the reboot is complete login to the router with ssh again and check the free disk space with df and mount command.

df -h

mount

The df commnd should return a lot of free space available at rootfs, that means extroot is working fine.

OpwnWrt extroot free spaceNow check it again by installing some big packages, example >

 opkg install e2fsprogs 

 

I hope this simple beginner friendly tutorial will help you to start your experiment with OpenWrt. If you have any question or suggestion, just leave a comment and don’t forget to share this with your friends 🙂 .

57 Responses

  1. Kklimo says:

    Hey do you know how to return it back from previous version?

  2. Khorshed Alam says:

    Hi Arnab,
    I am actually using my 4G wimax modem with MR3020 router. I also have 2TB USB HDD. After installing openwrt can I use both (HDD+4G modem) at the same time using a USB hub?

    Thanks,
    Khorshed

    • Arnab says:

      It may work or may not, depends on the USB hub, cable length and some other unknown parameters.
      In my case, the exact setup like your with a 500GB HDD and 3G modem(Micromax brand)) failed to work, while a CDMA modem(MTS, ZTE AC2766) worked perfectly.

  3. Veerendra says:

    Hi Arnab,
    I tried to follow your instructions to install OpenWRT on my router. firmware upgrade is successful. However I am struck with mounting the partition for copying overlay files. getting error while using mount command:

    [email protected]:~# mount /dev/sda1 /mnt
    mount: mounting /dev/sda1 on /mnt failed: No such file or directory

    The USB device is detected as sdb-> sdb1,sdb2
    sdb1 is the partition I had prepared for extroot with ext4 file system. I had tried both gparted and fdisk utilities.

    Request direct me. Thanks in advance.

    • Arnab says:

      Hi, thanks for feedback.
      Perhaps yo’re missing the proper drivers for ext4 partition.
      Try with a ext2 formatted partition.
      What’s the output of the dmesg command just after running the mount /dev/sda1 /mnt command ?
      Missing kernel drivers could be located from this log.

  4. Derper says:

    Hi,

    I got everything running.
    But is seems that some packages that I need are only supported with 15.X
    is it possible to upgrade to Chaos Calmer or will it just delete all configurations for extroot?

  5. Saadat says:

    Hello Arnab,
    After installing extroot, can I upgrade OpenWRT to CC, keeping extroot intact? Thanks.

    • Arnab says:

      Unfortunately you can’t !
      The upgrading process through sysupgrade works in a odd way, it creates a backup configuration file via UCI and restores that after finishing. Another point to remember, each OpenWrt major release are quite different.

Leave a Reply

Your email address will not be published. Required fields are marked *