Home » Networking » OpenWrt » Openwrt External Usb Storage

How to Add Extra External USB Storage to an OpenWrt Device

This tutorial will document steps you need to take to add USB storage to your OpenWrt router. These steps are tested on OpenWrt 21.02 in 2022.

These steps were tested on a BT HomeHub 5 which was modified to run OpenWrt. These devices come with 128MB of storage – enough for OpenWrt and software, but not really enough for hosting file shares.

Picking a USB Storage Device

Most routers running OpenWrt will not be able to supply enough power to spin a mechanical hard disk. Avoid portable hard drives without their own power supplies or stick to USB sticks with flash memory.

If you are running OpenWrt on a Raspberry Pi, you should be able to get away with one, but any more may run into power limitations as well.

If you already have portable drives which lack their own power supplies, an externally powered USB hub can be used to ensure enough juice is supplied.

Configuring External USB Storage in OpenWrt

1: Install Dependencies in OpenWrt

SSH into your OpenWrt Box and run the following command to install of of the dependencies required to mount and format your usb disk:

opkg update && opkg install block-mount e2fsprogs kmod-fs-ext4 kmod-usb-storage kmod-usb2 kmod-usb3

2: Identify USB Storage

Warning: The following steps will delete all data on the USB storage device.

Ensure your usb storage device is unplugged.

List all attached USB storage devices (with the device you’re adding still unplugged) by running:

ls -al /dev/sd*

The list of current USB storage devices will be listed (or nothing will be displayed if there is no existing USB storage). Be aware that some internal USB storage may show as USB storage. If populated, the list will look something like this:

root@OpenWrt:~# ls -al /dev/sd*
brw-------    1 root     root        8,   0 Feb  4 15:13 /dev/sda
brw-------    1 root     root        8,   1 Feb  4 14:06 /dev/sda1

Note that there are two entries per device – we’ll be interested in the one that ends with a number.

Plug in your USB storage device and wait a few seconds for it to be detected.

Then, run:

ls -al /dev/sd*

…again. The new device will be shown in the list of USB storage devices – and you’ll know exactly which one of those devices is the new one, as it won’t have been shown in the initial list while the device was unplugged. Make a note of the name of the new storage device, it will be something like:

/dev/sda1

3: Format USB Storage

Format the device by running:

mkfs.ext4 /dev/sda1

Make sure you replace ‘sda1’ with the name of the device as identified in the previous step

4: Update fstab with New Storage Device

fstab is the Linux configuration file which configures the storage available on the system. It must be updated to recognise the newly formatted partition.

This can be done automatically by running:

block detect | uci import fstab

To ensure the drive is always mounted when OpenWrt starts, run:

uci set fstab.@mount[0].enabled='1' && uci set fstab.@global[0].anon_mount='1' && uci commit fstab

5: Reboot OpenWrt

All you need to do now is reboot your router and your new storage will be available at

/mnt/sda1

(Replacing sda1 with your device name, of course)

More details and configuration options can be found on the OpenWrt Wiki/

SHARE:
Photo of author
Author
I'm Brad, and I'm nearing 20 years of experience with Linux. I've worked in just about every IT role there is before taking the leap into software development. Currently, I'm building desktop and web-based solutions with NodeJS and PHP hosted on Linux infrastructure. Visit my blog or find me on Twitter to see what I'm up to.

2 thoughts on “How to Add Extra External USB Storage to an OpenWrt Device”

  1. Hi Brad – For this procedure, when I run this command:
    uci set fstab.@mount[0].enabled=’1′ && uci set fstab.@global[0].anon_mount=’1′ && uci commit fstab
    I get this:

    uci: Invalid argument

    How can I fix this?
    Thanks,

    Reply
    • It looks like the quote characters could have been messed up during a copy and paste (they appear to be backticks rather than single quotes in your comment) – give this a try:

      uci set fstab.@mount[0].enabled='1' && uci set fstab.@global[0].anon_mount='1' && uci commit fstab

      Reply

Leave a Comment