Jan 27, 2011

Two short stories with a great moral...

The Frogs

A farmer came into town and asked the owner of a restaurant if he could use a million frog legs. The restaurant owner was shocked and asked the man where he could get so many frog legs! The farmer replied, "There is a pond near my house that is full of frogs - millions of them. They all croak all night long and they are about to make me crazy!" So the restaurant owner and the farmer made an agreement that the farmer would deliver frogs to the restaurant, five hundred at a time for the next several weeks.

The first week, the farmer returned to the restaurant looking rather sheepish, with two scrawny little frogs. The restaurant owner said, "Well... where are all the frogs?" The farmer said, "I was mistaken. There were only these two frogs in the pond. But they sure were making a lot of noise!"

Moral : Next time you hear somebody criticizing or making fun of you, remember, it's probably just a couple of noisy frogs. Also remember that problems always seem bigger in the dark. Have you ever lain in your bed at night worrying about things which seem almost overwhelming like a million frogs croaking? Chances are pretty good that when the morning comes, and you take a closer look, you'll wonder what all the fuss was about.


The Pretty Lady

Once upon a time a big monk and a little monk were traveling together. They came to the bank of a river and found the bridge was damaged. They had to wade across the river. There was a pretty lady who was stuck at the damaged bridge and couldn't cross the river. The big monk offered to carry her across the river on his back. The lady accepted. The little monk was shocked by the move of the big monk. "How can big brother carry a lady when we are supposed to avoid all intimacy with females?" thought the little monk. But he kept quiet. The big monk carried the lady across the river and the small monk followed unhappily. When they crossed the river, the big monk let the lady down and they parted ways with her.

All along the way for several miles, the little monk was very unhappy with the act of the big monk. He was making up all kinds of accusations about big monk in his own head. This got him madder and madder. But he still kept quiet. And the big monk had no indication to explain his situation. Finally, at a rest point many hours later, the little monk could not stand it any further; he burst out angrily at the big monk. "How can you claim yourself a devout monk, when you seize the first opportunity to touch a female, especially when she is very pretty? All your teachings to me make you a big hypocrite.

The big monk looked surprised and said, "I had put down the pretty lady at the river bank many hours ago, how come you are still carrying her along?"

Moral : This very old Chinese Zen story reflects the thinking of many people today. We encounter many unpleasant things in our life, they irritate us and they make us angry. Sometimes, they cause us a lot of hurt, sometimes they cause us to be bitter or jealous. But like the little monk, we are not willing to let them go away. We keep on carrying the baggage with us. We let them keep on coming back to hurt us, make us angry, make us bitter and cause us a lot of agony. Why? Simply because we are not willing to put it down or let go of the baggage.

We should let go of the incident soon after crossing the river, that is after the unpleasant event is over. There is no need to be further hurt by the unpleasant event after it is over.

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.