There will come a time when, after some amount messing around with OpenWRT, you will run out of storage, and won't be able to install any more packages or even create any more files. At this point you can consider upgrading to a router with a bigger flash memory, but if the router is otherwise working fine, and has a USB port, why not use a USB Flash Disk as your storage instead? Here are the steps to set up a USB Flash Disk as OpenWRT storage.

I did this on my TP-Link 1043ND V2, with a USB2 sandisk cruzer fit 8GB plugged into the USB port.

Backup Your Current Settings
  • You'll want this if you screw up. Particularly if this is your internet router, and you've put in effort to get it working.
  • The easiest way to do a backup is System -> Backup -> Generate Archive. This appears to be a backup of the most package subfolders in /etc folder.
  • Note that there can be other stuff that needs backing up, especially if you created them outside of packages. For extra safety, I also did a:
    • ssh root@router "tar czf - /etc /usr/local /root " | cat - > backup-etc.usr_local.root-2017-12-16.tar.gz
  • This backup probably can't be restored via Luci, but will be useful if you've somehow lost everything and need to set things up from scratch.

Reset Your Router
  • If you've got lots of space left in your existing onboard flash, this is probably not necessary. In my case, I was down to around 500k free space, so I thought it would be a good exercise to reset the router back to openWRT factory settings. This would also be a good chance to confirm I've documented my setup steps properly.
  • Configure your router for internet access. At least this fills up your original overlay file system with the bare minimum to get internet access.

Configure for Pivot Overlay

  • Execute the following:
    • opkg update
    • opkg install kmod-usb-storage-extras
    • opkg install kmod-fs-ext4
    • opkg install block-mount
    • opkg install fdisk
    • opkg install e2fsprogs
  • Insert the flash disk into the router's USB port.
  • Partition the flash disk. I had 8GB, so created a 2gb and 5.5gb partition using fdisk:
Disk /dev/sda: 7.5 GiB, 8002732032 bytes, 15630336 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xd4014153

Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 4196351 4194304 2G 83 Linux
/dev/sda2 4196352 15630335 11433984 5.5G 83 Linux
  • Format the flash disk. Execute the following:
    • mkfs.ext4 -O ^has_journal /dev/sda1
    • mkfs.ext4 -O ^has_journal /dev/sda2
  • Create mount point for /data
    • mkdir /data
  • Copy the existing /overlay to the /dev/sda1
    • mount /dev/sda1 /mnt ; tar -C /overlay -cvf - . | tar -C /mnt -xf - ; umount /mnt
  • Redetect USB partitions:
    • block detect > /etc/config/fstab
  • Configure /etc/config/fstab to mount /dev/sda1 as /overlay
    • sed -i s/option$'\t'enabled$'\t'\'0\'/option$'\t'enabled$'\t'\'1\'/ /etc/config/fstab
    • sed -i s#/mnt/sda1#/overlay# /etc/config/fstab
  • Configure /etc/config/fstab to mount /dev/sda2 as /data
    • sed -i s#/mnt/sda2#/data# /etc/config/fstab
  • reboot the router

... and we're done! Log into to the router, and "df -h" should now show a massive amount of storage for / and /data:

root@Router:~# df -h
Filesystem Size Used Available Use% Mounted on
rootfs 2.0G 5.3M 1.8G 0% /
/dev/root 2.3M 2.3M 0 100% /rom
tmpfs 29.8M 68.0K 29.8M 0% /tmp
/dev/sda1 2.0G 5.3M 1.8G 0% /overlay
overlayfs:/overlay 2.0G 5.3M 1.8G 0% /
tmpfs 512.0K 0 512.0K 0% /dev
/dev/sda2 5.4G 10.9M 5.1G 0% /data

  • You don't strictly have to create 2 partitions, you could use the whole flash disk as your /overlay if you like.
  • I'm not actually quite sure what happens if you were to reset the system after this ... my guess is that OpenWRT would remove the /overlay which is on the USB flash disk. But the config on the /overlay on the built-in flash would then have stuff that is not in USB /overlay. To be safe, it's probably better to remove the USB flash disk and reset and reformat and repeat the above steps from scratch if you're planning to revert the system.