How to Add a USB drive or a SD card as Overlay

When you want to install the Openwrt packages and find our router does not have enough flash memory, you can mount a USB drive or SD card as an external disk to install those packages onto it, like AdGuard Home.

Example with GL-MT1300

Connect your router to the internet, use SSH to login the Openwrt and run below:

root@GL-MT1300:~# opkg update

root@GL-MT1300:~# opkg install block-mount kmod-usb-storage kmod-fs-ext4 e2fsprogs

Check the mount point and format your USB/SD and, for example, /dev/sda1:
root@GL-MT1300:~# ls /dev/sd* (if you are using SD card, it should be ls /dev/mmcblk0*)
root@GL-MT1300:~# mkfs.ext4 /dev/sda1 << EOF

Y
EOF

overlay3

Create the root for USB/SD
root@GL-MT1300:~# mount -t ext4 /dev/sda1 /mnt
root@GL-MT1300:~# mkdir /tmp/root
root@GL-MT1300:~# mount -o bind / /tmp/root
root@GL-MT1300:~# cp /tmp/root/* /mnt -a
root@GL-MT1300:~# umount /tmp/root
root@GL-MT1300:~# umount /mnt

overlay4

Set auto mount and restart your router
root@GL-MT1300:~# block detect > /etc/config/fstab
root@GL-MT1300:~# uci set fstab.@mount[0].target='/overlay'
root@GL-MT1300:~# uci set fstab.@mount[0].enabled='1'
root@GL-MT1300:~# uci commit fstab
root@GL-MT1300:~# reboot

After reboot, please check if the USB/SD is mounted normally.
For example, if you mounted an 8G USB, you will see the return like this

root@GL-MT1300:~# df -h
overlay5

If you upgrade or factory reset your router, you need to do it once again.

3 Likes

I'm looking at this, and it's similar tohttps://forum.gl-inet.com/t/extroot-configuration/27421 and [OpenWrt Wiki] Extroot configuration, although those seem to do most of the work with uci, and there are minor differences (fstab vs fstab.rwm for one).

This one seems to be newer, so is it the current/best way?

And when it says "If you upgrade, you need to do it once again", does that mean that I have to do this every time I get an update on the device?

Thanks!

I've got the AX1800 "Slate", with the latest firmware.

Well, it works, anyway, whether or not it is the best way.