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 hard disk, etc. This article will tell you the steps and requirements to do this.
Note that this article is mainly about adding external space in addition to the internal flash usage. Moving the root-fs to an external storage space is described in the article extroot.
The main course of action is as follows:
/dev/. For example /dev/sda as the device, with /dev/sda1, /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/sdb, /dev/sdc and so on. Make sure that the file system requirements are satisfied by installing the proper kernel packages for specific file system support (see Storage);/etc/config/fstab and you can configure it as root file system using extroot.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-storage required … 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-extras optional … Kernel support for some more drivers, such as for SmartMedia card readers.kmod-scsi-core Any mass storage is a generic SCSI device.| | Before the Attitude Adjustment release, other optional packages included: block-hotplug for USB recognition upon plug-in and block-extroot required for rootfs on external storage. In r26314 the three opkg packages block-mount, block-extroot and block-hotplug have been merged into a single package block-mount. |
| | Since r36988 block-mount has been superceded by ubox. block-mount_binary_package. The block command line utility is still useful in the block-mount package especially for setting up fstab |
e2fsprogs additional 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.opkg install e2fsprogs
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 kmod-fs-ext4
If using version older than r36988 you may still need:
opkg install block-mount
After install use storage with:
mkswap /dev/sda1 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 kmod-fs-ext4 kmod-fs-vfat kmod-nls-cp437 kmod-nls-iso8859-1 mkdir -p /mnt/usb mount -t vfat /dev/sda1 /mnt/usb
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
umount /mnt/usb #make sure the disk isn't mounted before doing this touch /mnt/usb/USB_DISK_NOT_PRESENT chmod 555 /mnt/usb chmod 444 /mnt/usb/USB_DISK_NOT_PRESENTThis will prevent only processes not running as root from writing onto NAND (see this discussion). You can of course also use this file in your own scripts.
The good news first: OpenWrt can use encrypted disks almost out-of-the-box.
The bad news is, there are some things to keep in mind.
Devices with 32 MB memory may run short of free memory. Symptoms can be that LUCI is displaying the Login page instead of the actual target page or that the out-of-memory killer starts killing tasks, so strange failures happen. Monitor the memory, e,g. using the free command.
Decryption and encryption may slow down the system. cryptsetup benchmark will show some numbers that can be compare for different platform.
Using Linux hard disk encryption with LUKS is straight forward:
opkg install cryptsetup lvm2 kmod-crypto-aes kmod-crypto-misc kmod-crypto-xts kmod-crypto-iv kmod-crypto-cbc kmod-crypto-crc32c kmod-crypto-hash kmod-dm kmod-crypto-user
echo sha256_generic >/etc/modules.d/11-crypto-misc
cryptsetup luksOpen /dev/encrypted_partition usbstorage_luks && mount /dev/mapper/usbstorage_luks /mnt/mountpoint
umount /mnt/mountpoint && cryptsetup luksClose usbstorage_luks
Please refer to the existing documentations, e.g.
<none yet>