Tutorial 1: Setting up RPi as a Torrent Server
by lezigg
In this tutorial I document what I did to set up Raspberry Pi (RPi) as a torrent server. Before you begin, please set up your RPi correctly. See: http://elinux.org/RPi_Easy_SD_Card_Setup.
I used Debian Squeeze 6.0.4 for my OS. Instructions may differ for Arch, Fedora, or for some of the other microOS distributions that are out there. Because the GUI on Debian Squeeze (LXDE) can be a bit of a memory hog (LXDE is actually quite light weight…but we only have 256mb of ram to work with), the entire tutorial will be done in command line. In addition, you need the following parts:
- A USB External Hard Drive
- USB wire (for External Drive)
- Ethernet wire
-
A GOOD quality power supply (>= 2A current maximum).
This tutorial is presented in three parts. I give the basic setup on the RPi itself to get the task done. After this, more advanced tweaking options for transmission torrent client are given. Depending on your kernel or possible errors that occur, I outline some additional problems I encountered, and how they were solved.
Note: For the code examples given, single arrow “>” means command line input. Double arrow “>>”means the lines one puts in the configuration files.
Basic Setup:
1) First let’s make our lives easier. On Debian, file permissions can cause some obstructions when running and editing files. Lets setup root and login as root. By default root access on Debian is done with sudo, and the “root” user is not setup. Go to terminal and type:
> sudo passwd root
and give root a password. Now log out of the system, and sign in as root.
2) With root access, lets get our torrent client. I chose transmission because its well supported and already available in our Debian repository. Type:
> apt-get update
> apt-get install transmission transmission-daemon transmission-cli
There are actually three different packages for the torrent client: transmission, transmission-daemon, and transmission-cli. transmission is the regular application that a desktop user would run; in an X windows environment it would launch a GUI front end.
Transmission is a lot more robust than this; transmission-daemon is a ‘headless’ (non-GUI) form of transmission used for more complex setups (such as, having multiple instances of transmission running across multiple computers in a LAN). We only need one instance of transmision-daemon for our purposes.
3) Once installed, locate the transmission-daemon folder on your system. Type:
> cd /etc/transmission-daemon ; ls
You will see a number of files, but we care about the settings.json. Type:
> nano settings.json
And open it up. We are going to set up the ports for transmission-daemon traffic, and for the webUI port. Specifically, look for lines that start with “rpc”. Here are the RPC lines:
“rpc-enabled”: true,
“rpc-password”: “<your password>”,
“rpc-port”: “<your chosen port>”,
“rpc-username”: “<your username>”,
Here we are enabling the Remote client. Set “rpc-enabled” to true, as well as your chosen port, password and user name.
Note #1: Security conscious users might be worried about storing their password in plain text. Dont worry: when transmission starts running, it reads this file and replaces the password entered with a hashed password. You can check this out yourself to verify it.
Note #2: You need to check to make sure your ports are free. Before doing this, type:
> netstat -nap.
and see if your desired port is already registered!
4) Next, configure your LAN router to allow for outside connections. Get your IP address for your RPi by typing:
> ifconfig eth0
If you are on a LAN, your IP address should have the form 192.168.X.Y.
Log into your router, and in the ‘Virtual Servers’ tab, associate your chosen port number to your RPi’s given IP address. Here it is for my router: I’ve chosen port 8002 for the webconsole, and 8001 for incoming torrent traffic.
Most routers have DHCP enabled, so we need a static IP address for port mappings to hold. Configure your router to permanently assign the RPi and IP address, so the mappings sticks. Again, it’s up to you to find this option on your router. On my router (a D-link), I was able to do this under “Network Settings”.
Mounting a Hard Drive:
5) We need to connect an external hard drive to Linux, to store our torrent files. I happened to have an NFTS file system on my external hard drive. RPi will recognize the drive, but it may not mount it correctly.
To start, connect your hard drive via USB and let it initialize. Now type:
> fdisk -l
The tables that are produced represent each physical hard drive; every row of the table is a partition on the hard drive. Look for the table with “NFTS” and record the device boot path. In my example, it is /dev/sda1. Sample console output below:
6) For Debian, mounted drives are accessed through the /media folder. Lets mount the drive:
> cd /media
> mkdir <your directory name>
> mount -t ntfs-3g /dev/sda1 /media/<your directory name>
Above, we made a directory for our mount command to associate the mounted drive to a folder. Now that this is done, let’s go to settings.json and set up our folders for transmission-daemon:
>cd /etc/transmission-daemon
> nano settings.json
Look for the following lines, and type in the following information:
>>”download-dir”: “/media/<your directory name>/<folder on drive>”,
>>”incomplete-dir”: “/media/<your directory name>/<some other folder on drive>”,
>>”incomplete-dir-enabled”: true,
Where <your directory name> is the name chosen when we made the directory (above). Save the file.
7) Finally, we would like our transmission torrent client to start up automatically when our RPi is turned on. We need to edit the rc.local start up
file to make this possible.
> cd /etc
> nano rc.local
Add the following lines to the very bottom of the file:
>> mount -t ntfs-3g /dev/sda1 /media/<your directory name>
>> transmission-daemon &
Restart your RPi. Basic setup is done!
Check that RPi is Working Correctly:
1) First check if you can access your torrent server from inside your LAN. In a browser, type: <RPi’s LAN address>:<web client port number>. A login box should appear:
Login with your creditials. If successful, you will see the web console like so:
2) Now check to see if you can access from outside your LAN. You will need the IP address assigned to your modem, from your ISP (google: whats my ip? to get this). In a browser type: http://<your modem ISP>:<your webUI port number>. You should go straight to the webUI console, if you already logged in in step (1).
Additional Setup:
There are a number of other features in settings.json that can be set. Here are some of note:
- “cache-size-mb”: Sets our cache size before writing to the External USB drive.
- “download-limit”, “download-limit-enabled”: Set your download limits.
- “encryption”: Set to 1 to turn it on.
- “max-peers-global”, “peer-limit-global”,”peer-limit-per-torrent”: Control the number of peers that connect to your server.
- “open-file-limit”: Limit how many torrent files can download at once.
- “ratio-limit”, “ratio-limit-enabled”: Limit your Leech:Seed Ratio. Be nice and set it to 1.000 or above :).
- “script-torrent-done-enabled”,”script-torrent-done-filename”: Quite an interesting feature. When your torrent file finishes, you can run a script to process it, or move it to another directory.
- “speed-limit-down”, “speed-limit-down-enabled”, “speed-limit-up”, “speed-limit-up-enabled”, “upload-limit”, “upload-limit-enabled”, “upload-slots-per-torrent”: This whole list of options controls download and upload speeds.
Problems and Hangups:
Alas, doing the basic setup probably won’t work for everyone. I had a number of issues I had to solve before I could get things working.
1) Incomplete torrent files don’t stick around: Make sure the “incomplete-dir-enabled” option is set to True (1).
2) My RPi’s Ethernet Driver keeps crashing!
This is by far the biggest issue for the whole setup. You might find that doing file transfers or Downloads at high speeds (> 500k/sec) causes the RPi ethernet driver to crash. You won’t be able to SSH into the RPi, or access the internet with it, but the RPi runs fine otherwise.
The reasons for this vary. Perhaps a bit of background is in order.
The RPi Ethernet and USB ports are controlled by one single chip, which share the same system bus. Naturally, our torrent box application puts a lot of load on this chip and bus. Not only is a lot of traffic flowing through the ethernet port, but we are also using the same system bus to write to the USB connected hard drive. More specifically, Ethernet packets are being saved to a cache in memory (RAM), as are the incomplete torrent files. RPi also writes cached information to the disk, while accessing other disk files to supply information to other leechers on our torrent network. So there is high two-way traffic across the bus. You better have a well compiled kernel to handle all this traffic correctly.
Here are a number of solutions to try (in order of complexity), to avoid an Ethernet Driver Crash:
(a) Use a proper power supply: I’ve mentioned this before. And I know using your microUSB phone charger to power the RPi is tempting. But high External Hard Drive + Ethernet usage needs more than the 700mA minimum quoted in the RPi operating specs. Most phone power supplies are 1A or below. Please try a more beefy power supply. Really.
(b) Change your Kernel: Older versions of the ARM kernel aren’t compiled to handle the high system bus traffic problem outlined above. A newer kernel patch has been recently issued to alleviate this problem. Apparently the Arch Linux RPi distribution has a kernel update that patches this automatically. Other distributions do not, and you have to replace your kernel manually:
In theory, the Linux kernel should be perfectly swappable and your system should boot, after you swap your old kernel for the patched one. For the brave, type the following commands to do so:
> cd /boot
> wget http://positron.dckd.nl/~jeroen/stuff/rpi-ipv6-kernel.img
> mv kernel.img kernel.backup.img
> mv rpi-ipv6-kernel.img kernel.img
and restart your system. I got my kernel from the RPi fourm thread [ http://www.raspberrypi.org/phpBB3/viewtopic.php?f=28&t=5142&hilit=%5Bsolved%5D+ethernet&start=25 ], and it alleviated my Ethernet problems.
Note: Recovering the kernel: This worked for me (and many others), but in the event it doesn’t work for you – or worse, your RPi doesn’t boot, do the following to recover your old kernel. Access your RPi file system by plugging the SD card in another system, and navigate to the /boot folder. Then delete the new kernel.img file, and reinstate the old backup one. So:
> rm -f kernel.img
>mv kernel.backup.img kernel.img
(c) Edit vm.cache: Once your kernel is patched, the torrent server should work fine in most cases. If not, you can edit the sysctrl.conf file to increase cache size, like so:
>cd /etc
> nano sysctl.conf
…. locate the line vm.cache_size….
>> set vm.cache_size = 32000
And save the file. Restart your system.
Change Log and Thanks:
27/08/2012: Fixed command line typos [therulerofchina]
END
Does all the routers come with port forwarding?
Almost all new routers these days should have port forwarding. Some of the older/really cheap ones may not.
some routers will list it as “Virtual servers” its the same thing e.g. TP-Link use the term virtual servers
Thanks for this, the various transmission packages had me confused.
if anyone gets an error when trying
> apt-get install transmission, transmission-daemon, transmission-cli
try this instead:
> apt-get install transmission transmission\-daemon transmission\-cli
this happened for me, hope it helps 😀
Good catch! I was writing it in English instead of command line format (hence, the commas).
I found that for my system, I didn’t need to escape the “-” characters. Just a heads up for people.
Another little thing that may be worth mentioning is that if transmission is running while you are changing the settings it will simply put them back when you reboot. I had to type “killall transmission-daemon” before editing settings.json before the changes would stick
Happy I checked here, thanks for that I was having that exact problem when ever I restarted.
could you give me an example of how the rc.local file looks like? There is other stuff in there and I am uncertain where to put it.
When I look up information about starting a daemon at boot I find info about /etc/init.d what is going on there?
Here transmission overwrites the settings.json file to default everytime i restart the Pi.. Chmodding it to 444 is useless because it will not be able to enter the needed hashed password, and even if I chmod it to 444 it will STIL replace the file with the default, weird eh?
If ONLY I could READ. In the README file it says:
Currently transmission overwrites the settings.json configuration file
on exit. The daemon can be instructed to reload the config with a SIGHUP,
or
# invoke-rc.d transmission-daemon reload
Otherwise changes made manually to the file while the daemon is running
will be silently overwritten on exit.
So you might want to add that to your tutorial, that you have to stop the client before editing the settings.json file 🙂
yes, took me a while too… killed the deamon and set the json.
I was having problems when downloading 2 files at the same time at decent speeds and writing to an external USB drive. I was using a wifi dongle, but I guess it’s the same problem with overloading the bus.
I fixed the problem simply by increasing the cache-size-mb setting from 2 to 64. It should keep things in memory long enough to decrease IO operations to the disk. So far it’s working anyway.
Thanks for the guide.
Thanks for the tutorial, but I’m having a problem: When I reboot my rpi the transmission seems to start before the USB hdd mount, and I get errors and have to re-open all my torrents that were not finished. Could you help? Maybe adding some sort of delay for the transmission daemon? (I’m a linux newbie)
tried placing sleep in between mounting and starting daemon on the rc.local?
[…] file should be, chestnutty though not peanuts :p. Setting up wasn’t any tougher with these instructions. I only followed the part for transmission and ntfs-3g (Default ntfs driver from the kernel is […]
If you are experiencing slow download speeds (compared to your home computer), you should go into the settings.json file and increase the cache size. So
>cd /etc/transmission-daemon
> nano settings.json
and increase the value of “cache-size-mb”
Would you happen to still have a copy of that alternative kernel? The download you posted is not working anymore and I can’t seem to find a copy elsewhere. Many thanks.
So what are the stable download speeds that are to be expected? I mean without the bottlenecks or freezes. I’m really interested in buying a RPi for a torrent box but considering a 500Kb/s download speed it almost doesn’t seem worth it…
My external hard drive has its own power supply. Will it have the mentioned Ethernet driver crash problems?
its not because the drive doesnt have the power supply its because data sent and received on the usb ports and ethernet port are all handles by one chip. If you use a good PSU (as the poster mentioned) thats one way to avoid issues – the other is the kernel update
Unfortunately iam stuck at the beginning of the process.
When i edit settings.json, save the file and then reboot, the file come back to the original version.
My modifications doesn’t stick!
Even if i do the manipulations in SU
Do you know where this could come from ?
Oups i just found the solutions with the previous comments.
Transmission is up and running, but i got an “input / output error” on every files i try to download…
Do you know where this is coming from ?
it is possible that your permissions are set incorrectly for your download directories or transmission can no longer see them. I had a similar issue with sabnzbd and other programs not being able to write to samba shares
Lezigg, can you show me how to use custom web interface like Kettu with Transmission on Raspberry Pi? I need to be able to select download locations for each of my downloads.
I just googled around and found this really useful:
to find out what settings.json file is actually in use run “transmission-daemon -f”
that will spit out a log of what is going on and say which settings.json file is being saved to
when i initially tried to run i was editing the settings.json in the /etc directory
[…] LINK […]
I am such a noob. I’m following this word for word. I’m doing this all via the command line on the raspberry pi. When I get to the root portion it didn’t seem to do anything so I installed after typing sudo su. When I get to the cd/etc/transmission-daemon;ls. It says no such file or directory exists. So I don’t understand how to find and edit the settings.json.
Great tutorial!
Thank you
[…] http://stevenhickson.blogspot.com/2012/10/using-raspberry-pi-as-web-server-media.html https://cumulativeparadigms.wordpress.com/2012/08/13/tutorial-1-setting-up-rpi-as-a-torrent-server/ […]
[…] Torrent client – You need 2 days to complete a download, but you are worried about the electricity bills with your Core i7 desktop PC? You can use a super power-efficient RPi and forget about it. […]
[…] Torrent client – You need 2 days to complete a download, but you are worried about the electricity bills with your Core i7 desktop PC? You can use a super power-efficient RPi and forget about it. […]