2014/09/02

PirateBox on a TP-Link TL-MR3020


 

I bought one of these little routers a few months ago for around $25 or so. My initial plan was to get something that I could run off of USB power in the car so that the kids could connect with their devices and annoy each other on long trips. I was also intrigued with its compatibility with open-wrt.

I had it floating around for a number of months, and it had made a few trips with us. It served its purpose, but it was pretty uninspiring. I don't like uninspiring. So a couple of weeks ago, I started reading up on converting it to open-wrt. Turns out, that step is pretty easy. I just followed the directions on the web site linked above and pretty much just flashed it like a normal firmware update.

It turns out that open-wrt can be pretty dull, too, if you don't have a goal. Enter PirateBox. They probably describe it best:
PirateBox is a DIY anonymous offline file-sharing and communications system built with free software and inexpensive off-the-shelf hardware.
 My idea was to provide the original desired functionality along with the ability to provide music and movies for the kids as well. It looks like I've got it all running, and this is how I did it.

One point I would like to bring up before we begin, I started with a standard open-wrt image on my router. The website's DIY page assumes that you start with the TP-Link firmware or an existing PirateBox install. I would recommend this. I got it straightened out, but it took some poking around and some luck in my original research.

For PirateBox, you will need the TL-MR3020 router and a USB stick. Some of the file system will reside on the USB stick permanently, so pick a stick that is big enough to allow for that and any files you want to serve/store.

I started the PirateBox conversion by downloading the two files that they provide via the website (install_piratebox.zip and *squashfs-factory.bin). Their recommendation for a fresh installation is to set the slider switch to the 3G option (I assume to get the USB port active). You extract the install_piratebox.zip file and copy the INSTALL folder to a USB drive. Remove the USB drive from your computer and plug it into the router and power it on. Connect your laptop to the router and update the firmware (via the normal administration tools) to the firmware file you downloaded from the PirateBox site. This will mount the USB on reboot and install PirateBox, just like the direction say.

I can't say how well this works because I didn't think to plan this far in advance when I started this whole thing. I had to follow the upgrade directions, but I had an issue because I had open-wrt installed already without the USB mounting modules required (and packaged with the PirateBox firmware). The premise for the upgrade is to copy the firmware file to the router via USB drive and copy it over the existing firmware. Upon rebooting, the USB drive will be seen, the zip file will be decompressed, and PirateBox will be installed.

My problem was that I couldn't mount my USB drive with the stock open-wrt firmware. In order to do this, I used some info I got from this site. That site is for setting up the router as a Pineapple box (for man-in-the-middle attacks). What was really important for me was the following piece:
Install the following packages :

opkg update
opkg install kmod-usb-storage
opkg install kmod-fs-ext4
opkg install block-mount
I didn't need the ext4 module since I used FAT32, but the block mount seems to solve the small issue I was having with seeing my USB drive on the router.

So I connected the router via Ethernet cable to my internet router so that I could install the required modules. Once I could mount the USB drive, I copied the PirateBox firmware onto the router with the following command:
cd /mnt/usb
mtd write -r openwrt firmware
Then I rebooted with:
reboot
I then waited the 20 to 45 minutes that are recommended (in my case, I went to bed). After that, I was able to telnet into 192.168.1.1 (note that, telnet, not SSH). In order to do this, I had to actually install telnet on my laptop. Anyway, once I got into the machine, I set the password via:
passwd
This allowed me used SSH again. After that, I followed the steps in the Post-Installation section to activate the Kareha board, setup the time, and start the miniDLNA server. This is what allows you to stream music and movies via a DLNA client.

The one issue that I had was getting the time set up. The TL-MR3020 doesn't have a time clock, so it defaults to 01/01/1970. Since it is designed to run as a stand alone network, there isn't access to an NTP server, either. There are directions in the PirateBox forum for this. At least for this current firmware. In essence, this is what you do (from the above link):


The step about the timesave.sh script is a script for fixing this. The issue is only, that the timesave.sh as a syntax error and the routine within the openwrt package has a bug too -- in 1.0.0

I prepared the fix for 1.0.1 which is currently in beta testing.

To fix it manually:

edit /opt/piratebox/bin/timesave.sh

find
if [ `get_datetime` -lt `cat $TIMESAVE` ] ;
and replace with
if [ `get_datetime` -lt `cat $TIMESAVE` ] ; then
(missing then)

Then edit /etc/rc.local

change
/opt/piratebox/conf/piratebox.conf /opt/piratebox/bin/timesave.sh recover
with
/opt/piratebox/bin/timesave.sh /opt/piratebox/conf/piratebox.conf  recover
Additionally run:
/opt/piratebox/bin/timesave.sh /opt/piratebox/conf/piratebox.conf  install

BUT, that is no exchange for areal Real-Time-Clock. This is not available on such cheap systems.
At that point, I shut down my router, mounted the USB stick on my laptop and copied a bunch of music and movies onto it. This is much faster than trying to upload them. For the DLNA server, you will need playlists for your music. I haven't bothered with this. A simple script can be run to parse a folder/folder structure to get songs available and create playlist files.

This was a really straight-forward install. I was impressed with how easy this was. The guys working on this project have done a great job, and the only issues I had were my own doing.

No comments: