USB Storage
Once you have obtained Basic USB support, you may want to connect a USB storage device (USB stick, USB harddisk, etc) to your router. This HowTo will tell you the steps. You should be aware that any storage device has to be partitioned and formated with a File system (ie. ext3) before data can be addressed as files by the OS.
Preparations
Prerequisites
- obtain Basic USB support on your OpenWrt-powered device
- install storage and file system requirements (Required Packages), as shown below. Minimum you need kmod-usb-storage to see usb disk devices.
- connect the already partitioned and formatted storage device (e.g. hard disc) to your OpenWrt-powered device; the device itself and its partitions should immediately be available as Device files under
/dev/, for exampledev/sda,/dev/sda1,/dev/sda2, etc.
| ✘ | We do NOT recommend using NTFS. While it is possible, it has serious performance issues under Linux. |
| ✔ | We recommend the file systems ext2, ext3, or ext4 (all supported by kmod-fs-ext4) |
If you are planning on sharing your USB storage with Samba, and/or using it to share large multimedia content over UPnP, e.g. with ushare, you should use ext3 or ext4 rather than ext2. Default Ext2 partitions will be limited to files of no more than 4 Gb, but this restriction is eliminated with the newer filesystems. To retain good performance with the newer filesystems, particularly on flash USB storage, you should also consider disabling journaling with the "-O ^has_journal" when using mkfs.ext4 to format the filesystem. Also for ext4, the "extent" formatting option (e.g. "-O ^has_journal,extent") will make filesystem access to large files more performant.
Required Packages
As of r26314 block-extroot and block-hotplug have been merged with block-mount. That means that once you select block-mount the scripts for extroot mounting and hotplug mounting are installed. block-mount can be installed even if you have not selected a block device package, but if you want to actually mount a block device you must still install the drivers (block device package) as well as the filesystem you want to use (e.g. ext4, kmod-fs-ext4 and e2fsprogs). ( This may not be true for Backfire (10.03.1, r29592) users. It was confirmed that block-mount is not enough to make fstab work → block-hotplug had to be installed separately with opkg install block-hotplug. Its possible that same might be said about the block-extroot package.) |
kmod-usb-storagerequired Kernel support for USB Mass Storage deviceskmod-usb-storage-extrasoptional Kernel support for some more drivers, such as for SmartMedia card readersblock-mountoptional & recommended Scripts used to mount and check block devices (filesystems and swap). Required forfstabconfiguration.- Since Attitude Adjustment it includes:
block-hotplugrequired for configuration with/etc/config/fstabblock-extrootrequired for rootfs on external storage
- Dependencies:
blkidCommand-line utility to locate/print block device attributesswap-utilsThis package contains a collection of tools for managing swap space:mkswap,swaponandswapoff
kmod-fs-????required the filesystem you formated your partition in
kmod-usb2optional USB2.0 support, needed for stable USB1.0 usage with some devices (e.g. La Fonera 2), too.
kmod-usb-ohci or kmod-usb-uhcioptional USB1.0 support
kmod-scsi-generic
probably required Any mass storage is a generic SCSI device.
Available Filesystems
As of r26645 the modules for ext2 and ext3 (kmod-fs-ext2 and kmod-fs-ext3) are no longer available. You can use the module for ext4 kmod-fs-ext4 to mount ext2/ext3 as well, but then you have to mount your ext2 or ext3 partition like ext4 partition: mount -t ext4 /dev/sda1 /mnt/share -o rw,sync |
OpenWrt-Forum: Benchmarks with different filesystems
Available file systems and their packages can be listed with opkg update; opkg list "kmod-fs*".
| 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-exportfs | Kernel module for exportfs. Needed for some other modules. |
| kmod-fs-ext4 | Kernel module for ext2, ext3 and ext4 filesystem support1) |
| 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-minix | Kernel module for MINIX file system support |
| kmod-fs-msdos | Kernel module for MSDOS filesystem support |
| kmod-fs-nfs | Kernel module for NFS support |
| kmod-fs-nfs-common | Common NFS filesystem modules |
| kmod-fs-nfsd | Kernel module for NFS kernel server support |
| kmod-fs-ntfs | Kernel module for NTFS read only filesystem support |
| kmod-fs-reiserfs | Kernel module for ReiserFS 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 |
| You are not required to use NTFS or FAT in order to access the disk from Microsoft Windows! See http://wiki.ubuntuusers.de/Linux-Partitionen_unter_Windows on HowTo access Linux filesystems from Windows. Thus native Linux file systems like ext2 or ext3 are the first choice when working with Linux. Don't bother with NTFS, VFAT and the like. They all have some quirks we could do without. |
If, for whatever reasons, you insist to utilize NTFS as file system, you may find Writable NTFS helpful.
Available NLS files
For some filesystems, like for VFAT, you need to additionally install language packages (codepages / charsets) to handle the filenames. If your mount fails, look in dmesg - a message like
FAT: codepage cp437 not found
means that you need NLS codepage 437, and a message like
FAT: IO charset iso8859-1 not found
means that you need NLS ISO 8859-1.
***''kmod-nls-base''** Kernel module for NLS (Native Language Support)
Available NLS files and their packages can be listed with opkg update; opkg list "kmod-nls*".
| Name | Description |
|---|---|
| kmod-nls-cp1250 | Kernel module for NLS Codepage 1250 (Eastern Europe) |
| kmod-nls-cp1251 | Kernel module for NLS Codepage 1251 (Russian) |
| kmod-nls-cp437 | Kernel module for NLS Codepage 437 (United States, Canada) |
| kmod-nls-cp775 | Kernel module for NLS Codepage 775 (Baltic Rim) |
| kmod-nls-cp850 | Kernel module for NLS Codepage 850 (Europe) |
| kmod-nls-cp852 | Kernel module for NLS Codepage 852 (Europe) |
| kmod-nls-cp866 | Kernel module for NLS Codepage 866 (Cyrillic) |
| kmod-nls-iso8859-1 | Kernel module for NLS ISO 8859-1 (Latin 1) |
| kmod-nls-iso8859-13 | Kernel module for NLS ISO 8859-13 (Latin 7; Baltic) |
| kmod-nls-iso8859-15 | Kernel module for NLS ISO 8859-15 (Latin 9) |
| kmod-nls-iso8859-2 | Kernel module for NLS ISO 8859-2 (Latin 2) |
| kmod-nls-koi8r | Kernel module for NLS KOI8-R (Russian) |
| kmod-nls-utf8 | Kernel module for NLS UTF-8 |
Configuration
There is nothing to configure! Read the manpage for mount. Pay special attention to the options! You can only mount a partition to an existing directory. You can create it with mkdir, for example:
mkdir -p /mnt/shares
To manually mount a partition:
mount -t ext3 /dev/sda2 /mnt/shares -o rw,sync
To unmount:
umount /mnt/shares
To mount a swap partition:
swapon /dev/sda1
To unmount a swap partition:
swapoff /dev/sda1
Examples
opkg update opkg install kmod-usb-storage block-mount block-hotplug kmod-fs-ext4 swapon /dev/sda1 mkdir -p /mnt/share mount -t ext3 /dev/sda2 /mnt/share -o rw,sync
Other example is how to external usb stick with FAt32 partition (but we'll keep ext4 support also)
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
Start on boot
As of r26314 block-extroot and block-hotplug have been merged with block-mount. That means that once you select block-mount the scripts for extroot mounting and hotplug mounting are installed. block-mount can be installed even if you have not selected a block device package, but if you want to actually mount a block device you must still install the drivers (block device package) as well as the filesystem you want to use (e.g. ext4, kmod-fs-ext4 and e2fsprogs) |
Install the packages block-mount and block-hotplug, they will take care of this and also enable automatic mount when device is plugged in.
The configuration file is /etc/config/fstab.
Example settings in fstab for mounting to /mnt/share with automatic detection of the file system:
config 'mount'
option 'device' '/dev/sda1'
option 'options' 'rw,sync'
option 'enabled_fsck' '0'
option 'enabled' '1'
option 'target' '/mnt/share'
|
And to make the fstab settings effective in current session run:
/etc/init.d/fstab start
To make the fstab settings effective after every reboot run:
/etc/init.d/fstab enable
UCI CLI commands:
/etc/init.d/fstab stop uci add fstab mount uci set fstab.@mount[-1].device=/dev/sda1 uci set fstab.@mount[-1].options=rw,sync uci set fstab.@mount[-1].enabled_fsck=0 uci set fstab.@mount[-1].enabled=1 uci set fstab.@mount[-1].target=/mnt/share uci commit fstab /etc/init.d/fstab start
Delete with UCI CLI commands:
/etc/init.d/fstab stop uci delete fstab.@mount[0] uci commit fstab /etc/init.d/fstab start
Note: In order to do fsck (aka CHKDSK) of FAT32/VFAT partitions before mounting (i.e. during the boot process), you should read the following tickets:
Incorrect log output for mount point file systems without a fsck, and
Missing fsck function for block-mount/-hotplug of dos/vfat filesystems
Rigging it up from OpenWrt
Actually there are packages in the OpenWrt repositories with which you can partition, format and check filesystems:
fdisk(for help with partitioning see TLDP)e2fsprogsContains the essential ext2 filesystem utilitiese2fsck,mke2fs,debugfs,dumpe2fsandtune2fs, and also most of the other core ext2 filesystem utilities available. for help with formatting see TLDP
Note: In order to perform a e2fsck on 1 GiB partition, you will need at least 1 MiB of RAM.2) The same is true for mke2fs. You can solve this by mounting a SWAP partition (or by using a device with enough RAM).
Installing OPKG packages in mount point other than root
Once you successfully mounted your partition, you may want to install packages onto it. Please see Installation.Destination for that.
If you plan to install kernel modules on a USB drive you might want to read this: https://dev.openwrt.org/ticket/10739
Disable writing when not mounted
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.
Manual
mount the external drive:
(where sda1 is your drive, see fdisk -ls, and /mnt/hdd is the point where you wish to mount. Use md to make the directories)
ntfs-3g -o rw,noatime /dev/sda1 /mnt/hdd
Then make the following script:
nano /etc/init.d/hdd
And the contents:
(In this script, You can control other processes, like transmission, whitch uses Your external drive)
#!/bin/sh /etc/rc.common
START=98
STOP=40
start()
{
echo -n "Mounting USB drive: "
ntfs-3g -o rw,noatime /dev/sda1 /mnt/hdd
swapon /mnt/hdd/swapfile
mount -o loop /mnt/hdd/owrt_loop /mnt/loopdisk
opkg-link mount /mnt/loopdisk
apachectl start
echo "Done."
}
stop()
{
echo -n "Umounting USB drive: "
apachectl stop
sync
sync
swapoff /mnt/hdd/swapfile
umount -l /mnt/loopdisk
umount -l /dev/sda1
echo "Done."
}
restart()
{
apachectl restart
}
|
Enter the required permissions to it.
chmod a+x /etc/init.d/hdd
create a swapfile, then format and turned on.
dd if=/dev/zero of=/mnt/hdd/swapfile bs=1M count=64 mkswap /mnt/hdd/swapfile swapon /mnt/hdd/swapfile
To see if work:
free
Virtual Disk
Now let's do a virtual disk. You need an additional package.
opkg update opkg install kmod-fs-ext3 kmod-loop e2fsprogs insmod ext3 insmod loop
Then, create, and format the disk:
dd if=/dev/zero of=/mnt/hdd/owrt_loop bs=1M count=128 mke2fs -j -F -b 1024 /mnt/hdd/owrt_loop
To be able to use, plug-in for OpenWrt:
mkdir /mnt/loopdisk mount -o loop /mnt/hdd/owrt_loop /mnt/loopdisk
Now our system is not only the OpenWrt xMB, but x+128 MB
Write in /etc/opkg.conf file into the following line
dest usb /mnt/loopdisk |
To install package:
opkg -dest usb install package
To delete package:
opkg -dest usb remove package
Troubleshooting
FAT, NTFS
Prefer EXT2 or EXT3 file system.
I don't see /dev/sda1 or similar
Symptoms: I have installed kmod-usb-storage, but I don't see sda, sda1, sda2 or similar in /dev directory.
Solution: Make sure you have started and enabled usb startup script:
/etc/init.d/usb start /etc/init.d/usb enable
kmod-fs-ext4 won't mount ext2 or ext3 partition
Symptoms: You are trying to mount ext2 or ext3 partition and you have installed only kmod-fs-ext4. Neither mount command nor fstab works. The kmod-fs-ext4 issue definitely applies to Backfire, but is not an issue for Attitude Adjustment (tested on Attitude Adjustment RC1).
Solution a): you have to make sure that you are trying to mount the ext2 or ext3 partition like it was ext4 partition. Example /etc/config/fstab config and mount command follows:
config mount
option target /mnt
option device /dev/sda1 # sda1 is ext3 partition
option fstype ext4 # but is mounted as ext4, since we have installed kmod-fs-ext4 only
option options rw,sync
option enabled 1
option enabled_fsck 1
|
mount -t ext4 /dev/sda1 /mnt -o rw,sync
Solution b): install kmod-fs-ext3 or kmod-fs-ext2 filesystem.
opkg update opkg install kmod-fs-ext3
Other
Note: If you are having trouble with fstab, see fstab troubleshooting.
Note: If you are having trouble using storage on a Huaweu 3G dongle, you should read the following ticket:Mass storage missing from 3G dongle
Notes
doc/howto/usb.storage.txt · Last modified: 2013/02/13 19:31 by stephenc01
