Typical OpenWRT devices usually have pretty limited storage. Some have 128MB+ today, but the ones I most often use have 32MB or less. Not a lot of flash memory for storing logs or full PCAP captures! But many of these home routers have USB ports and we can use these to add gigabytes of storage.
To get setup, first make sure your package repositories are updated:
root@OpenWRT:~# opkg update
Mounting Support
root@OpenWRT:~# opkg install block-mount
The block-mount package includes an /etc/init.d/fstab
file which prints out an annoying but irrelevant error message: this file has been obsoleted. please call "/sbin/block mount" directly
. You can safely ignore it. The init.d file isn't needed, it uses hotplug instead to auto-mount.
Plug your USB device in. And type block detect
and it'll output a uci-style config. If it looks like this (i.e. there are no 'mount' sections), you'll need to do the Kernel Modules section below to get the right support setup.
root@OpenWrt:~# block detect
config 'global'
option anon_swap '0'
option anon_mount '0'
option auto_swap '1'
option auto_mount '1'
option delay_root '5'
option check_fs '0'
But if your output looks like this (i.e. it has one or more 'mount' sections), then your kernel support is already setup!
root@OpenWrt:~# block detect
config 'global'
option anon_swap '0'
option anon_mount '0'
option auto_swap '1'
option auto_mount '1'
option delay_root '5'
option check_fs '0'
config 'mount'
option target '/mnt/sda1'
option uuid '12345678-1234-5678-90ab-123456789abc'
option enabled '0'
Kernel Modules
Unfortunately, not all OpenWRT images are created alike. My Linksys EA4500 build (Viper) had usb-storage modules built-in (and I could skip this section). But my TP-Link WDR3600 did not. And so I had to manually install some kernel modules.
I'm using ext4 formatted USB drives. Substitute in the filesystem of your choice below (usually vfat
or ext4
). Caution: I've seen a handful of USB devices formatted with exfat. I haven't seen any official support for this in OpenWRT yet! Here is what is supported (as of 5 October 2018 and OpenWRT 18.06.1) and the package name to get the right modules:
Package Name | Description |
---|---|
kmod-fs-autofs4 | Kernel module for AutoFS4 support |
kmod-fs-btrfs | Kernel module for BTRFS support |
kmod-fs-cifs | Kernel module for CIFS support |
kmod-fs-configfs | Kernel module for configfs support |
kmod-fs-cramfs | Kernel module for cramfs support |
kmod-fs-exportfs | Kernel module for exportfs. Needed for some other modules. |
kmod-fs-ext4 | Kernel module for EXT4 filesystem support |
kmod-fs-f2fs | Kernel module for F2FS filesystem support |
kmod-fs-fscache | General filesystem local cache manager |
kmod-fs-hfs | Kernel module for HFS filesystem support |
kmod-fs-hfsplus | Kernel module for HFS+ filesystem support |
kmod-fs-isofs | Kernel module for ISO9660 filesystem support |
kmod-fs-jfs | Kernel module for JFS support |
kmod-fs-minix | Kernel module for Minix filesystem support |
kmod-fs-msdos | Kernel module for MSDOS filesystem support |
kmod-fs-nfs | Kernel module for NFS client support |
kmod-fs-nfs-common | Common NFS filesystem modules |
kmod-fs-nfs-common-rpcsec | Kernel modules for NFS Secure RPC |
kmod-fs-nfs-v3 | Kernel module for NFS v3 client support |
kmod-fs-nfs-v4 | Kernel module for NFS v4 support |
kmod-fs-nfsd | Kernel module for NFS kernel server support |
kmod-fs-ntfs | Kernel module for NTFS filesystem support |
kmod-fs-reiserfs | Kernel module for ReiserFS support |
kmod-fs-squashfs | Kernel module for SquashFS 4.0 support |
kmod-fs-udf | Kernel module for UDF filesystem support |
kmod-fs-vfat | Kernel module for VFAT filesystem support |
kmod-fs-xfs | Kernel module for XFS support |
Need the usb-storage module (to talk to our usb device) AND the filesystem modules:
root@OpenWRT:~# opkg install kmod-usb-storage kmod-fs-ext4
With that support out of the way, let's see if our USB device is recognized:
root@OpenWrt:~# dmesg
[ 3350.134439] usb 1-1.1: new high-speed USB device number 6 using ehci-platform
[ 3350.291658] usb-storage 1-1.1:1.0: USB Mass Storage device detected
[ 3350.299002] scsi host0: usb-storage 1-1.1:1.0
[ 3351.704847] scsi 0:0:0:0: Direct-Access JetFlash Transcend 16GB 1100 PQ: 0 ANSI: 6
[ 3351.716537] sd 0:0:0:0: [sda] 30851072 512-byte logical blocks: (15.8 GB/14.7 GiB)
[ 3351.725008] sd 0:0:0:0: [sda] Write Protect is off
[ 3351.729892] sd 0:0:0:0: [sda] Mode Sense: 43 00 00 00
[ 3351.730622] sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
[ 3351.746248] sda: sda1
[ 3351.754754] sd 0:0:0:0: [sda] Attached SCSI removable disk
root@OpenWrt:~#
Mount the Drive
The block-mount
packaged provided the /sbin/block
tool to help with auto-mounting. All you need to do is put the right config in /etc/config/fstab
.
If it's your first device, simply run:
root@OpenWrt:~# block detect > /etc/config/fstab
That'll get the file setup. Then you'll need to edit /etc/config/fstab
and set enabled to 1.
config 'global'
option anon_swap '0'
option anon_mount '0'
option auto_swap '1'
option auto_mount '1'
option delay_root '5'
option check_fs '0'
config 'mount'
option target '/mnt/sda1'
option uuid '12345678-1234-5678-90ab-123456789abc'
option enabled '1'
Make sure the directory you want to mount to exists!
root@OpenWrt:~# mkdir /mnt/sda1
Finally, manually call block to mount the drive:
root@OpenWrt:~# block mount
Voila! Your drive should be mounted. Verify it by calling mount
:
root@OpenWrt:~# mount
/dev/root on /rom type squashfs (ro,relatime)
proc on /proc type proc (rw,nosuid,nodev,noexec,noatime)
sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,noatime)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noatime)
/dev/mtdblock3 on /overlay type jffs2 (rw,noatime)
overlayfs:/overlay on / type overlay (rw,noatime,lowerdir=/,upperdir=/overlay/upper,workdir=/overlay/work)
tmpfs on /dev type tmpfs (rw,nosuid,relatime,size=512k,mode=755)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,mode=600,ptmxmode=000)
debugfs on /sys/kernel/debug type debugfs (rw,noatime)
/dev/sda1 on /mnt/sda1 type ext4 (rw,relatime,data=ordered)