Jan 25, 2011

Step by Step guide to setting up Buffalo router into a torrent downloader & NAS box

I have been using the Linksys 610N as a torrent downloader plus wireless router for the past year and while I was happy with the router, there are a few things that were bugging me. One was the NAS speeds to copy the downloaded torrents to my PC. I would hardly get 3mbps. I have also tried the Asus W500g and that was also a broadcom chipset and it was more limited than the Linksys.

So I decided that I would give a try for the Atheros wireless chipset. I shortlisted and got the Buffalo WZR-HP-G300NH router for INR 5k. It is a sleek black router with nice antenna's, fantastic wireless range, gigabit ports, a 400MHz processor, 32MB flash, 64MB RAM and a USB port.

The biggest stumbling block with the Atheros chipset was the fact that DD-WRT had limited support for packages on this chipset. The reason being that the Atheros CPU in the Buffalo router is MIPS while the Broadcom routers like Linksys 610N are MIPSEL. In laymans terms, it means the popular optware packages in DD-WRT compiled for broadcom will not work on this router. I installed dd-wrt and the openwrt packages using a lot of hacks documented on the web and most things did work. Then I started discovering issues, the primary one being there is no large file support in the firmware, so any downloaded files over 2gb would not even be visible on the Samba share.

This left me with the last option, install OpenWRT on the router. Information on OpenWRT is sadly less than for DD-WRT, there are lots of scattered information all over the net, but no consolidated place. Anyways, once I finished the setup, I was pleasantly surprised by the performance of NAS and the wireless ! I easily get over 7mbps to read files off the NAS connected to the WZR-HP-G300NH and the wireless range is fantastic. It also seems to draw less power than the Linksys (3watts as compared to 7watts for the Linksys).

Since I struggled for over a week to get everything working, I decided to document the procedure. Here are the exact steps to setup and configure the Buffalo WZR-HP-G300NH with OpenWRT to act as a wireless router, NAS and torrent downloader.


Remember a few ground rules.

1. Rule one, make sure that all the features of the router works in its default firmware before you move further. If there is a issue with the hardware, you do not want to find out after you have voided the warranty.

2. On the warranty front, OpenWRT is not a supported firmware for the Buffalo, so you might need to move back to the official firmware if there is ever a need to open a warrarty request. Do not blame me if you end up messing everything and cannot revert for some reason.

3. The router is virtually un-brickable as it has TFTP support in its bios. So you can almost always recover in any worse case scenario. Just make sure you have a Linux machine or LiveCD that can be used to update the firmware with TFTP.

4. Have a UPS connected to the router when upgrading. Power cut halfway through a upgrade is one way to void point 3. This router takes almost 5 minutes for a flash update and goes through multiple boots. Never do anything with the router till the red diagnostic LED stops flashing and the green LED come on solid. Get some popcorn if you do not have patience !!!

5. Make sure you have the Indian (B0 C0) or a non Japanese version of the router. This 4 digit code is printed on the router itself above the default SSID (unfortunately no way to figure this out unless you open the box. But if you are buying from a dealer in India, you will not get the Japanese version). If you have a Japanese version (A0 A1 or A0 A3), STOP right now and read this link , there are lots of complications with the Japanese router upgrade.


Here goes:


1. Download the latest "buffalo_to_ddwrt_webflash-MULTI.bin"

Pick on the latest date in the ftp link, move to the buffalo_wzr-hp-g300nh folder to get your file.

ftp://dd-wrt.com/others/eko/BrainSlayer-V24-preSP2/

I particularly used the file from this link for my work.

Note : There is a easier way to directly move to OpenWRT using the TFTP method as described in the last section, but I will use the easy method, even if it means three firmware flashes !!!


2. Connect to 192.168.11.1 with your browser and go to the firmware update page.


Choose the file you downloaded in step 1 and wait till the router is flashed fully.

Note : I will be referencing 192.168.11.1 as the default router page. Sometime the default page could be 192.168.1.1. One of them will always work.


3. After the reboot, if you again go to the router homepage via your browser, you should now see the DD-WRT webpage.

Change the admin password so that you can use ssh and login using the same password you just set.


4. Login to the router via ssh (Can use putty.exe)

Run these commands :
cd /tmp
wget http://downloads.openwrt.org/backfire/10.03.1-rc4/ar71xx/openwrt-ar71xx-wzr-hp-g300nh-jffs2-sysupgrade.bin
mtd -r write openwrt-ar71xx-wzr-hp-g300nh-jffs2-sysupgrade.bin linux
Note : As of now, 10.03.1-rc4 is the latest, always go for the latest version you find.

Wait for a full 6-9 minutes before you do anything. When the router comes up again, you should have OpenWRT running.


5. Run the following commands one by one to install all the USB and file system drives :

opkg update
Make sure this command above completes. If there is a issue with your network, the update will fail. Fix this before you move ahead.
opkg install kmod-fs-btrfs kmod-fs-ext2 kmod-fs-ext3 kmod-fs-ext4 kmod-fs-isofs kmod-fs-reiserfs kmod-fs-vfat kmod-fs-xfs

opkg install kmod-nls-cp1250 kmod-nls-cp1251 kmod-nls-cp437 kmod-nls-cp775 kmod-nls-cp850 kmod-nls-cp852 kmod-nls-cp866 kmod-nls-iso8859-1 kmod-nls-iso8859-13 kmod-nls-iso8859-15 kmod-nls-iso8859-2 kmod-nls-koi8r kmod-nls-utf8

opkg install kmod-usb2 kmod-usb-storage kmod-usb-storage-extras block-hotplug block-mount hotplug2

6. Connect a USB drive to the router and reboot.


Im going to assume that there is a external drive connected with a single partition formatted to ext3. If you need more partitions or a different file system, you probably know what you are doing, so tweak the commands !!!


7. The next set of commands are a safety net.

If you ever bootup without the USB drive connected, you might end up writing to the router flash and mess things, so the command below will make sure you cannot write anything to the share if the drive is not mounted.
mkdir /mnt/download -p
touch /mnt/download/WARNING_USB_DRIVE_IS_NOT_MOUNTED
chmod 444 /mnt/download -R

8. Run the following commands to setup the first partition to be mounted automatically :
uci set fstab.@mount[0].target=/mnt/download
uci set fstab.@mount[0].device=/dev/sda1
uci set fstab.@mount[0].fstype=auto
uci set fstab.@mount[0].enabled=1
uci set fstab.@mount[0].options=rw,sync,noatime,nodiratime
uci commit fstab
Reboot the router


9. Run the following commands to install samba3:
cd /mnt
chmod 777 download/
cd download/
mkdir -p /mnt/download/downloads
mkdir -p /mnt/download/torrents
chmod 777 downloads torrents

opkg update
opkg install samba3 luci-app-samba

uci set samba.@samba[0].name=Buffalo
uci set samba.@samba[0].description=Buffalo
uci set samba.@samba[0].workgroup=WORKGROUP
uci set samba.@sambashare[0]=sambashare
uci set samba.@sambashare[0].guest_ok=yes
uci set samba.@sambashare[0].path=/mnt/download/downloads
uci set samba.@sambashare[0].name=download
uci commit samba

10. Samba3 is now installed. Time to configure it.

Edit the file : /etc/samba/smb.conf.template

Add the lines :
force user = root
writeable = Yes
create mask = 0777
directory mask = 0777
inherit permissions = Yes
Remove the line:
invalid users = root

11. Run the command to start samba :

/etc/init.d/samba restart

At this point, use explorer to goto \\192.168.11.1 to make sure the samba share is accessible and writable.


12. Time to install transmission for the torrent downloads.

Run the following commands :

opkg install transmission-web
transmission-daemon -g /mnt/download/torrents
killall transmission-daemon
cd /mnt/download/torrents
cp settings.json settings.json.copy

13. Time to configure transmission startup :

Replace the contents of the file /etc/init.d/transmission with the text below :

#!/bin/sh /etc/rc.common

START=99

start(){
cp /mnt/download/torrents/settings.json.copy /mnt/download/torrents/settings.json
transmission-daemon -g /mnt/download/torrents
}

stop(){
killall transmission-daemon
}

14. Edit the file /mnt/download/torrents/settings.json.copy and replace all the content in the file with these lines below :

{
"bind-address-ipv4": "0.0.0.0",
"bind-address-ipv6": "::",
"blocklist-enabled": false,
"blocklist-url": "http://www.example.com/blocklist",
"cache-size-mb": 2,
"dht-enabled": true,
"download-dir": "/mnt/download/downloads",
"encryption": 1,
"incomplete-dir": "/mnt/download/incomplete-torrents",
"incomplete-dir-enabled": false,
"lazy-bitfield-enabled": true,
"lpd-enabled": false,
"message-level": 2,
"open-file-limit": 32,
"peer-limit-global": 240,
"peer-limit-per-torrent": 60,
"peer-port": 55555,
"peer-port-random-high": 65535,
"peer-port-random-low": 49152,
"peer-port-random-on-start": false,
"peer-socket-tos": 0,
"pex-enabled": true,
"port-forwarding-enabled": true,
"preallocation": 1,
"ratio-limit": 2,
"ratio-limit-enabled": true,
"rename-partial-files": true,
"rpc-authentication-required": false,
"rpc-bind-address": "0.0.0.0",
"rpc-enabled": true,
"rpc-password": "{414db619f34798e4204bce201b584670afd2795ax7vJCOc. ",
"rpc-port": 9091,
"rpc-username": "",
"rpc-whitelist": "*",
"rpc-whitelist-enabled": true,
"speed-limit-down": 1000,
"speed-limit-down-enabled": true,
"speed-limit-up": 100,
"speed-limit-up-enabled": true,
"start-added-torrents": true,
"trash-original-torrent-files": false,
"umask": 0,
"upload-slots-per-torrent": 14
}
If you know what you are doing, feel free to change any of the values above to change the behavior of your torrent downloader.


15. Run the command below to make transmission auto start with the router :

cd /etc/init.d; chmod +x transmission; ./transmission enable

16. Increase the life of the hard drive by making it sleep after 5 minutes of inactivity :

opkg update
opkg install hd-idle luci-app-hd-idle
uci set hd-idle.@hd-idle[0]=hd-idle
uci set hd-idle.@hd-idle[0].disk=sda
uci set hd-idle.@hd-idle[0].idle_time_unit=minutes
uci set hd-idle.@hd-idle[0].idle_time_interval=5
uci set hd-idle.@hd-idle[0].enabled=1
uci commit

opkg install of the luci component might return a few errors, just ignore them.

16. Reboot the router and browse to : http://192.168.11.1:9091

You should see the transmission webpage from where you can add and control all torrent downloads.


That is about it. Add torrents, let the router download all night, then use samba to copy the downloaded file to your machine !!!

Have fun downloading and NAS'ing







If you mess up with the steps and your router stops responding : :

1. Boot into linux on the PC (LiveCD will work well), typically Ubuntu 10.10. Connect the PC network cable to the lan port closest to the blue WAN port. Switch OFF the router.

2. Run the following commands (substitute the XX:XX with your router's MAC ID which is printed on the box):

ifconfig eth0 192.168.11.2 netmask 255.255.255.0

arp -s 192.168.11.1 xx:xx:xx:xx:xx:xx

3. Now run the tftp command and enter the commands under it one by one,

tftp 192.168.11.1
binary
rexmt 1
timeout 60
trace
put openwrt-ar71xx-wzr-hp-g300nh-jffs2-tftp.bin

4. Now turn on the power to the router even as the command above is running.

The TFTP command would timeout a few times and will start the process as soon as the router is turned on. Wait for a full 10 minutes after the tftp command returns (yes, it takes that long !) and you should be back up and running.

21 comments:

Anonymous said...

I am using ASUS RTN13U and it works well with the default firmware and has USB drive also so that you can use any flash drive or USB harddrive for downloading the torrents.

I tried to use TATA Photon+ for data connection with it, but couldn't get it work even with the lastest firmware.

Anand said...

Hi Vinayaga,
I am following your blog right from when u posted about WDLive...looks like u r real brainy... I appreciate your effort & also the sharing of the same to everyone...:-)
I am in Bangalore...I have browsed a thousand websites, reviews & forums but am unable to decide what(Router, NAS Adapters & the like...) to use as a 24hr torrent downloading solution....I came across the same Buffalo Router which u r using....just a few simple doubts

1) Can I use any Windows related methods to update/tweak the firmware of this router?(as I dont know much about Linux)
2) Why are you flashing a ddwrt again when the Router has an already built-in mtorrent client? Also, how many torrents can be downloaded at a time? Howz the speed? Is the torrent downloading customizable...I mean can you choose which files to download in a particular torrent if it has multiple files?
3) I am thinking of buying a Iomega IConnect for the above said job from one of my friends cheaply. Are there any possibilities to update/tweak the firmware of this device? At present it is possible to download only one torrent at a time with iConnect

4) How is Asus RT-N13U rev.B1?

I would appreciate if you reply asap. I can be reached at apshandilya@gmail.com

Anonymous said...
This comment has been removed by a blog administrator.
Vinayaga said...

Hi Anand,

Thanks for the compliments, appreciate it.

1. You can use windows for the most part, but if something goes wrong, you might have to fall back to Linux. I have usually never needed to use Linux and have managed to do all this mostly on windows. But remember that a lot of the configuration still is linux based (that is you login to the linux box via ssh from windows) and you will still need to use the linux commands that I have provided.

2. The inbuilt torrent client on the router is very limited. Transmision is a fantastic torrent client that has limitless possibilities. No comparison there, but if you are uncomfortable in linux, it is a acceptable choice.

3. The iomega product is not upto the mark. You will be better off with buying a readymade router with inbuilt torrnet client like the Asus or Buffalo.

4. The Asus N13 rev B has a major drawback of not being able to be flashed with any opensource firmwares. So you will be limited to the stock firmware.

Given your dilemma with Linux, I suggest you buy the Asus N13 or the Buffallo WZR300 and use the factory torrent client on the same.

-Vinayaga

Anand said...

Hi Vinayaga,

Thanks for the sincere reply....a simple doubt.....& a favour

1) Can I use a USB hub on the Buffalo WZR300 to expand the number of USB devices?....Also, I got a quote of Rs.4000 for the router....Can I go for it?

2) I got the IConnect from my friend just to have a feel of it...& as we communicate, I am downloading the torrents...drawback is that only one torrent can be downloaded at a time....however, the device was intelligent enough to resume from where it was stopped(bcoz of a power shutdown...common in B'lore)...speed is good(a factor of the available peers & seeds)...what do you suggest?

And the favour, if possible from your side....can you tweak/ firmware update(on the same lines as guided in your blog) the Buffalo WZR300 for me, if I purchase it?....looks like I am troubling you

Vinayaga said...

You can use a hub for sure. I do.

4k looks like a good price, go for it. I paid about 4.5k.

As for helping you, it is a matter of time and Im facing a big shortage of it because of work pressure. If you offer me a crate of beer, that might do the trick, but would increase the cost for you :-) Better you learn it yourself and remember that the Buffalo is pretty much un-brick-able. So you can tweak it and make mistakes as many times as you want !

Anand said...

Thanks again...regarding the beer, I shall treat you for sure, mate....these days, it's becoming difficult to find a good friend...but let me see what I will do regarding the router/iConnect.... ;-)

JUha said...

Thanks for great instructions. I have a small problem, I followed your instructions ...all went well until step 5 - I got the message -sh: opkg: not found

what should I do next?

I'd like to see my USB (WD My Book) in my PC as a network drive

Disk Info
--- /dev/sda
Block device, size 1.819 TiB (1999696297984 bytes)
DOS/MBR partition map
Partition 1: 1.628 TiB (1789981097984 bytes, 3496056832 sectors from 409600000)
Type 0x0B (Win95 FAT32)
FAT32 file system (hints score 5 of 5)
Volume size 1.627 TiB (1789107486720 bytes, 109198455 clusters of 16 KiB)
Volume name ""
Status: Mounted on /mnt

Router Model
Buffalo WZR-HP-G300NH
Firmware Version
DD-WRT v24-sp2 (02/17/11) std - build 16214
Win 7 pro

Would it be better to format ext3

Thanks for you time
Juha

Vinayaga said...

opkg should be part of the default openWRT system, I would be very surprised if it is not available in your case. Try logging into the default openwrt website on router and install packages using luci.

As for the fat32 drive, it is not a great idea to have a 1tb+ fat32 drive. fat32 is not very good with error corrections and corruption. However, if you want to use it as is, you still can do it as openWRT has support for Fat32 drivers. Just login to the dafault openwrt website and use luci to install the packages for fat32.

Prasad said...

Hi Vinayaga,

I am not able to procure the Buffalo router....Could you please suggest any other good routers (apart from the ones you have mentioned in your blog as I have checked with those makes & found that some or the other problem exists with them, also most of them are outdated).....I am in Bangalore.

Vinayaga said...

Contact Arun Kumar from Computer Doc. He is a Buffallo dealer and has home delivered the router in bangalore anytime I asked.

Arun Kumar
+91 782-934-0687
Computer Doc

Arun said...
This comment has been removed by the author.
Arun said...

Thanks for your valuable comments

Prasad said...

Thanks Vinayaga,
I got the router from an other dealer after giving him a headache to procure it.

Before I start following your steps, one simple doubt....Do I get a support for downloading files > 4GB (and ofcourse visibility of files>2GB) after I follow your steps in the blog?

I am using a 500GB ext HD---FAT32 for downloading.

Thanks again for the sincere reply

Anonymous said...

You will get support for 2gb+ files if you use the exact procedure I documented. If you use DD-WRT, then the mismash of openwrt libraries and dd-wrt ensures that you cannot access files bigger than 2gb.

Krishna said...

Hello Vinayaga.

This is real cool.
you said that you are using linksys wrt610n as torrent downloader.

I bought wrt320n recently and need you help in downloading torrents from it.

Can you pls guide me in setting this router for torrent download...

Metalspree said...

Is the NTFS format supported??.If yes how to do it ??.

Vinayaga said...

Yes NTFS support works after you install the NTFS modules in OpenWRT. Luci allows you to install it seamlessly from the Openwrt menus.

Anonymous said...

yw qz si jhwp qyap zujp bolsyz npgadd dlbzjzbp rg qz [url=http://www.montblancukpens.co.uk]mont blanc[/url] ykvg [url=http://www.montblancukpens.co.uk]mont blanc outlet[/url] espn yqij ujgxhs jmtkye xtqkdbqb yl vm dlje tvxl pepz [url=http://www.montblancukpens.co.uk]mont blanc boheme pen[/url] hykxvl gezvga mraabryd iv gd ebqi inve ygnt dglzly vwrkrw [url=http://www.montblancukpens.co.uk]http://www.montblancukpens.co.uk[/url] cumcuaqp hy jw cbsi gzdm apti [url=http://www.montblancukpens.co.uk]mont blanc keychain[/url] khtnag bekvwj myaeozog oa nl wfhw [url=http://www.montblancukpens.co.uk]montblanc starwalker ballpoint pen[/url] avit usne uhlcly zgalle kzqftead qg cs odkz vfvk rzcy xwko

Unknown said...

Nice blog Thanks for sharing.
Routers Dealers Bangalore

Anand said...

Hi Vinayaga,

I am Anand.... hope u remember me from my previous comments...

I am using the WZR-HP-G300NH since 2 yrs without any problem.... till now... :(

I have updated the firmware to 1.79 & still using the same torrent client that came with the router. I haven't modified anything as per your blog.

I was able to download all types of torrents.... but now I am able to only small size torrents like ebooks & not big sized ones

I was surprised to see that I am not the only guy to face this prob from the foll link---- http://buffalo.lithium.com/t5/Wireless/WZR-HP-G300NH-Some-torrent-s-won-t-start-downloading/td-p/47028/page/2

I also did a factory-reset... but no-go

Shud the NAT table be cleared? If yes, then how?

Also is there a problem with anti-leeching?

Any help wud b appreciated.... thanks in advance

Regards,
Anand