Central Seven

Science is fun!


Raspberry Pi2 Seedbox with Deluge and a VPN

Recently, the Raspberry Pi 2 was announced, and I recently bought a couple. They’re fantastic little devices, $35 for an fully-functioning, pocket sized computer.

One of the first projects I did was building a Linux-based Torrent Seedbox. I had originally started working with a UDOO, which is a bit more powerful. The main advantage of the UDOO was the SATA connector, but in the end I ran into too many complications, and ultimately switched over to the Raspi.

The Raspberry Pi is lower cost, but still fairly powerful. After a fair bit of tinkering, I built a nice little autonomous seedbox with ~100 GB capability and VPN connectivity. I set it up to hook it directly to the router through an Ethernet port (to avoid the complications and connectivity issues of wireless), and also have it draw power from one of the USB ports on the router. The one piece I’m still working on is encryption, which would be nice to have but isn’t a deal-breaker at this point.

To start

The things you’ll need: raspberry pi 2, biggest microSD card that’s reasonably priced (I ended up with a 64 GB class 10), larger USB flash drive (you can get a 128 GB for about 60$), video cable, keyboard, mouse, screen.

The image I used was:

Install it in the typical fashion, which in this case was

dd if=/home/user/downloads/2015-02-16-raspbian-wheezy.img of=/dev/sde bs=1M

where the sde is the location of the microSD card. Then throw the card in the Pi, and boot it up.

On boot, it automatically runs raspi_config, and run through the following options:
-Expand filesystem
-Change user password
-Enable Boot to Console
-Internationalisation (en_US_UTF)
-Advanced: change hostname, enable SSH

Hook it up directly to the network (ethernet), and SSH in using the new password you just created. Then run:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential libtool autotools-dev autoconf libssl-dev pkg-config

The next step is installing latest version of deluge, you’ll have to build it from scratch because the older, apt-driven versions in the PPT kept crashing randomly on me. Also, the version in the PPT apparently can’t handle Magnet links, which makes it a pain to use.

Install dependencies for deluge:

sudo apt-get install python python-twisted python-openssl python-setuptools intltool python-xdg python-chardet geoip-database python-libtorrent python-notify python-pygame python-glade2 librsvg2-common xdg-utils python-mako

But before you can install deluge, you have to build libtorrent from source, because the version available in the repository has problems.

wget http://downloads.sourceforge.net/project/libtorrent/libtorrent/libtorrent-rasterbar-0.16.19.tar.gz
tar -zxvf libtorrent-rasterbar-0.16.19.tar.gz
cd libtorrent-rasterbar-0.16.19
./configure --enable-python-binding

However, when this runs, you get the following error:

checking for boostlib >= 1.36... configure: We could not detect the boost libraries (version 1.36 or higher). If you have a staged boost library (still not installed) please specify $BOOST_ROOT in your environment and do not give a PATH to --with-boost option. If you are sure you have boost installed, then check your version number looking in <boost/version.hpp>. See http://randspringer.de/boost for more documentation.

So maybe the solution is to install libboost-dev:

sudo apt-get install libboost-dev
./configure --enable-python-binding
checking for exit in -lboost_system... no
configure: error: Could not link against boost_system !

Same error. Maybe if I install absolutely everything related to libboost?

sudo apt-get install  libboost-filesystem-dev  libboost-iostreams-dev  libboost-system-dev  libboost-thread-dev
./configure --enable-python-binding
configure: error: in `/home/pi/Downloads/libtorrent-rasterbar-0.16.19':
configure: error:
Could not link test program to Python. Maybe the main Python library has been
installed in some non-standard library path. If so, pass it to configure,
via the LDFLAGS environment variable.
Example: ./configure LDFLAGS="-L/usr/non-standard-path/python/lib"
You probably have to install the development version of the Python package
for your distribution. The exact name of this package varies among them.

Well that can be fixed easily enough.

sudo apt-get install python-dev
./configure --enable-python-binding
checking whether the Boost::Python library is available... yes
checking for main in -lboost_python... no
checking for main in -lboost_python... (cached) no
configure: error: Boost.Python library not found. Try using --with-boost-python=lib.

Ok, here’s another try:

sudo apt-get install libboost-all-dev
./configure --enable-python-binding


make #***wait forever***
sudo apt-get install checkinstall
sudo checkinstall

*checkinstall creates a deb package that then can be used by dpkg to remove all the installed files easily.*

The next code segment tests whether libtorrent actually worked and python can interact with it appropriately.

python -c "import libtorrent as lt; print lt.version"
Traceback (most recent call last):
File "", line 1, in
ImportError: libtorrent-rasterbar.so.7: cannot open shared object file: No such file or directory

It turns out that a library not correctly linked. This can be fixed easily:

cd /lib
sudo ln -s /usr/local/lib/libtorrent-rasterbar.so.7

With libtorrent taken care of, the next step is to down and install Deluge from source.

wget http://download.deluge-torrent.org/source/deluge-1.3.11.tar.gz
tar -zxvf deluge-1.3.11.tar.gz 
cd deluge
python setup.py build
sudo python setup.py install --install-layout=deb
sudo python setup.py install_data
deluged -v
deluged: 1.3.11

Which actually goes off surprisingly easily.


To make this setup work with a VPN, you’ll need to have an account already setup with a VPN provider. The provider iPredator is an easy and relatively cheap one to get started with, they have some nice tutorials as well, but I have no particular investment in one over another.

So ahead of time, you’ll need to download the TA key and the CA certificate ahead of time (provided by the VPN provider after you create your account). You may need to change the following configuration file to adjust for your file names, locations, and servers.

sudo apt-get install openvpn
mkdir vpn
cd vpn
vi configure.ovpn
echo "VPNusername" > pass.txt ; echo "VPNpassword" >> pass.txt

With that done, I wrote a short BASH script to connect the VPN, remove the local gateway (so it will never torrent if the VPN goes down), and then start Deluge daemon and Deluge web interface. The Deluge daemon runs the core of the program, while the web interface makes for an easy way to interact with the program.

I originally ran the script by hand until I was sure it was stable, and I noticed an error would pop up every time I started it.

Deluged: error!
Unhandled error in Deferred:
Unhandled Error
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/deluge-1.3.11-py2.7.egg/deluge/main.py", line 230, in start_daemon
Daemon(options, args)
File "/usr/lib/python2.7/dist-packages/deluge-1.3.11-py2.7.egg/deluge/core/daemon.py", line 161, in __init__
File "/usr/lib/python2.7/dist-packages/deluge-1.3.11-py2.7.egg/deluge/component.py", line 296, in start
File "/usr/lib/python2.7/dist-packages/deluge-1.3.11-py2.7.egg/deluge/component.py", line 124, in _component_start
d = maybeDeferred(self.start)
--- ---
File "/usr/lib/python2.7/dist-packages/twisted/internet/defer.py", line 134, in maybeDeferred
result = f(*args, **kw)
File "/usr/lib/python2.7/dist-packages/deluge-1.3.11-py2.7.egg/deluge/core/preferencesmanager.py", line 162, in start
File "/usr/lib/python2.7/dist-packages/deluge-1.3.11-py2.7.egg/deluge/config.py", line 312, in register_set_function
function(key, self.__config[key])
File "/usr/lib/python2.7/dist-packages/deluge-1.3.11-py2.7.egg/deluge/core/preferencesmanager.py", line 258, in _on_set_listen_interface
self._on_set_random_port("random_port", self.config["random_port"])
File "/usr/lib/python2.7/dist-packages/deluge-1.3.11-py2.7.egg/deluge/core/preferencesmanager.py", line 276, in _on_set_random_port
self.session.listen_on(listen_ports[0], listen_ports[1], str(self.config["listen_interface"]).strip())
exceptions.RuntimeError: Address family not supported by protocol

Despite that noise, everything seemed to work fine. I so I ignored it. And it didn’t cause any problems.

External USB Flash Drive, Installing Samba, Automation

Next step, mount the external drive (I picked up a 128 GB for $50, remember when 128 MB was HUGE?). Plug it into one of the USB slots, and add to the following line to /etc/fstab:

/dev/sda1 /mnt ext3 defaults 0 2

I found that the USB drive could not transfer data as quickly as needed to torrent more than 5 or so files off the USB. I would start getting errors, and the error log would slowly fill up. The speed issue of USB turned out to be a fair hassle, so I ultimately replaced the 16 GB microUSB that holds the OS with a 64 GB chip.

I enabled Samba So people on my network can access the downloaded files without hassle. Samba (aka Windows SMB or Server Message Block) allows easy file sharing, although it has always been a security headache. In this case, I’m not putting any security on it, with the idea that anyone who can get on the network can have access to these files.

sudo apt-get install samba
vi /etc/samba/smb.conf

Edit your smb.conf so that it looks like this:

security = share
guest account = nobody

comment = Sharing
path = /home/pi/Downloads
public = yes
writable = no
browsable = yes
create mask = 0765
guest ok = yes

Last step, once you’re confident that the startup script runs as it should and everything is appropriately in place, you can stick the script in your /etc/rc.local, and you’ll have everything in place.

sudo echo "sudo -u pi /home/pi/vpnconnect &" >> /etc/rc.local

That’s it! It was a fun starting project for the Pi, and has been very handy in keeping seeds running full time without having to the have a VPN running full time on my personal computer.

Dantana • May 17, 2015

Previous Post

Next Post


  1. Nick September 29, 2015 - 5:06 am Reply

    Thanks for this. Any reason you used libtorrent-rasterbar-0.16.19.tar.gz rather than libtorrent-rasterbar-1.0.5.tar.gz for the libtorrent version?

    • Dantana October 1, 2015 - 1:11 am Reply

      Compatibility with Deluge. When trying to build Deluge from source with libtorrent-rasterbar-1.0, some errors popped up that I couldn’t easily debug through, so I ended up just going back to the slightly older version.

Leave a Reply

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