Skip to content

Adding external USB support

Kirigia edited this page Jun 13, 2024 · 4 revisions

This page is for adding USB support for OpenWRT.

In this use case we are using it to store the websites HTML data on a usb drive.

Before starting, please make sure your router has a USB port and has a internet connection

Format drive

Make sure your drive is over 8MB and is formatted to ExFAT. Simply drag and drop your data onto your drive.

Install and verify USB drivers

This step ensures that required USB storage drivers are properly installed.

Start by refreshing the list of available software packages in PuTTY: opkg update

Install a USB storage driver by pasting this in PuTTY. opkg install kmod-usb-storage opkg install kmod-usb-storage-uas

To see if it installed correctly paste this into PuTTY: opkg install usbutils

Connect your USB drive and type this into PuTTY: lsusb -t

This will output a list of device USB hub ports and connected external storage devices: /: Bus 02.Port 1: Dev 1, Class=root_hub, Driver=xhci-mtk/1p, 5000M /: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci-mtk/2p, 480M |__ Port 1: Dev 5, If 0, Class=Mass Storage, Driver=usb-storage, 480M

Make sure your USB device shows up, it should be listed under a BUS as shown in this example.

Verify that the OS recognizes the attached disk and partitions

  1. Ensure your USB disk/stick is stick connected
  2. Paste this in PuTTY ls -l /dev/sd*

This should now show a list of block devices known to the OS brw------- 1 root root 8, 0 Oct 30 12:49 /dev/sda brw------- 1 root root 8, 1 Oct 30 12:49 /dev/sda1

This should print at least a connected disk like “/dev/sda” or “/dev/sdb”. If no disk at all is listed, recheck USB driver installation and reboot your OpenWrt device once. If don't see a device called /dev/sda1 then OpenWRT doesn't see your device.

Install the block tool to get more info about existing partitions by pasting these lines in PuTTY

opkg install block-mount opkg install libblkid

Run the block tool: block info | grep "/dev/sd"

and you should see output like this, if your disk already has partitions:

/dev/sda1: UUID="2eb39413-83a4-4bae-b148-34fb03a94e89" VERSION="1.0" TYPE="ext4"

Install file system drivers and create a file system in the partition

Paste this line into PuTTY

opkg install kmod-fs-exfat

Automount the partition

This is a very important step to make sure OpenWRT sees your USB drive

Paste all of these lines into PuTTY block detect | uci import fstab uci set fstab.@mount[-1].enabled='1' uci commit fstab uci set fstab.@global[0].check_fs='1' uci commit fstab

Now reboot your device by typing reboot in PuTTY

After the reboot type this in PuTTY uci show fstab

You should see something remotely close to this fstab.@global[0]=global fstab.@global[0].anon_swap='0' fstab.@global[0].anon_mount='0' fstab.@global[0].auto_swap='1' fstab.@global[0].auto_mount='1' fstab.@global[0].check_fs='0' fstab.@global[0].delay_root='5' fstab.@mount[0]=mount fstab.@mount[0].target='/mnt/sda1' fstab.@mount[0].uuid='49c35b1f-a503-45b1-a953-56707bb84968' fstab.@mount[0].enabled='1' Check the “enabled” entry. It should be '1'.

Now paste this into PuTTY to enable everything service fstab boot

installed

All of your files will be viewable in FilesRemote under /mnt/sda1

If you want to have your router get all of the website HTML off of the USB drive go to the USB Website page in the Wiki.

Clone this wiki locally