Sunday, January 03, 2010

My Torrent downloading setup using beagle board

Prologue : dont get upset by the large maze of wires in the picture. I have included some additional componets like USB to Serial adapter and USB hard disk, which are not mandatory for the mission outlined here. I have included them for the sake of completeness. Please click on the image for a better quality one.
For the sake of dummies who has never thought a world beyond intel/x86 PCs- Beagle Board is a low-cost, fan-less single board embedded board with a heart made of 600 MHz TI's Arm Cortex A8 based OMAP 3530 processor. The board is said to consume less than 2 watts of power while running and is just a 2 inch square in size.

I bought beagle board mainly to have an arm board at my disposal at home for hobby purposes like learning arm assembly and arm/architecture dependent and ofcourse arch independent portions of linux kernel. Though i have access to a wide variety of high end arm boards at my workplace, at times i miss them at home. Despite these noble intentions while buying i have to confess that in the most part of the last 4 months while I was in possession of my beagle i have done no more kernel hacking than recompiling kernel and u-boot for beagle with some prints. I have to accept that i was practically spoilt by the amazing support provided by the community in terms of software support for this board, and i could get it running with practically zero effort.

After beagle board was lying practically idle in its small box for a little over 4 months, couple of weeks before, i got stricken by an idea to put it to real use. How about using it as a headless [monitor less] system which will keep downloading your torrents 24/7 ie you can leave it home and go for a week long vacation and it will download all the torrents you have queued, which means when the power goes off and comes back beagle will again start up and continue the download. You can also add more torrents if you wish to while you are away , via ssh , provided you have a static IP as is my case.

The main problem, in achieving this was that beagle board didnt have an ethernet port, but it has USB port. So I have bought one usb to ethernet adapter [believe me finding this adapter these days can be quite a challenge i was able to find one at computer ware house for around RS 200/ mg road / barton centre in bangalore] . You should also buy one self powered USB hub. I couldnt find it here in bangalore so i ordered one from eBay [Belkin 4 port for Rs 850] . The purpose of USB hub is two fold in case of beagle board.
1. The USB ethernet adapter is a Full Speed [USB 1.1] device and the USB host controller port on the beagle will support only High Speed [USB 2.0] devices. Since the hub is a USB 2.0 device, if you plug the adapter on the hubs port it will be detected - see the image for details

2. My 160GB USB ethernet drive was also not working [though it is USB 2.0] while connecting directly to the board[ though thumb drives were working while connected directly], but worked while connected under the hub. I guess this was because the beagle is unable to power the hard disk, but as the Hub is self powered it isable to power the hard disk.

3. I didnt order a power adapter for the beagle board while ordering from digikey since i had to shell out an extra 1000 bucks for that. Ideally you should be able to find it from some neighbourhood electrical shops - but i couldnt . As a work around i was powering the board from my laptop using a mini B cable to the USB OTG port on the board.
So if you are using a self powered usb hub, you can power the beagle board by taking power from one of its port. This explains the 3rd downstream connection to the usb hub in the picture.

That completes the hardware setup, now u have burn the Xloader and u-boot into the Beagle board flash as explained here. Then i got an SD card and partitioned and formatted it into two, the first a 50 MB FAT partition and the remaining as an ext3 partition. I used GParted utility available in desktop Linux. So put the SD card in a usb card reader and plug it onto a native linux machine. Since i dont have a native Linux machine i used my ubutnu VMWare virtual machine running inside my vista for this purpose. For more detailed instructions on this, please see this video. Now download one angstrom Linux kernel build [uImage file] from this link. Put that file in the FAT partition of the SD card. Though you can burn the kernel image into the FLASH, it is better to keep it on the SD card as you can easily replace it with another kernel, by plugging the SD card onto another system.

Now that we have the XLoader, u-boot and Kernel, in place, all that is remaining is the root file system. Here i used anstrom Linux online image builder. For our purposes please include the following packages rtorrent, samba, ntp - network time, dropbear -ssh server, screen - session manager and Busybox replacements. Other interesting packages you can select are powertop, mplayer, Alsa utils and Cheeroke - web server. That will give you a tar ball which you can extract into your ext3 partition in the sd card. That is about it you can put the SD card and boot power on the beagle board and you should get linux shell. If you are seeing kernel panic - unable to mount root fs, check kernel command line during linux boot up - it should have something like this
Kernel command line: console=ttyS2,115200n8 root=/dev/mmcblk0p2 rw rootfstype=ext3 rootwait

Otherwise go and edit u-boots bootargs environment variable and modify it to
bootargs=console=ttyS2,115200n8 console=tty0 root=/dev/mmcblk0p2 rootdelay=2 rootfstype=ext3 rw single

Now configure the network, and ntp client and then get hold of a torrent file and launch rtorrent and you can start downloading torrents like the son of Bram Cohen. Please check this article on how to configure rtorrent . Have a look at this article also while configuring rtorrent. From my experince i have found that rtorrent is a very robust ncurses based bit torrent client. You can launch it with screen so that every time you ssh you can get the same console. Dont forget to read starting rtorrent at startup in the above mentioned link which can be quite handy.

I have ran this set up close to two weeks[including one week where i travelled to my native place for new year and returned and found that rtorrent was still running in spite of the numerous power outages, i even added a few torrents from my home over ssh] and found the setup to be quite reliable, except for a few cases where in i have founf USB ethernet driver has crashed ie when i tried to copy large file via samba into my windows system, but those can be easily worked around.

Though not related i am just adding one powertop screen shot also, just in case for your reference

Finally a word of thanks to my friend Manu Thayyil who carried the beagle all the way from US.

Please feel free to post your queries and comments.