Contribute to the global «Linux Distribution Network» by creating a dedicated secure torrent download megalith that consumes as little as 10 watts. It is possible and it will of course be based on the Raspberry Pi.

Loading and sowing (you do sowing, right? Good people baited at least in a ratio of 2.0) is a tough task for any regular computer, and that means you’re using far more power than you need by leaving it on overnight. What if you could offload that task to a low-powered Raspberry Pi, small enough to fit under a floorboard and barely breaking 10W of power to do it all. That’s exactly what I’ll show you how to do today.

Here is the plan:

  • Install Raspberry Pi with a USB drive and transfer the system drive to USB to extend the life of our SD card.
  • Share it online.
  • Configure your VPN so that all traffic is routed through the VPN, securely, and everything stops if that connection fails. We don’t want the provider to know which Linux distribution we prefer.
  • Install the remotely controlled Transmission torrent client.

Sounds complicated, doesn’t it? I assure you, no more than a few hundred terminal commands. A lot of this is the same as our Raspberry Pi NAS. tutorial, so if you’re not that interested in torrenting and VPN, you can try this instead.

Flash drive

Start with a fresh install of Raspian, plug in an ethernet interface, and plug in a USB stick (via a powered USB hub, or more likely you’ll run into errors later like me) — it doesn’t need to be formatted yet. Log in remotely using the default pi/raspberry username/password combination and then run the command:

sudo raspi-config 

Change the amount of memory allocated to graphics to 16 megabytes — we’ll be using this completely headless, so you won’t need graphics memory. Come out and let’s set up some partitions on USB. We’re going to set up at least two — one for system use to save the life of our SD card, and the other to save downloads. First find out which drive is your USB.

 tail /var/log/messages 

In my case it was easy to identify as «sda». With that in mind, tweak the following command to run utility fdisk on the respective device.

 sudo fdisk /dev/sda 

Click p to view a list of current partitions. To remove any existing press d . Create a new primary partition with n then p . When it asks you for a size, enter + 8G . Now go ahead and create another partition for your torrent data (again, the main one) or more partitions if you like. W will write the new partition map to disk when you’re done.

Once the new table is written, use the following commands to format the disks as linux ext4 . Use additional commands if you have partitioned your drive into more than two partitions.

 sudo mkfs.ext4 /dev/sda1 sudo mkfs.ext4 /dev/sda2 sudo mkdir /mnt/systemdrive sudo mkdir /mnt/torrents sudo mount /dev/sda1 /mnt/systemdrive sudo mount /dev/sda2 /mnt/torrents df -h 

The last command will confirm that you have mounted the partitions correctly. Next, we want to copy the SD card data to disk — this will extend its lifespan by avoiding constant cache reads/writes etc. Install rsync, to do this:

 sudo apt-get install rsync sudo rsync -axv / /mnt/systemdrive 

This initiates a long series of file copying, so shake your fingers a little.

 sudo cp /boot/cmdline.txt /boot/cmdline.orig sudo nano /boot/cmdline.txt 

Adjust it like this:

 dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/sda1 rootfstype=ext4 elevator=deadline rootwait rootdelay=5 

Then change fstab, to mount them at startup.

 sudo nano /etc/fstab 

Add the following lines:

 /dev/sda1 / ext4 defaults,noatime 0 1 /dev/sda2 /mnt/torrents ext4 defaults 0 2 

Comment out the following line, which refers to the SD card:

 #/dev/mmcblk0p2 / ext4 defaults,noatime 0 1 

Reboot the pi with

 sudo reboot 

Sorting! Your Pi will now mount both the root data partition and your torrents partition.

Share The Drive: Samba

First make sure we’re up to date, uninstall the Wolfram Mathematica packages that always gave me problems doing absolutely anything with the Pi (math-kernel related stuff) and then install the necessary packages

 sudo apt-get update sudo apt-get dist-upgrade sudo apt-get remove wolfram-engine sudo apt-get install samba samba-common-bin sudo nano /etc/samba/smb.conf 

Click CTRL-W and type «security» to find the next line and comment it out.

 security = user 

Add the following to define our shared torrent folder:

 [torrents] comment = torrents path = /mnt/torrents valid users = @users force group = users create mask = 0775 force create mode = 0775 security mask = 0775 force security mode = 0775 directory mask = 2775 force directory mode = 2775 directory security mask = 2775 force directory security mode = 2775 browseable = yes writeable = yes guest ok = no read only = no 

Restart the Samba service:

 sudo service samba restart 

Next, we need to add a user to the system. Replace «jamie» with the username you want to log in with to access the shared folder. The following commands will then ask you to create your passwords, the first at the system level and the second for Samba. Change the last commands if you name your data drive something else (and here’s an example on file ownership in linux).

 sudo useradd jamie -m -G users sudo passwd jamie sudo smbpasswd -a jamie sudo chown pi:users /mnt/torrents chmod g+w /mnt/torrents 

Test — You should be able to connect from another computer on your network and read/write files to the new share. Check that they also appear on the Pi with ls from a folder /mnt/torrents .

VPN setup

Install required packages

 sudo apt-get install openvpn resolvconf 

Download the OpenVPN configuration files from your ISP. You can check out the list of the best VPNs here, but be sure to find one suitable for torrents. I use privacy.io , but Private Internet Access is another popular option in the torrent communities. In any case, you will be able to get a ZIP file with configurations and a certificate. Put them in your torrents folder, in a directory called openvpn . Change the following command to indicated to your config file, which will almost certainly be different from privacyIO.ovpn

 sudo openvpn --client --config /mnt/torrents/openvpn/privacyIO.ovpn --ca /mnt/torrents/openvpn/privacy.ca.crt --script-security 2 

openvpn-connections-output

If you get this output, you’re good. Click ctrl-c, to complete it. However, the need to enter a password is annoying, and we need a few modifications to add start and stop scripts. Edit the configuration file (again, replace the privacyIO.ovpn file with the .ovpn file provided by your ISP)

 nano /mnt/torrents/openvpn/privacyIO.ovpn 

First change the following line. Basically what we are saying is that we will store the username and password in a file called pass.txt.

 auth-user-pass /mnt/torrents/openvpn/pass.txt 

Save and enter:

 nano /mnt/torrents/pass.txt 

Enter your username on the first line and password on the next. Save and try connecting again:

  sudo openvpn --client --config /mnt/torrents/openvpn/privacyIO.ovpn --ca /mnt/torrents/openvpn/privacy.ca.crt --script-security 2 

You do not have to be bugged to enter this time. Hooray! Then open the configuration file again and add the following lines:

 route-up /mnt/torrents/openvpn/route-up.sh down-pre down /mnt/torrents/openvpn/down.sh 

This points to some scripts that we are going to create later to perform tasks when the connection is either successfully established or aborted. Make sure you are in the directory mnt/torrents/openvpn and then do the following:

 nano route-up.sh 

Add the following to ensure that traffic is sent through the VPN:

 #!/bin/sh iptables -t nat -I POSTROUTING -o tun0 -j MASQUERADE 

Then create a down.sh script

 nano down.sh 

Add:

 #!/bin/sh iptables -t nat -D POSTROUTING -o tun0 -j MASQUERADE 

Finally, we want the script to open a connection, rather than launch it from the command line, as we just did.

 nano vpn.sh 

Paste the start VPN command from earlier. If you forgot:

 sudo openvpn --client --config /mnt/torrents/openvpn/privacyIO.ovpn --ca /mnt/torrents/openvpn/privacy.ca.crt --script-security 2 

Now make all these scripts executable and run the VPN script on startup.

 chmod +x down.sh chmod +x route-up.sh chmod +x vpn.sh sudo nano /etc/rc.local 

Add the following line before the line exit 0 . We’re just saying to run this script on startup.

 /mnt/torrents/openvpn/vpn.sh 

Finally, reboot your system again.

ifocnfig - VPN registration

Login again and run ifconfig . You’ll know it works if you see the entry for tap0 (or tun0) and be able to successfully collapse the web page:

 curl //www..com 

Torrent client

Almost there now. Finally, we’re going to install Transmission, which is lightweight and has a nice web interface. The following commands install, then stop the daemon — since we need to configure it first — then open the configuration file for editing.

 sudo apt-get install transmission-daemon sudo /etc/init.d/transmission-daemon stop sudo nano /etc/transmission-daemon/settings.json 

Change «rpc-authentication-required» to false; change the «rpc whitelist» to include your local subnet — for example:

 "rpc-whitelist": "127.0.0.1,10.0.1.*", 

Add or customize the following if it’s already present:

 "download-dir": "/mnt/torrents", "watch-dir": "\/mnt\/torrents\/", "watch-dir-enabled": true, "umask": 2, 

Then edit the daemon startup file itself to fix some permission issues.

 sudo nano /etc/init.d/transmission-daemon 

Change USER = Transmission-Daemon on the USER=root . Restart the daemon.

 sudo service transmission-daemon reload 

Finally, we will set avahi-daemon to set up a bonjour/zeroconf network, which means we won’t need to use the Pi’s IP address to access it from a browser — instead we can use raspberrypi.local address.

 sudo apt-get install avahi-daemon 

Assuming your hostname is the default (raspberrypi, but can be changed with raspi-config) switch to:

http://raspberrypi.local:9091/transfer/web/

First, check if your torrent IP is properly masked through the VPN. Download a test torrent file from TorGuard — the download image looks like an ad, but it’s not — and put it in your shared torrent folder.

torrent IP registration

We have already configured Transmission to watch this folder for new torrents, so it should be added immediately. Go ahead and add some legal Linux distributions in there.

Transfer-Torrent-IP-test results

The IP check flow should return an error along with the discovered IP address. Make sure it’s not your home IP — if it is, the VPN hasn’t been set up correctly. By default, all torrents you drag into the folder will be renamed to .added and the .part file must be created before the transfer is complete. Make sure this is the case in your shared folder.

common drive

This is it! You now have a super-low-powered, secure, torrent-downloading Pi — leaving your workstation available for better things. Now you may want to add a UPnP server to stream media over the network, or use BitTorrent Sync to create your own cloud storage. own cloud storage own cloud storage What features will you be adding?

Похожие записи