USB storage

From DD-WRT Wiki

Revision as of 20:54, 17 October 2008 by Matoqui (Talk | contribs)
Jump to: navigation, search

Contents

USB storage

Applications

  • The use of a USB-compatible router makes the SD/MMC modification unnecessary. Just drop any old digital camera card into a USB flash card reader and easily expand the tiny 4Mb or so of flash memory in a typical Linux-based router to as much as eight gigabytes. Any of the various card types, including CompactFlash and SD, are suitable. USB flash devices are also available as one self-contained unit: a small "tag" which can store up to several gigabytes of data.
  • A USB hard drive can be used as network-attached storage, shared by all computers on a LAN using Samba or NFS. Most standard internal hard drives (notebook or desktop) can be converted simply by installing them in an inexpensive USB enclosure.
  • A USB hard drive can also be used as virtual memory by creating swap space. Instead of abruptly running out of memory when the 32Mb of physical RAM in these units is full, a portion is swapped to disc and the applications continue to run normally, but with a speed penalty.
  • Mounting a USB storage device as /opt provides nearly-unlimited space to install many applications from the large collection of Optware packages, ported to embedded Linux originally for use with the Linksys "slug" (NSLU2) USB network-attached storage servers. A USB-compatible router can provide pretty much all of the NSLU2's capabilities (at a comparable price) plus offer all of the capabilites of a standard router and a wireless access point.

The use of standard USB hubs allows other USB devices (such as printers, serial ports, CD/DVD drives and audio) to remain connected even while the USB interface is used for flash cards or hard drive interfaces.

Compatible units

This is not a comprehensive list of Supported Devices, just a few which support USB:

Note: The Asus WL-520GU requires the use of the usb-ohci driver. Using the ehci-hcd driver will identify and find USB storage devices, but reboots the WRT every time you try to access the storage. See this OpenWRT forum discussion for more information.

Note: as of v.24 USB support is included via the web-GUI in the mega versions of dd-wrt.

Note: v.24 x86 version of dd-wrt does not yet have USB support built in to the web-GUI

For versions (Mega and more) with built-in USB suport

  • USB support is built-in on the Mega version of DD-WRT as of v.24.
  • eko has built mini versions of DD-WRT v24+ with USB support here:
http://www.dd-wrt.com/dd-wrtv3/dd-wrt/downloads.html
(under 'others', 'eko', 'v24_TNG', from svn10137 or later)


Enable USB support on the Mega version of DD-WRT

Using the Web-GUI to enable USB support select:

Services -> Services --> USB support:
Core USB support = enable

Enable one or both of the following if you want to use USB 1.1 devices

  • USB 1.1 Support (UHCI)
  • USB 1.1 Support (OHCI)

Enable the following if you want to use USB 2.0 devices

  • USB 2.0 Support

Enable the following if you want to access USB hard disks or USB flash drives

  • USB Storage Support

Activate one or more file systems to be able to access on the storage devices

  • ext2 / ext3 File System Support
  • FAT File System Support

Enable the following if you want to access USB printers attached to the DD-WRT mega loaded router over the network

  • USB Printer Support


Where to go from here...

... to actually use USB devices on your DD-WRT Mega version.


To access a network drive partition

Step 1 - Partition and format your USB drive

You need to first partition and format you drive

This can be done by attaching the drives to an other system.
Like a PC running linux (maybe from a LiveCD) or from a Windows PC using a partitioning tool. Some have been able to use their iPod.

You can format your partitions to either ext2/3 or FAT32. Use ONLY ext2/3 for partition/drives that you plan for permanent connection to your DD-WRT box, or for drives where you plan to install additional software packages onto.

For large drives you may want to consider creating three partitions:

  • one: for optware packages - make it 512Kb - 2Gb - use ext2/3 as the format
  • two: for swap file - make it 128-1024 Kb - format it as linux swap file
  • three: for data space - make it fit the rest of the disk - use ext2/3 as the format


Step 2 - Connect the HD to your DD-WRT box

Plug in the freshly partitioned and formatted USB drive to you dd-wrt box!


Step 3 - Prepare to mount the drive(s)

You need to identify mounting details about you USB drive(s)

  • Use a telnet connection (use ie. PuTTY) to connect to your router
  • Use command dmesg to get mounting details of your USB drive(s). The list can get quite long, so you need to...

Look for something that starts with /dev, like:

Partition check:
/dev/scsi/host0/bus0/target0/lun0: p1
p1 means partition1.

The string /dev/scsi/host0/bus0/target0/lun0 is hardware specific, which is why you need to find this information/string for your specific router. The example is from a wl500gP v1 router.


Command ls can then be used to find actual name of partition(s) on your drive

Example with three partitions:
root@DD-WRT:~# ls /dev/scsi/host0/bus0/target0/lun0
disc part1 part2 part3
root@DD-WRT:~# ls -l /dev/scsi/host0/bus0/target0/lun0
brw------- 1 root root 8, 0 Jan 1 1970 disc
brw------- 1 root root 8, 1 Jan 1 1970 part1
brw------- 1 root root 8, 2 Jan 1 1970 part2
brw------- 1 root root 8, 3 Jan 1 1970 part3
root@DD-WRT:~#
Actual name of partition 3 would be:
/dev/scsi/host0/bus0/target0/lun0/part3


Examples of mount commands can also be found at:
this forum post: how to access USB drive from WL500gP w/ DD-WRT v24 mega?
and at Usage

Step 4 - Mount the drive/partitions

You need to mount the drive/partition, using the information you found using the dmesg command, and add a /part1 at the end of the string.
For easy use with Optware packages (where you can easily get ie. Samba, FTP and more), it is recommended that you mount your new partition as /opt

For a HD this command can be used to mount the partition (ex. for wl500gP v1)
mount   /dev/scsi/host0/bus0/target0/lun0/part1   /opt 
For a USB flash drive this command can be used to mount the partition
mount   -o noatime  /dev/scsi/host0/bus0/target0/lun0/part1  /opt
The '-o noatime' option means: "Do not update inode access times on this file system".
This may cause less writing to the flash drive, thus lengthening its life span.

For drives with three partitions the Data Partition could be mounted as /mmc

mount  /dev/scsi/host0/bus0/target0/lun0/part3   /mmc


Note: If you plan to do much testing of installing software, you may consider mounting the first drive as /mnt, and then makeing test sub-directories/folders for /opt monunts, as this will give you a quick way of switching the entire /opt folder system from one to another test setup (see Step 5.1 for example).


Step 5 - Auto mount partion at boot-time

If you want the drive/partion to be auto mounted every time you boot your router, you need to:

option a) enable jffs (a user accesable partition on the built-in flash EEPROM of the router) , and store a startup script in the /jffs/etc/config folder
option b) or save the the command to mount a partition in NVRAM As well as save the the command to run the usb.startup in NVRAM


For a) look at the jffs: Directions for using Web-GUI to enable the jffs partition. Then store usb.startup script in the /jffs/etc/config folder

After enabling the jffs partition (and rebooting your router) to download the script you need to : Write the following commands in a telnet/ssh session:

mkdir /jffs/etc
mkdir /jffs/etc/config
cd /jffs/etc/config
wget http://www.3iii.dk/linux/dd-wrt/usb.startup 
chmod +x usb.startup

Example of the usb.startup script

#!/bin/sh 

# Mount partition 1 as /opt folder - then wait for the drive to mount
  mount /dev/scsi/host0/bus0/target0/lun0/part1 /opt 
  sleep 5 

# set path so optware binaries are automatically found as new commands
  echo "export PATH=$PATH:/opt/bin:/opt/sbin" > /tmp/root/.profile 
  export PATH=$PATH:/opt/bin:/opt/sbin 

# option for auto-starting standard Samba2 Optware install
  /opt/etc/init.d/S80samba start
  
# method for auto-running scripts found in /opt/etc/config folder
  for I in `/bin/ls /opt/etc/config/*.startup`
  do
     sh $I &
  done 

For b) look at the Startup Scripts page

Short version: in web_GUI goto tab:Administration -> tab:Commands -> type your commands in the text window -> click:Save Startup

You need to add the mount command to the NVRAM stored startup script, only add "&" to the end of the command. You can mount the /opt folder on a wl500gP v1 with the following command:

mount   /dev/scsi/host0/bus0/target0/lun0/part1   /opt   &
Step 5.1 - Alternativ Auto mount at boot-time

Save in NVRAM using web-GUI -> Administration -> Commands

mount   /dev/scsi/host0/bus0/target0/lun0/part1   /mnt   &
sleep 3
sh /mnt/etc/config/begin-here.startup

Click: Save Startup

Make the following folders:

mkdir /mnt/etc
mkdir /mnt/etc/config
mkdir /mnt/test1
mkdir /mnt/main-opt
mkdir /mnt/org-opt

Save the following script to the /mnt/etc/config folder as file begin-here.startup

#!/bin/sh 

# Mount /opt to one of the options - then wait for the drive to mount
  mount /mnt/test1 /opt 
  #mount /mnt/org-opt /opt
  #mount /mnt/main-opt /opt
  sleep 3 

Make the script run-able/executeable by the boot process using chmod command

chmod +x /mnt/etc/config/begin-here.startup

Step 6 - Downloading extra Software Packages

Now you need to activate Samba, FTP or NFS systems to be able to share your USB mounted drive/partition over the network.

These software packages are not pre-installed on DD-WRT, so you need to get them from either OpenWRT or Optware.

option a) You can download packages from OpenWRT using the ipkg commands, these packages are directly designed for the OpenWRT system, but many will run on a DD-WRT box, and all will run with minor modifications, as DD-WRT is made to be as compatible with OpenWRT as possible.
option b) Once the initial Optware files are setup (see step 6.1) you can download the Optware packages using the ipkg-opt commands. Optware has cross-compiled almost all of their 1000+ packages specifically to fit DD-WRT needs. Optware also uses the ipkg system to download and setup their packages (NSLUG/Optware invented the ipkg system!), but for Optware on DD-WRT it is recommended to use the DD-WRT - Optware adapted ipkg-opt.

Note: once the initial optware files are installed, then using "ipkg-opt" or "/opt/bin/ipkg" ensures the corret optware result. If you just use "ipkg" you also have to look at your PATH to know which of these two files ("/bin/ipkg" or "/opt/bin/ipkg") are actually used.

See: more at Ipkg tutorial and Optware tutorial

Step 6.1 - Extra software the Optware way

Once you have mounted an /opt folder, then either of the following ways, will install the basic Optware files

wget http://pastebin.ca/raw/1031954 -O - | tr -d '\r' > /tmp/optware-install.sh 

or

wget http://www.wlan-sat.com/boleo/optware/optware-install-ddwrt.sh -O - | tr -d '\r' > /tmp/optware-install.sh 


Note: If your are still having trouble getting the script to run, then you might chance it and edit the /tmp/optware-install.sh script, by adding a # in front of the _check_config line at the buttom of the script. Should then be like this:

<snip>
#_check_config
_install_package uclibc-opt_0.9.28-13_mipsel.ipk
_install_package ipkg-opt_0.99.163-10_mipsel.ipk
</snip>

Then move to /tmp folder, and issue command

sh optware-install.sh

/Note

Note2: Having installed Optware packages, you should also make the following changes to your system. Create /opt/etc/profile file with the following content

export PATH=/opt/bin:/opt/sbin:/bin:/sbin:/usr/bin:/usr/sbin
export PS1='\u@\h:\w\$ '

[ -x /opt/bin/less ] ||  alias less=more
[ -x /opt/bin/vim ] ||  alias vim=vi
 

arp() { cat /proc/net/arp; }
ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; }
reboot() { killall nmbd
          killall smbd
          killall xinetd
          killall thttpd
          sleep 1
          umount /opt
          umount /mnt
          /sbin/reboot 
         }

You should also modify the begin-here.startup file (mentioned in Step 5) to look like this:

#!/bin/sh 

unset LD_LIBRARY_PATH
unset LD_PRELOAD

# Mount /opt to one of the options - then wait for the drive to mount
 mount /mnt/test1 /opt 
 #mount /mnt/org-opt /opt
 #mount /mnt/main-opt /opt
 sleep 3 

#Update stock profile to Optware optimized profile
[ -e /opt/etc/profile ] && mount -o bind /opt/etc/profile /etc/profile

/Note2

Read more at the optware wiki entry to see which software packages to install, like Samba, FTP, Torrent client, extra HTTP server and more.

Step 7 - Auto-run the extra software at boot-time

Add some way of auto-running optware software like Samba at boot-up time

method a) Start your extra software directly from the NVRAM stored commands (see Startup_Scripts), or better yet
method b) Start your different systems from one script that calls another script, and just call ONE initial script from the NVRAM stored command, see Step 5.1
method c) acttivate jffs2 and place you startup scrits in /jffs/etc/config, as scripts in this folder automatically are run when your rooter is booted (see: jffs of how to enable jffs).

To access a networked printer

check [Printer sharing]

2.1 you need to make sure it is recognized by dd-wrt

2.2 You may need to adjust start-up scripts so the printer is correctly initialized

2.3 You need to install the correct printer driver on you pc's OS

2.4 You need to connect the printerdriver of your pc to the networked usb printer

Installation (for non-Mega versions of DD-WRT)

Prerequisites

To install the USB Kernel modules, a couple of initial steps are required (this assumes a new install starting with DD-WRT default settings).

1. Enable JFFS

  • You will need ~650KB of free storage space in JFFS -- if you don't have enough free space, consider the mini or micro versions of DD-WRT.

2. Ensure the ipkg temporary directory is created (otherwise the update command will fail)

  • Telnet/SSH to the WRT
 # mkdir -p /jffs/tmp/ipkg

3. Update ipkg package list

 # ipkg update

Install USB Kernel modules

If your kernel is still 2.4.30 (older versions of dd-wrt -> see output of uname -a):

 ipkg install kmod-usb-uhci // this is for USB 1.1 (only required if your router does not support USB 2)
 ipkg install kmod-usb-core
 ipkg install kmod-usb2
 ipkg install kmod-usb-storage

If your kernel is newer than 2.4.30:

 ipkg -force-depends install kmod-usb-core kmod-usb2 kmod-usb-storage

This has been tested with kernel 2.4.35 and it did work .....

For the Asus WL-520GU, you will also need the kmod-usb-ohci package:

 ipkg -force-depends install kmod-usb-ohci

Manual installation and check

  • insert the modules one by one by following commands in a telnet session.
 insmod /jffs/lib/modules/2.4.30/usbcore.o
 insmod /jffs/lib/modules/2.4.30/ehci-hcd.o
 insmod /jffs/lib/modules/2.4.30/scsi_mod.o
 insmod /jffs/lib/modules/2.4.30/usb-storage.o
 insmod /jffs/lib/modules/2.4.30/sd_mod.o
  • for the ASUS WL-520GU, use the usb-ohci driver instead of ehci-hcd
 insmod /jffs/lib/modules/2.4.30/usbcore.o
 insmod /jffs/lib/modules/2.4.30/usb-ohci.o
 insmod /jffs/lib/modules/2.4.30/scsi_mod.o
 insmod /jffs/lib/modules/2.4.30/usb-storage.o
 insmod /jffs/lib/modules/2.4.30/sd_mod.o

Check

  • See the enabling from dmesg output of a Linksys WRTSL54GS. A SanDisk Cruzer Micro 4G flash drive as recognized.
 # dmesg
 <snip>
 <6>ehci_hcd 01:02.2: PCI device 1033:00e0
 <6>ehci_hcd 01:02.2: irq 2, pci mem c0181000
 <6>usb.c: new USB bus registered, assigned bus number 1
 <6>ehci_hcd 01:02.2: USB 2.0 enabled, EHCI 1.00, driver 2003-Dec-29/2.4
 <6>hub.c: USB hub found
 <6>hub.c: 5 ports detected
 <6>hub.c: new USB device 01:02.2-1, assigned address 2
 <4>usb.c: USB device 2 (vend/prod 0x781/0x5406) is not claimed by any active driver.
 <6>SCSI subsystem driver Revision: 1.00
 <6>Initializing USB Mass Storage driver...
 <6>usb.c: registered new driver usb-storage
 <6>scsi0 : SCSI emulation for USB Mass Storage devices
 <0>  Vendor: SanDisk   Model: U3 Cruzer Micro   Rev: 2.18
 <0>  Type:   Direct-Access                      ANSI SCSI revision: 02
 <0>  Vendor: SanDisk   Model: U3 Cruzer Micro   Rev: 2.18
 <0>  Type:   CD-ROM                             ANSI SCSI revision: 02
 <7>WARNING: USB Mass Storage data integrity not assured
 <7>USB Mass Storage device found at 2
 <6>USB Mass Storage support registered.
 <0>Attached scsi removable disk sda at scsi0, channel 0, id 0, lun 0
 <0>SCSI device sda: 8015505 512-byte hdwr sectors (4104 MB)
 <0>sda: Write Protect is off
 <6>Partition check:
 <6> /dev/scsi/host0/bus0/target0/lun0: p1 p2 p3
 #

Create a startup script that loads the modules

Create a file, usb.startup in /jffs/etc/config/ directory

~ # mkdir /jffs/etc/config
~ # vi /jffs/etc/config/usb.startup

that contains this (press i once for insert mode):

#!/bin/sh
insmod /jffs/lib/modules/2.4.30/usbcore.o
insmod /jffs/lib/modules/2.4.30/ehci-hcd.o
# WL-520GU users - add a dash (#) to the line above, and remove the dash (#) from the line below
#insmod /jffs/lib/modules/2.4.30/usb-ohci.o
insmod /jffs/lib/modules/2.4.30/scsi_mod.o
insmod /jffs/lib/modules/2.4.30/usb-storage.o
# remove the dash (#) from the line below if you use USB 1.1
#insmod /jffs/lib/modules/2.4.30/uhci.o
insmod /jffs/lib/modules/2.4.30/sd_mod.o

vi is ended using "ESC" and then :wq

make the script executable:

 chmod +x /jffs/etc/config/usb.startup

For DD-WRT v23 SP1 or below

add the follwing script to startup. It executes on every reboot all *.startup scripts located in /jffs/etc/config/

console mode

 > ~ # nvram set rc_startup="
 > for I in `/bin/ls /jffs/etc/config/*.startup`
 > do
 >    sh $I &
 > done
 > "
 > ~ # nvram commit
 >

web interface mode

 for I in `/bin/ls /jffs/etc/config/*.startup`
   do
     sh $I &
 done


This is it. Here's my dmesg from Asus WL-500gP

 dmesg
 SCSI subsystem driver Revision: 1.00
 Initializing USB Mass Storage driver...
 usb.c: registered new driver usb-storage
 USB Mass Storage support registered.
 uhci.c: USB Universal Host Controller Interface driver v1.1
 PCI: Enabling device 01:03.0 (0000 -> 0001)
 uhci.c: USB UHCI at I/O 0x100, IRQ 2
 usb.c: new USB bus registered, assigned bus number 2
 hub.c: USB hub found
 hub.c: 2 ports detected
 PCI: Enabling device 01:03.1 (0000 -> 0001)
 uhci.c: USB UHCI at I/O 0x120, IRQ 2
 usb.c: new USB bus registered, assigned bus number 3
 hub.c: USB hub found
 hub.c: 2 ports detected

kernel modules for filesystems

Now to access FAT/EXT/XFS partitions you must install

 ipkg install kmod-vfat
/mnt # ipkg install kmod-vfat
ipkg_depends: Warning: kernel mentioned in dependency but no package found in //jffs/usr/lib/ipkg/lists

Downloading http://downloads.openwrt.org/whiterussian/packages/kmod-vfat_2.4.30-brcm-5_mipsel.ipk ...
Connecting to downloads.openwrt.org[195.56.146.238]:80
kmod-vfat_2.4.30-brc 100% |********************************************| 32018    --:--:-- ETA
Done.
ipkg_depends: Warning: kernel mentioned in dependency but no package found in //jffs/usr/lib/ipkg/lists
Unpacking kmod-vfat...Done.
Configuring kmod-vfat...Done.
/mnt #

  
  Check what got installed.
/mnt # ipkg files kmod-vfat
/jffs
/jffs/lib
/jffs/lib/modules
/jffs/lib/modules/2.4.30
/jffs/lib/modules/2.4.30/vfat.o
/jffs/lib/modules/2.4.30/fat.o
/jffs/etc
/jffs/etc/modules.d
/jffs/etc/modules.d/30-vfat
/mnt #

   
 ipkg install kmod-ext2
 ipkg install kmod-ext3
 ipkg install kmod-xfs

autoload filesystem modules

This part is very confusing. So I should add the filesystem modules to usb.startup? Where should I add them? Can somebody clear this up?


Add to /jffs/etc/config/usb.startup (comment out lines you don't need to save memory)

 /mnt # cat /jffs/etc/config/usb.startup
 #!/bin/sh
 insmod /jffs/lib/modules/2.4.30/usbcore.o
 insmod /jffs/lib/modules/2.4.30/ehci-hcd.o
 # WL-520GU users - add a dash (#) to the line above, and remove the dash (#) from the line below
 #insmod /jffs/lib/modules/2.4.30/usb-ohci.o
 insmod /jffs/lib/modules/2.4.30/scsi_mod.o
 insmod /jffs/lib/modules/2.4.30/usb-storage.o
 # remove the dash (#) from the line below if you use USB 1.1
 #insmod /jffs/lib/modules/2.4.30/uhci.o
 insmod /jffs/lib/modules/2.4.30/sd_mod.o
 /mnt #

the following lines:

 # Filesystems
 # Ext2
 insmod /jffs/lib/modules/2.4.30/ext2.o
 # Ext3
 insmod /jffs/lib/modules/2.4.30/jbd.o
 insmod /jffs/lib/modules/2.4.30/ext3.o
 # FAT
 insmod /jffs/lib/modules/2.4.30/fat.o
 insmod /jffs/lib/modules/2.4.30/vfat.o
 # XFS
 #insmod /jffs/lib/modules/2.4.30/xfs.o

Now dmesg should show (The example below is from a 80 GB HD)

 Attached scsi disk sda at scsi0, channel 0, id 0, lun 0
 SCSI device sda: 156301488 512-byte hdwr sectors (80026 MB)
 Partition check:
 /dev/scsi/host0/bus0/target0/lun0

Multislot card reader

In order to use some multislot card readers, you must add the following parameter to the scsi_mod in the file /jffs/etc/modules.d/60-usb-storage:

scsi_mod max_scsi_luns=8

Note that this is model-dependent; some multislot readers do treat each slot as an independent drive and even allow them to be used simulentaneously.

Usage

Mounting

mount /dev/scsi/host0/bus0/target0/lun0/part1 /mnt

You can also add the above line to /jffs/etc/config/usb.startup to mount the partition on reboot

cn0rris: I had to add a sleep 1 before the mount to get it to mount reliably.

WL-520GU Users: If you use this script, make sure to replace ehci-hcd.o with usb-ohci.o

Manuel: I use usb-ohci.o for the wrt350n.

An example /jffs/etc/config/usb.startup file for use on a device with JFFS, Optware and all USB storage modules already installed:

#!/bin/sh
#
#Load various modules for USB, hard drive, printer/scanner support - omit any of these that aren't being used:
insmod /jffs/lib/modules/2.4.30/usbcore.o
insmod /jffs/lib/modules/2.4.30/ehci-hcd.o
insmod /jffs/lib/modules/2.4.30/scsi_mod.o
insmod /jffs/lib/modules/2.4.30/usb-storage.o
insmod /jffs/lib/modules/2.4.30/sd_mod.o
insmod /jffs/lib/modules/2.4.30/fat.o
insmod /jffs/lib/modules/2.4.30/vfat.o
insmod /jffs/lib/modules/2.4.30/ext2.o
insmod /jffs/lib/modules/2.4.30/ext3.o
insmod /jffs/lib/modules/2.4.30/printer.o
insmod /jffs/lib/modules/2.4.30/sg.o
insmod /jffs/lib/modules/2.4.30/scanner.o
sleep 2
#
# Use first partition on first USB hard drive for Optware package storage
mount /dev/discs/disc0/part1 /opt
unset PATH
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/opt/bin:/opt/sbin:/jffs/sbin:/jffs/bin:/jffs/usr/sbin:/jffs/usr/bin
unset LD_LIBRARY_PATH
#
# Enable if using network servers such as SANE or e-mail services
# xinetd
#
# Enable these if using Samba, a Windows-compatible networking package, to share disc drives or CUPS printers:
# nmbd
# smbd
#
# To enable local network access to the USB-attached printer(s), use one (and only one) of the following:
# cupsd
# /jffs/usr/sbin/p910nd -b -f /dev/usb/lp0 0
#
# Note that these paths appear not to be exported, so you will want to add /opt/bin and /opt/sbin to your PATH elsewhere:
PATH=/opt/bin:/opt/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/jffs/sbin:/jffs/bin:/jffs/usr/sbin:/jffs
export LD_LIBRARY_PATH=/opt/lib:/opt/usr/lib:/lib:/usr/lib:/jffs/lib:/jffs/usr/lib:/jffs/usr/local/lib
#
# Enable this *only* if a swapfile has already been created on a USB hard drive and prepared for use:
# swapon /opt/var/swapfile
#
# Mixing packages from Optware and other sources may lead to conflicts between libraries, so unset libpath as a precaution:
unset LD_LIBRARY_PATH
export LD_LIBRARY_PATH

The disc drives will also appear as /dev/discs/disc0/part1 and other corresponding numbers in this series (a symbolic link). Drive 0 nominally appears as the first disc located on startup, typically the drive on the first port of a USB hub. USB card readers may appear as multiple discs if they support multiple card types.

The .../part1 through .../part4 are individual primary partitions on a drive, which may be formatted as any of VFAT (DOS/Windows), ext2 or ext3 (Linux native) or Linux swap. It is most often easier to partition and format a USB drive on a desktop PC (preferably a computer with Linux installed, as Windows is limited to creating 32Gb VFAT partitions) before moving it to your embedded device.

Manuel: I had problems with dd-wrt detecting only one partition of a three ext2 partition disk and then refusing to mount. After using gparted to set the "partition table type" (or the "disk label") in "device" menu to ms-dos, the problem went away and the three partitions in the disk were recognized and mounted without problems. I also tried this with the hfsplus filesystem but could only mount read-only on dd-wrt.

Performance Testing

With help of the hdparm package you could test your performance. On an Asus WL-500gP(remium) without overclocking you will get

hdparm -tT /dev/scsi/host0/bus0/target0/lun0/part2
Timing cached reads:   188 MB in  2.04 seconds =  92.16 MB/sec
Timing buffered disk reads:   24 MB in  3.19 seconds =   7.52 MB/sec


Please note overclocking wouldn´t get you significant more performance on Asus WL-500gP(remium) Router.

On a WRTSL54G with 4G flash disk

/ # hdparm -tT /dev/scsi/host0/bus0/target0/lun0/part2

/dev/scsi/host0/bus0/target0/lun0/part2:
 Timing cached reads:   148 MB in  2.03 seconds =  72.91 MB/sec
 Timing buffered disk reads:   24 MB in  3.22 seconds =   7.45 MB/sec
/ #

On a WRT350N with 2GB SanDisk Cruzer Titanium flash disk

/ # hdparm -tT /dev/scsi/host0/bus0/target0/lun0/part1

/dev/scsi/host0/bus0/target0/lun0/part1:
 Timing cached reads:   196 MB in  2.01 seconds =  97.51 MB/sec
 Timing buffered disk reads:   28 MB in  3.04 seconds =   9.21 MB/sec
/ #

Listing Contents

ls -l /mnt
# multiple partitions
mkdir /tmp/usb
mkdir /tmp/usb/1
# wait to recognize devices properly
sleep 2
# mount first partition
/bin/mount /dev/scsi/host0/bus0/target0/lun0/part1 /tmp/usb/1
# list its contents
ls -l /tmp/usb/1
# second partition
mkdir /tmp/usb/2
mount /dev/scsi/host0/bus0/target0/lun0/part2 /tmp/usb/2
# list its contents
ls -l /tmp/usb/2

If you're having trouble

If you still cannot get your USB drive to mount after following these instructions to the letter, you can try resetting the NVRAM. Do this by using the recovery utility to upload the bin/trx file meant for that purpose.

NOTE: This has miraculously solved problems on an ASUS WL-500G Premium. Your mileage may vary, especially if you have a different router.