DD-WRT on the Buffalo WZR-HP-G300NH – Adding USB storage and optware

In my previous post I described setting up DD-WRT on the Buffalo WZR-HP-G300NH. To recap, I am running the latest official Buffalo DD-WRT release v24SP2-MULTI (07/15/12) std – build 19484 on the v1, A0A3 h/w version of this router. So far, it has been going well. The router has been very stable and wired and wireless clients are getting great connectivity and consistent speeds.

I have since then enabled JFFS2 and configured some static DHCP leases for my LAN. This has worked without any issues.

Now that this setup has been running stably for about 3 days now, I decided to go ahead with adding USB storage and optware. optware is a set of extra packages that provide a lot of additional functionality. Some of these packages simply provide nicer tools to work with in the router itself when you SSH (things like bash, vim etc.). Others add functionality to the router (things like asterisk, privoxy etc.).

The router has a USB port and I  decided to expand the storage in the router by using a 16 GB USB thumb drive. My plan was to install any optware packages and their associated configuration changes in the USB drive. I also wanted to use the drive as a test bed for DLNA in the future. The first step then was to prepare the USB drive to be used as a storage device by the router. I read the instructions here and used my Ubuntu VM to partition and prepare the thumb drive. I created three partitions:

  • A 1024 MB partition for optware installation and configuration
  • A 32 MB partition for swap space
  • The rest of the drive in a single data partition

Note that you don’t really need a JFFS2 partition – the router has plenty of space to host one. As mentioned in the How-To, you can use the fdisk utility in Linux to partition the drive. Be careful in figuring out which device the thumb drive shows up as – otherwise you can end up doing serious damage to your data. The optware partition must be ext2 or ext3. The other data partition can be FAT32. I went with ext2 filesystem for both the optware partition and the data partition but this is actually not a good idea. The fear of flash wear is overblown (it is a real phenomenon, but in practical terms the number of writes required are so large that for this scenario I don’t think it is an issue at all). But the data loss that can result from dirty shutdown of a non-journaled filesystem like ext2 is very real and more likely to hit. I plan to eventually try to re-do this with ext3 but for now, I have stuck with ext2. Use mkfs.ext3 to create and format the data partitions as ext3 filesystems.

Once this was done, I plugged the USB drive in the router and turned on USB storage support in the router (found under Services/USB). You specifically need to turn on Core USB support, USB Storage Support and Automatic Drive Mount. Since I was planning to follow the directions from here for adding optware support, I picked the option to auto mount the drive to /mnt. When I attempted this, I found that USB drive wasn’t successfully mounted (the web admin GUI will show the mounted partition information if the partition was successful). I fired up PuTTY, SSH’d into the router to see what was going wrong. What I found is that /mnt was a symlink to /tmp/mnt. Unfortunately, there was no /tmp/mnt directory and as a result the auto-mount to /mnt wasn’t succeeding. This was very easy to fix – I just created the /tmp/mnt folder and rebooted the router and voila, my first partition showed up automatically. To recap, if you want to follow the forum instructions to add optware support to the official Buffalo DD-WRT firmware, you need to do the following manually first before following the rest of the directions:

SSH into the router
mkdir /tmp/mnt

After this, I just followed the instructions from here and had optware running on the router with no issues. First order of business was to install bash and vim. Once that was done, I decided to add a startup and shutdown script for regular daemon startup/shutdown and (hopefully) proper unmount of all the partitions in shutdown. Here is my startup script:

#!/bin/sh
 sleep 5
 if [ -f /mnt/sda_part1/optware.enable ]; then
 mount -o bind /mnt/sda_part1/etc /etc
 mount -o bind /mnt/sda_part1/root /tmp/root
 mount -o bind /mnt/sda_part1/opt /opt
 for f in /opt/etc/init.d/S*; do
 [ -x $f ] && $f start
 done
 else
 exit
 fi

And here is my shutdown script:

#!/bin/sh

for f in /opt/etc/init.d/K*; do
    [ -x $f ] && $f stop
done

sleep 3
umount -rl /tmp/root
umount -rl /etc
umount -rl /opt
umount -rl /mnt/sda_part1

The key idea with the for loops in startup and shutdown is to replicate the init.d like functionality in full-blown Linux that allow you to order the startup sequence and the shutdown sequence. In the next series, I will explain the use of the init.d/S* and init.d/K* files to order the startup and shutdown sequence. I will also explain using privoxy to enable an ad-blocking proxy in the router.

1 Reply to “DD-WRT on the Buffalo WZR-HP-G300NH – Adding USB storage and optware”

Leave a Reply

Your email address will not be published. Required fields are marked *