USB on ASUS WL500GPV2

From DD-WRT Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 21:19, 6 November 2009 (edit)
Masterman (Talk | contribs)
(Command Line Configuration)
← Previous diff
Revision as of 21:20, 6 November 2009 (edit) (undo)
Masterman (Talk | contribs)
(Command Line Configuration)
Next diff →
Line 51: Line 51:
= Command Line Configuration = = Command Line Configuration =
-See [[Frater's no hassle, newbie friendly Optware]] for a much more user friendly approach+See [http://www.dd-wrt.com/wiki/index.php/USB_on_ASUS_WL500GPV2#Frater.27s_no_hassle.2C_newbie_friendly_Optware Frater's no hassle, newbie friendly Optware] for a much more user friendly approach

Revision as of 21:20, 6 November 2009

Contents

Introduction

This short How To is intended to walk someone through configuring a basic USB printer and a USB storage device (specifically USB flash drive) on their ASUS WL-500G Premium v2 (WL500GPV2) router. There are great USB how to articles on the DD-WRT wiki and I am sure that a lot of information in this article is duplicated elsewhere. Nevertheless, a lot of the guides I found only solved a piece of the puzzle. This article intends to bring all of that information into a single URL.

Firmware

I highly recommend a fresh firmware flash and a clearing of the NVRAM, starting with a clean slate will provide the smallest chance of encountering a random problem. Flash your WL500GPV2 router with either the latest DD-WRT Mega firmware (v24 SP2) or the Eko DD-WRT NEWD or NEWD-2 mini USB, or Big build releases that include full USB support. If ising a mini firmware package, consider the following:

Why bother with the reduced functionality of a mini build when this router has 8MB flash? Well, there are several advantages. The mini is a fraction of the size, yet provides the vast majority of the functionality of the larger builds. For this small sacrifice, you get a much more lean and efficient setup, including...

  • A nearly 5.0MB JFFS2 partition
  • Nearly 90% free system memory on a fully configured system
  • Full USB support, easily enabled from the web GUI (just like Mega)
  • Faster, leaner (Merely observational, but noteworthy)
If you want to use USB it is good idea to use Eko's modified firmware instead of original, because
there have important fixes for the Broadcom BCM5354 CPU. It improves stability of USB devices. 

Firmware

BrainSlayer Builds

Use builds with a date August 3rd 2009 or higher. Once build of choice is selected, navigate to the broadcom section and choose your build. If planning to enable JFFS2, do NOT flash with these builds! Use the Eko builds listed below


Eko Builds

These are the preferred builds for Asus routers. Use SVN 12548 or higher. NEWD-2 builds will work for the WL500gP v2 but NOT the WL500gP v1!!!

Initial Prep

  1. Complete your standard WAN, LAN, DHCP configuration so that your router has working Internet access
    Note: This guide will not explain these details, since they are very well documented elsewhere
  2. Under Services, enable:
    Secure Shell (SSHd)
    Telnet (optional, select this if you have no idea how to connect to an SSH server)
    USB modules which you need to enable under Services->USB (Core USB support, UHCI, OHCI, USB 2.0, USB Storage, ext2/ext3, FAT, USB Printing)

For example, if you only want to install Limited Optware packages on 2.0 device you can enable : Core USB support, USB 2.0, USB Storage, ext2/ext3 FS support.

  1. Save & then Apply Settings
  2. Under Administration > Management:
    Enable JFFS2 Support
    Clean JFFS2
  3. Save & then Apply Settings
  4. Reboot Router


NOTE

If pursuing more dynamic and more advantageous properties of Optware, do NOT enable JFFS2. Read the rest of this tutorial to find out the amazing things you can do with an external storage device and a printer.

Command Line Configuration

See Frater's no hassle, newbie friendly Optware for a much more user friendly approach


Now that we have JFFS2 and command line access via SSH, lets connect to the router and perform the core of the configuration. This section is a little more advanced and some Unix/Linux experience will help reduce the chance of a cockpit error.

  • SSH to your router's internal IP address, by default this is the 192.168.1.1 address and login with the web admin credentials (default is root/admin)
    alternatively, if you enabled Telnet you can connect via the Windows built-in telnet client
  • verify that the JFFS2 partition is mounted
root@DD-WRT:/jffs# mount | grep -i jffs
/dev/mtdblock/4 on /jffs type jffs2 (rw)
  • Update the ipkg package list
ipkg update

The last line of the output should be similar to this

Updated list of available packages in /jffs/usr/lib/ipkg/lists/backports

Note: For me, the first time I run ipkg update I always get errors. Try exiting out of SSH/Telnet by pressing Ctrl-C, typing "exit", and reconnecting - if that doesn't work, then reboot the router. It has worked every time for me.

  • Install the Print Server package to your JFFS2 partition
ipkg -d root install p910nd

Note: You may be tempted to install your ipkg software to a Samba mount point, USB flash/hard disk, SD card or some other place aside from the limited JFFS2 file system. This is of course your choice, and may seem the logical one, but there are several advantages to using the JFFS2 partition. For one, the JFFS2 partition always mounts. Being internal to the router, it is the most reliably detected and mounted file system at your disposal. Installing the Print Server and associated configuration pieces adds < 400K and regular usage entails no writes as far as I have observed.

  • The core of the Print Server is a single binary. Verify that the Print Server package installed the binary in the proper location.
root@DD-WRT:/# ls -l /jffs/usr/sbin/
-rwxr-xr-x    1 root     root         8563 Mar 26  2006 p910nd
  • Verify that dd-wrt Linux has detected your USB printer
root@DD-WRT:/# ls -l /dev/usb
crw-rw----    1 root     root     180,   0 Jan  1 00:00 lp0
root@DD-WRT:/#

Note: lp0 means line printer 0 was properly detected by the dd-wrt Linux kernel. So far, so good.

  • Set the Print Server binary to start automatically on boot with the correct command line parameters.
mkdir -p /jffs/etc/config
echo "/jffs/usr/sbin/p910nd –b –f /dev/usb/lp0 0" >  /jffs/etc/config/usb.startup
chmod +x /jffs/etc/config/usb.startup

Note: The contents of usb.startup will be executed automatically at boot, there is nothing you have to do to enable this, other than create the file and give it execute permissions (shown above)

  • Reboot the Router

Note: Before rebooting the router, unmount the jffs partition (umount /jffs) to make sure all changes have been committed to flash. I have found that a web GUI reboot does not always unmount the JFFS2 partition and I have experienced data loss.

Verify the Print Server is Running

  • SSH to the router
  • See if Print Server process is running
root@DD-WRT:/mnt# ps | grep p91
596 root       348 S    /jffs/usr/sbin/p9100d -b -f /dev/usb/lp0 0

and...

root@DD-WRT:/mnt# netstat -an | grep 910
tcp        0      0 0.0.0.0:9100            0.0.0.0:*               LISTEN

If it doesn't work, see this page for more detailed info (not all is relevant to the mega versions): http://www.dd-wrt.com/wiki/index.php/USB_printer_sharing

Configure the Printer from a Windows/Linux Client

  • From Windows, go to Control Panel, Printers, Add Printer
  • Choose Local, create new port Standard TCP/IP Port
  • Set Device Type to TCP/IP
  • For Hostname or IP field, set to router IP
  • On Vista, do not query printer for driver
  • On next screen, click custom
  • Manually select the printer from list or select Have Disk to add a new printer driver
  • Note: On Vista, many newer HP Deskjet printers can be set to HP Deskjet 990c since no Vista drivers are available from HP.

Adding USB Storage

Obviously you wouldn't be here if you hadn't bought a router with TWO USB ports, so why not make the absolute best out of what you paid for? You can use many types of storage devices such as Hard disks and flashdrives.

It is important to understand that only Linux filesystems (ext2 or 3) and FAT are supported by this router.

If you just want to share your files over FTP or your network places, FAT will work fine. However, the benfits of Optware are the best thing since sliced bread!

To make the following work, you must format and partition the drive to a linux filesystem. I have made it as simple as possbile on how to do this, so don't give up! It doesn't take alot of technical skill and is fairly easy if you follow the directions.


NOTE ALL external harddisks MUST be self powered. Do NOT use a portable external! Flashdrives are fine. You can even use a USB hub to connect several devices to the router.


Frater's no hassle, newbie friendly Optware

This is the latest, greatest and easiest way to enable Optware on your Router. It is recommended that you have a router with USB capable storage (Harddisk, flashdrives etc.), although SD/MMC Mods are working. Also, you wont be needing JFFS2, so DISABLE it.


Services that will be installed:


  • Bash instead of shell in busybox (LFS support)
  • Automounting and unmounting of storage device partitions
  • Network printing
  • Torrent transmission with watchdog
  • Hotmount
  • Pre-configured samba share
  • Reverse proxy featuring pound
  • Service tool
  • Xinetd
  • Pound
  • Asterisk
  • Lighttpd
  • Vlighttpd
  • Countryblock
  • Services running as other users than root
  • Vim with proper terminal support


In my opinion, Everyone with a router that has storage device capabilities should take advantage of this! You will NOT regret it, even if it can be a time consuming process!


Getting Started

If starting from scratch, you will need to first format and partition your harddisk, flashdrive or SD card to an EXT2 or EXT3 Linux filesystem. It is much easier than you think, and can be accomplished via a Linux Live boot-CD. There will be NO changes to your PC whatsoever, and it is very simple to implement.


My personal favorite is Ubuntu as it provides a very user friendly interface and can be understood in a matter of minutes no matter what OS you use (Windows, MAC etc) and not to mention Firefox is already installed. Just download the free for life version of your choice (32 or 64 bit) from the above link, and use a burning software like Nero to burn the Image to a CD. After that, simply pop the disc into your CD/DVD drive and reboot.


If your PC BIOS settings are set like they should be (first drive to boot should be the CD/DVD drive), then sit back and wait for it to load.


It will then prompt you for language selection, and then the query prompt will proceed. Default is "Try Ubuntu without any changes to your computer." Hit enter and let it load.


Once in Ubuntu, connect the drive you wish to format and partition. Once completed, navigate to the browsing menu at the top of the screen and look for applications, then click Terminal


Once in the Terminal window, read the following directions and enter the following commands:


NOTE: All BOLD text in this Wiki will be the commands that you enter.


Type sudo su - as this allows you to become root, or full administrator of the machine.


Using the fdisk command, you will be creating four partitions:

  • sd?1 - the /opt partition, where Optware will reside.
  • sd?2 - the swap partition, where Linux will swap jobs.
  • sd?3 - the /jffs partition
  • sd?4 - the data partition, which you will share via Samba or FTP.

NOTE The ?'s are the drive letters Linux assigns. You will need to determine which one is correct by issuing the command dmesg | more (Keep Hitting enter to continue readout). You will be looking for the disk you want to format. Here is an example of what it should look like:


scsi0 : SCSI emulation for USB Mass Storage devices
Vendor: WD        Model: 1600BEV External  Rev: 1.05
Type:   Direct-Access                      ANSI SCSI revision: 02
Attached scsi disk sdb at scsi0, channel 0, id 0, lun 0
SCSI device sdb: 312581808 512-byte hdwr sectors (160042 MB)


Another more user friendly way is to use Ubuntu's GParted tool, which is located in System->Administration->Partition Editor. Here you can either use it to identify the drive letter of the disk, or you can Partition it.


It's important to understand everyone's disk drive configuration will be different. If your drive is 40 GB or smaller, use the smaller set of partition sizes below. If your drive is over 40 GB, you can use the larger set of partition sizes.

Disk 40 GB or less


  • /opt 256 megabytes
  • swap 32 megabytes
  • /jffs 128 megabytes
  • data remainder of the disk

Disk greater than 40 GB


  • /opt 512 megabytes
  • swap 64 megabytes
  • /jffs 256 megabytes
  • data remainder of the disk


NOTE For smaller storage devices such as SD/MMC and flash drives, the minimum partition size for /opt should be 256MB


Also the /jffs partition is not necessary if you are only installing this Optware.


Code: (the ? are the drive letters (c,d,e etc.) so make sure you choose the correct one!) The bold texts are the commands

fdisk /dev/sd?
Command (m for help): p 
Disk /dev/sd?: 64 heads, 63 sectors, 621 cylinders
Units = cylinders of 4032 * 512 bytes
Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-621, default 1):<HIT ENTER>
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-621, default 621): +512M <HIT ENTER>
Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (197-621, default 197):<HIT ENTER>
Using default value 197
Last cylinder or +size or +sizeM or +sizeK (197-621, default 621): +64M <HIT ENTER>
Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (197-621, default 197):<HIT ENTER>
Using default value 621
Last cylinder or +size or +sizeM or +sizeK (197-621, default 621): +128M <HIT ENTER>
Command (m for help): n
Command action
  e   extended
  p   primary partition (1-4)
p
Partition number (1-4): 4
First cylinder (197-621, default 197):<HIT ENTER>
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (197-621, default 621): <HIT ENTER>
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 82
Changed system type of partition 2 to 82 (Linux swap)      
Command (m for help): p
Disk /dev/sd?: 64 heads, 63 sectors, 621 cylinders
Units = cylinders of 4032 * 512 bytes
Device Boot    Start       End    Blocks   Id  System
/dev/sd?1   *         1       196    395104+  83  Linux
/dev/sd?2           197       262    133056   82  Linux swap
/dev/sd?3           263       458    395136   83  Linux
Command (m for help): w

If you get a message saying that the current table is in use and will be executed on next reboot, then do it! Make SURE though after rebooting that when you open the terminal for the next sequence of commands, do a sudo su - followed by an fdisk /dev/sd? and type p as this will verify the partition table


Continuing:


Formatting the /opt, /jffs and data partitions, and preparing the swap partition

mke2fs -j -m 1 -L Optware /dev/sd?1

mke2fs 1.18, 11-Nov-1999 for EXT2 FS 0.5b, 95/08/09
Filesystem label=Optware
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
122112 inodes, 243964 blocks
12198 blocks (5.00%) reserved for the super user
First data block=0
8 block groups
32768 blocks per group, 32768 fragments per group
15264 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Writing inode tables: done
Writing superblocks and filesystem accounting information: done

mke2fs -j -m 1 -L Shared /dev/sd?3

mke2fs 1.18, 11-Nov-1999 for EXT2 FS 0.5b, 95/08/09
Filesystem label=Shared
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
122112 inodes, 243964 blocks
12198 blocks (5.00%) reserved for the super user
First data block=0
8 block groups
32768 blocks per group, 32768 fragments per group
15264 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Writing inode tables: done
Writing superblocks and filesystem accounting information: done

mke2fs -j -m 1 -L Data /dev/sd?4

mke2fs 1.18, 11-Nov-1999 for EXT2 FS 0.5b, 95/08/09
Filesystem label=Data
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
122112 inodes, 243964 blocks
12198 blocks (5.00%) reserved for the super user
First data block=0
8 block groups
32768 blocks per group, 32768 fragments per group
15264 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Writing inode tables: done
Writing superblocks and filesystem accounting information: done


mkswap /dev/sd?2


Now your disk drive is partitioned and formatted for Linux! If you are a windows user, you can either proceed (recommended) using Linux (Ubuntu comes with FireFox already installed) or shut down the Linux distro you used, and make sure the boot disk pops out, as you wll need to get back to windows.


Connecting the Drive to your Router

1. In the DD-WRT web GUI screen, on the Services USB tab enable the options for:

  • Core USB support
  • USB 2.0 support
  • USB storage support
  • Printer Support (optional)
  • ext2/ext3 File System support


2. From the DD-WRT web GUI screen, click on Apply Settings. This will reboot the router.


3. There are several methods of doing this. Once you have all your partitions set on the external device, add this to your Start-up script in Administration->Commands

Startup script (make sure you install to the/opt partition. Replace the ? after ..lun0/part with the appropriate partition number that /opt is designated. It SHOULD be 1)

sleep 10 && mount -t ext3 /dev/scsi/host0/bus0/target0/lun0/part? /opt &
n=1
while [ ! -d /opt/etc/init.d ] ; do
 sleep 3
 [ $n -gt 30 ] && break
 let n+=1
done
/opt/etc/init.d/optS

Click Save Startup


Shutdown script:

/opt/etc/init.d/optK

Click Save Shutdown


Give the router a minute or two to process and reboot.


Alternative (easier):

Web Interface Method:

Go to Services->USB. Enable USB Core support, USB 2.0 Support, USB Printer Support, USB Storage Support, Ext2/3 support, FAT File System Support (optional) and Automatic Drive Mount.

Once the drive and partitions are recognized, Select /opt from the Drop-down menu. Click Apply settings (your router will reboot)

NOTE This may be easier, but the initial Command Line method is much more reliable!


Next, start a terminal session to your router or use a program like PuTTY if using Windows.


First issue these commands to ensure /opt is mounted:

root@DD-WRT:~#mount
rootfs on / type rootfs (rw)
/dev/root on / type squashfs (ro)
none on /dev type devfs (rw)
proc on /proc type proc (rw)
ramfs on /tmp type ramfs (rw)
devpts on /proc/bus/usb type usbfs (rw)
/dev/scsi/host0/bus0/target0/lun0/part1 on /opt type ext3 (rw)
root@DD-WRT:~#



Here's just a little sample of my device output parameters. Yours will not look like this yet.


root@Asus:~# df -h
Filesystem            Size  Used Avail Use% Mounted on
rootfs                5.0M  5.0M     0 100% /
/dev/root             5.0M  5.0M     0 100% /
/dev/scsi/host0/bus0/target0/lun0/part3
                     259M  213M   44M  83% /opt
/dev/scsi/host0/bus0/target0/lun0/part4
                     293G  6.7G  284G   3% /mnt
/dev/scsi/host0/bus0/target0/lun0/part1
                      69M  5.6M   63M   9% /jffs
root@Asus:~#


Enter the following commands into Busybox/Telnet:


wget -O /tmp/prep_optware http://wd.mirmana.com/prep_optware 

sh /tmp/prep_optware

This will load all the necessary optware and supporting scripts that Frater wrote from the ground up.


This will take about 10-20 mins depending on your connection and your router CPU clock. Close your Web Interface as this consumes precious memory and CPU resources


Once everything has completed, type reboot into either the BusyBox/Telnet Shell (why not, your right there) or through the Web Interface.


The BusyBox/Telnet Commands to enable/disable the services are are follows:

service - show all services (enabled/disabled)
service <service name> - if "status" is supported it will run the service-script with "status" asparameter. 
service <service name> on - Enable the script (chmod +x  /opt/etc/init.d/S<servicescript>)
service <service name> off - Disable the script (chmod -x  /opt/etc/init.d/S<servicescript>)
service <service name> <parameter> - Run the script with the parameter.

Examples:

service
service pound
service pound off
service pound on
service pound stop


service automount start - mount all partitions
service automount stop - umount all partitions instead of the one to /opt
service automount status - show all partitions
service automount unmount <partition|mountpoint> - unmount that partition and remove it fromautomount
service automount nomount <partition> - Do not automount this partition
service automount nonomount <partition> - remove this partition from the nomount list


Useful scripts

mount
fdisk -l
blkid
df -h
cat /tmp/fdisk
cat /tmp/blkid
cat /opt/etc/automount
cat /opt/etc/nomount 
lsusb


Many more exciting packages are in the works, so be sure to follow This forum thread and further help is always available on the forums.

Enjoy!

File Serving Overview

Now that you've added USB storage, you may want to share that storage with other computers on your network. The available protocols are:

  • SSH Server (works out of the box)
  • FTP Server
  • NFS Server
  • SMB/CIFS server (aka Samba)

Links

The ASUS WL-500g Premium v2 Wiki Page