Once you have obtained Basic USB support, you may want to connect a USB storage device to your router, for example a USB stick, a USB harddisk, etc. This article will tell you the steps and requirements to do this.
The main course of action is as follows:
- Obtain basic USB support on your OpenWrt-powered device;
- Install USB storage prerequisites as shown below). A connected USB storage device (e.g. hard disc) can now be recognised by the system;
- If not already done, partition the device and create the file systems you want (see Storage on how to do this from within OpenWrt). The device itself and its partitions should immediately be available as Device files under
/dev/. For example
/dev/sdaas the device, with
/dev/sda2, … , the partitions. Or, in case it is not partitioned with a partition table and it has a single file system it may be directly accessible under e.g.
/dev/sda. Subsequent devices you add will be
/dev/sdcand so on. Make sure that the file system requirements are satisfied by installing the proper kernel packages for specific file system support (see Storage);
When your USB device is properly recognised by the system, using the proper driver kernel packages listed in Basic USB support, the following packages facilitate USB storage support:
kmod-usb-storagerequired … Kernel support for USB Mass Storage devices.
kmod-fs-<file_system>required … the file system you formatted your partition in. Common examples include kmod_fs_ext4, kmod-fs-hfs, kmod_fs_hfsplus, kmod-fs-msdos, kmod-fs-ntfs, kmod-fs-reiserfs and kmod-fs-xfs.
kmod-usb-storage-extrasoptional … Kernel support for some more drivers, such as for SmartMedia card readers.
kmod-scsi-genericprobably required … Any mass storage is a generic SCSI device.
|Before the Attitude Adjustment release, other optional packages included:
e2fsprogsadditional This package contains essential ext2/ext3/ext4 filesystem utilities for formatting and checking for errors on ext2/ext3/ext4 filesystems like mkfs.ext3, mkfs.ext4, fsck and other core utilities.
The following will install USB storage support, assuming USB works already, install ext4 file system support and mount a connected USB drive, pre-partitioned with a Linux swap partition and an ext4 partition.
opkg update opkg install kmod-usb-storage block-mount kmod-fs-ext4 swapon /dev/sda1 mkdir -p /mnt/share mount -t ext4 /dev/sda2 /mnt/share -o rw,sync
Note that partitions are usually auto detected, so this should work as well using default settings:
mount /dev/sda2 /mnt/share
Another example is how to use an external usb stick with a FAT32 partition (but we'll keep ext4 support also). See also Storage.
opkg update opkg install kmod-usb-storage block-mount block-hotplug kmod-fs-ext4 kmod-fs-vfat kmod-nls-cp437 kmod-nls-iso8859-1 mkdir -p /mnt/usb mount -t vfat /dev/sda1 /mnt/usb
This section is apparently incorrect as it doesn't work as reported here: https://forum.openwrt.org/viewtopic.php?id=42351 Can someone explain or improve this? Otherwise delete this section.
You may create an empty file to indicate that the disk is not plugged in so that you don't put files directly onto NAND by doing
touch /mnt/usbstorage/USB_DISK_NOT_PRESENT chmod 444 /mnt/usbstorage -RThis will prevent only processes not running as root from writing onto NAND. You can of course also use this file in your own scripts.
doc/howto/usb.storage.txt · Last modified: 2014/02/08 15:30 by jaloonz