OpenWrt devices such, routers to be specific, are low on storage and this limit the capabilities of the devices. For a OS as powerful as OpenWrt, with thousands of packages, having a low storage device is a disadvantage.
Armed with a spare micro SD card, I wanted to experiment adding more storage to my OpenWrt router. OpenWrt is different from desktop oriented Linux distribution where you just plug a USB drive or SD card and start playing with it. OpenWrt requires manual interaction and if you have mounted an external drive to a server, the step are similar.
First you will need to have the drive formatted and partitioned using a laptop or desktop. I have mine formatted to an ext4 file system and into one partition.
Now access your router via SSH and run the following commands in order to have the required packages.
opkg update && opkg install block-mount e2fsprogs kmod-fs-ext4 kmod-usb-storage kmod-usb2 kmod-usb3
You can omit the kmod-usb3 package if your router don’t support USB3 or else it will spit out errors.
Lets find out what is at /dev/sd* by running ls -al /dev/sd*. The output may be empty if there is no drive attached. Follow this by inserting your drive into the router and execute ls -al /dev/sd* again. This time the output should be something similar to this:
root@router:~# ls -al /dev/sd*
brw------- 1 root root 8, 0 Jan 1 1970 /dev/sda
brw------- 1 root root 8, 1 Jan 1 1970 /dev/sda1
Where /dev/sda is the first drive attached and /dev/sda1 is the first partition of the first drive attached.
The next step is creating an ext4 file system on the drive by running mkfs.ext4 /dev/sda1. Make sure you choose the right drive as picking the wrong one will wipe whatever is on it. Then create an fstab config file with block detect | uci import fstab. Now you can update the /etc/config/fstab file so that your block devices are mounted when your router restart. The command is:
uci set fstab.@mount[0].enabled='1' && uci set fstab.@global[0].anon_mount='1' && uci commit fstab
And finally, run /etc/init.d/fstab boot to auto mount the drives at boot.
With these few steps we have expand the OpenWrt router with more spaces. You can confirm it with df -h /mnt/sdcard/ and your output should be similar to this:
Filesystem Size Used Available Use% Mounted on
/dev/sda1 116.8G 60.0M 110.7G 0% /mnt/sdcard
Being low powered and online 24 hours with plenty of space, I am looking for more fun stuff to add to my OpenWrt router.