Mounting a USB Drive on OpenWRT Chaos Calmer

[This is a partial update to TP-Link AC1750 Archer C7 and OpenWRT - which is mostly about USB mounting on OpenWRT Barrier Breaker.]

The idea is simple: mount a USB thumb drive on an OpenWRT Chaos Calmer router. As it turns out, the practical reality is ... complex. The primary problem is that OpenWRT tries to be extremely small to fit into the limited memory of routers - and so it doesn't include any packages not essential to the operating system and being a router. So all packages related to mounting USB devices have to be added by hand. Secondary but significant problems include the following:

  • the OpenWRT site is a morass of conflicting and mostly outdated documentation, the majority of which doesn't bother to mention which version of the OS it applies to - so you just have to follow along until something breaks and you realize this is for an older version.
  • VFAT seems to be particularly tricky, and since I want to use standard USB thumb drives without reformatting them, that's what I started with.

Here's the first step:

# opkg install usbutils kmod-usb-storage block-mount

This will install the basics needed for handling USB devices (plus a couple dependencies). Having plugged in a USB stick, we can take a look around:

# ls -l /dev/sd*
brw-r--r--    1 root     root        8,   0 Oct 29 13:22 /dev/sda
brw-r--r--    1 root     root        8,   1 Oct 29 13:22 /dev/sda1
# block info
<...>
/dev/sda1: UUID="5bb5-24f4" LABEL="Lexar" VERSION="FAT32" TYPE="vfat"

We can see it, but we don't actually have all the packages we need to mount it. I wasn't sure, so I thought an early test was called for:

# mkdir /mnt/usb1
# mount /dev/sda1 /mnt/usb1/
mount: mounting /dev/sda1 on /mnt/usb1/ failed: Invalid argument

So I got the package I thought I needed:

# opkg install kmod-fs-vfat

That's it, right? So let's assume this is a very simple mount program (it's busybox!) and needs you to set all the parameters because it can't autodetect:

# mount -t vfat /dev/sda1 /mnt/usb1 -o rw,sync
mount: mounting /dev/sda1 on /mnt/usb1/ failed: Invalid argument

What makes me a bit crazy about this is that "Invalid argument" implies I haven't provided the correct command line parameters. But it doesn't tell you what or why: instead you have to look at the system messages:

# dmesg
<...>
[3686103.710000] FAT-fs (sda1): codepage cp437 not found

So ...

# opkg install kmod-nls-cp437
# mount -t vfat /dev/sda1 /mnt/usb1 -o rw,sync
mount: mounting /dev/sda1 on /mnt/usb1/ failed: Invalid argument
# dmesg
<...>
... FAT-fs (sda1): IO charset iso8859-1 not found
# opkg install kmod-nls-iso8859

And finally mount silently succeeded. (If you're not English-speaking or in North America, the kmod-nls-... modules you need will likely be different.)

With the previous Barrier Breaker release, the NLS/charset packages weren't needed for ext4 or iso file systems: I haven't confirmed if this is still true with CC. You would of course still need to install 'kmod-fs-...' packages for each of those. Here's the list of FS modules currently available:

  • kmod-fs-afs
  • kmod-fs-autofs4
  • kmod-fs-btrfs
  • kmod-fs-cifs
  • kmod-fs-configfs
  • kmod-fs-cramfs
  • kmod-fs-exfat
  • kmod-fs-exportfs
  • kmod-fs-ext4
  • kmod-fs-f2fs
  • kmod-fs-fscache
  • kmod-fs-hfs
  • kmod-fs-hfsplus
  • kmod-fs-isofs
  • kmod-fs-jfs
  • kmod-fs-minix
  • kmod-fs-msdos
  • kmod-fs-nfs
  • kmod-fs-nfs-common
  • kmod-fs-nfsd
  • kmod-fs-ntfs
  • kmod-fs-reiserfs
  • kmod-fs-udf
  • kmod-fs-vfat
  • kmod-fs-xfs

The details above are also not sufficient to automount USB devices on startup: that's another saga that I haven't attempted yet.

This page: "Partitioning, Formatting and Mounting Storage Devices" - which appears to be up-to-date for CC - recommends fairly strongly against using NTFS file systems as it has "performance issues" with "Linux." I put "Linux" in quotes because I use NTFS fairly heavily on Fedora and Debian without noticeable problems so I'm guessing that they actually mean "OpenWRT ..."