This post is a follow up of my previous post about using Raspberry pi as a media server and a torrent box. Since last time, I’ve managed to fix up most of the problems that came up and now my Raspberry Pi setup is working well as a media server and torrent box. The major update is that the whole rig sits inside an old metal ammunition box. I went out of city for 4-5 days twice in last 6 weeks after turning it on and the whole thing worked extremely well.  It boots up and starts all required processes in case of a power failure without any intervention. As of now it’s not accessible from internet, but I’d rather keep it this way . May be if something comes up in near future then I might think about enabling connections from other networks, but it’s pretty much adequate for now. I had taken some pictures while doing all this, but can’t  find them.
Since last time, I’ve moved the whole set up in to an old metal ammunitions box salvaged from a junkyard. The boxes were not exactly in good shape.  Dust and random debris was everywhere and there were big patches of rust where paint had been chipped off. So my first job was to clean the boxes by a blower, then washing them with water. Later on, I applied some rust remover on rust patches to clean away as much rust as possible. After this point, I applied a coat of clear spray paint on whole box.  It prevents further rusting and creates a nice shiny coat.
Next I bought an extension cord and took out the cord. After fixing the board inside ammunition box, I drilled a hole in the box using my drill, hammer and a file. It wasn’t an easy job with the tools I had. Proper tools for this kind of work in such a metal box are way too expensive. It isn’t exactly clean, but does the job. Now as I’m writing this, I now realise that the hole should’ve been bigger but too lazy to change it now. Next step was to solder the wire of extension cord back which was unexpectedly more difficult than I anticipated. Rest was pretty easy. Hard disk is placed on a aluminum heat sink salvaged from an old graphics card. Rest of the stuff like Raspberry Pi, USB hub and extension board are stuck using double sided tape to interior of box. This whole setup by  itself is pretty rugged and can take some rough handling apart from the power adapter which is a bit loose in extension board.
I was also thinking about installing a cooling fan to dissipate some heat, The fan from that old graphics card is just right for the job. It can be powered by attaching it to a USB cable powered by the USB hub. It’s voltage rating is higher but it ran perfectly fine on 5 V when tested. But the temperature of Raspberry Pi never exceeded 51 degrees even in  40 degrees weather, so dropped the idea.
I’ve also installed Kodi on it and now it can be connected to the TV via HDMI and media played live. Streaming as described above works too, but finding a particular file to play can be difficult when you have a large number of files with no proper naming convention. Kodi can also be accessed over HTTP but haven’t had the time to check the functions yet.  Attached to TV via HDMI, it works pretty well. All of this can be controlled via TV remote or any of dozens of Android apps. The whole setup remains mostly powered on unless I am not streaming, downloading or seeding something. Pi can be shutdown remotely but haven’t tried to enable remote power on option yet.
After purchasing a Netflix subscription, it seems that this box will not be as heavily used, but is still pretty vital considering the limited library available in India.
Following configuration changes were made since last post:
1) Transmission as a torrent client and it’s web interface start automatically at each boot up.
2) File sharing service Samba for accessing files on attached hard disk from other computers on network.
3) miniDLNA for streaming media to other devices.
4) Health and running status of setup can be checked via NoMachine and Android applications based on ssh.
Following are configuration files, mostly for my record:
SMB
#
# Sample configuration file for the Samba suite for Debian GNU/Linux.
#
#
# This is the main Samba configuration file. You should read the
# smb.conf(5) manual page in order to understand the options listed
# here. Samba has a huge number of configurable options most of which
# are not shown in this example
#
# Some options that are often worth tuning have been included as
# commented-out examples in this file.
#  – When such options are commented with “;”, the proposed setting
#    differs from the default Samba behaviour
#  – When commented with “#”, the proposed setting is the default
#    behaviour of Samba but the option is considered important
#    enough to be mentioned here
#
# NOTE: Whenever you modify this file you should run the command
# “testparm” to check that you have not made any basic syntactic
# errors.
#======================= Global Settings =======================
[global]
## Browsing/Identification ###
# Change this to the workgroup/NT-domain name your Samba server will part of
   workgroup = WORKGROUP
# Windows Internet Name Serving Support Section:
# WINS Support – Tells the NMBD component of Samba to enable its WINS Server
#   wins support = no
# WINS Server – Tells the NMBD components of Samba to be a WINS Client
# Note: Samba can be either a WINS Server, or a WINS Client, but NOT both
;   wins server = w.x.y.z
# This will prevent nmbd to search for NetBIOS names through DNS.
   dns proxy = no
#### Networking ####
# The specific set of interfaces / networks to bind to
# This can be either the interface name or an IP address/netmask;
# interface names are normally preferred
;   interfaces = 127.0.0.0/8 eth0
# Only bind to the named interfaces and/or networks; you must use the
# ‘interfaces’ option above to use this.
# It is recommended that you enable this feature if your Samba machine is
# not protected by a firewall or is a firewall itself.  However, this
# option cannot handle dynamic or non-broadcast interfaces correctly.
;   bind interfaces only = yes
#### Debugging/Accounting ####
# This tells Samba to use a separate log file for each machine
# that connects
   log file = /var/log/samba/log.%m
# Cap the size of the individual log files (in KiB).
   max log size = 1000
# If you want Samba to only log through syslog then set the following
# parameter to ‘yes’.
#   syslog only = no
# We want Samba to log a minimum amount of information to syslog. Everything
# should go to /var/log/samba/log.{smbd,nmbd} instead. If you want to log
# through syslog you should set the following parameter to something higher.
   syslog = 0
# Do something sensible when Samba crashes: mail the admin a backtrace
   panic action = /usr/share/samba/panic-action %d
####### Authentication #######
# Server role. Defines in which mode Samba will operate. Possible
# values are “standalone server”, “member server”, “classic primary
# domain controller”, “classic backup domain controller”, “active
# directory domain controller”.
#
# Most people will want “standalone sever” or “member server”.
# Running as “active directory domain controller” will require first
# running “samba-tool domain provision” to wipe databases and create a
# new domain.
   server role = standalone server
# If you are using encrypted passwords, Samba will need to know what
# password database type you are using.
   passdb backend = tdbsam
   obey pam restrictions = yes
# This boolean parameter controls whether Samba attempts to sync the Unix
# password with the SMB password when the encrypted SMB password in the
# passdb is changed.
   unix password sync = yes
# For Unix password sync to work on a Debian GNU/Linux system, the following
# parameters must be set (thanks to Ian Kahan <<kahan@informatik.tu-muenchen.de> for
# sending the correct chat script for the passwd program in Debian Sarge).
   passwd program = /usr/bin/passwd %u
   passwd chat = *Enter\snew\s*\spassword:* %n\n *Retype\snew\s*\spassword:* %n\n *password\supdated\ssuccessfully* .
# This boolean controls whether PAM will be used for password changes
# when requested by an SMB client instead of the program listed in
# ‘passwd program’. The default is ‘no’.
   pam password change = yes
# This option controls how unsuccessful authentication attempts are mapped
# to anonymous connections
   map to guest = bad user
########## Domains ###########
#
# The following settings only takes effect if ‘server role = primary
# classic domain controller’, ‘server role = backup domain controller’
# or ‘domain logons’ is set
#
# It specifies the location of the user’s
# profile directory from the client point of view) The following
# required a [profiles] share to be setup on the samba server (see
# below)
;   logon path = \\%N\profiles\%U
# Another common choice is storing the profile in the user’s home directory
# (this is Samba’s default)
#   logon path = \\%N\%U\profile
# The following setting only takes effect if ‘domain logons’ is set
# It specifies the location of a user’s home directory (from the client
# point of view)
;   logon drive = H:
#   logon home = \\%N\%U
# The following setting only takes effect if ‘domain logons’ is set
# It specifies the script to run during logon. The script must be stored
# in the [netlogon] share
# NOTE: Must be store in ‘DOS’ file format convention
;   logon script = logon.cmd
# This allows Unix users to be created on the domain controller via the SAMR
# RPC pipe.  The example command creates a user account with a disabled Unix
# password; please adapt to your needs
; add user script = /usr/sbin/adduser –quiet –disabled-password –gecos “” %u
# This allows machine accounts to be created on the domain controller via the
# SAMR RPC pipe.
# The following assumes a “machines” group exists on the system
; add machine script  = /usr/sbin/useradd -g machines -c “%u machine account” -d /var/lib/samba -s /bin/false %u
# This allows Unix groups to be created on the domain controller via the SAMR
# RPC pipe.
; add group script = /usr/sbin/addgroup –force-badname %g
############ Misc ############
# Using the following line enables you to customise your configuration
# on a per machine basis. The %m gets replaced with the netbios name
# of the machine that is connecting
;   include = /home/samba/etc/smb.conf.%m
# Some defaults for winbind (make sure you’re not using the ranges
# for something else.)
;   idmap uid = 10000-20000
;   idmap gid = 10000-20000
;   template shell = /bin/bash
# Setup usershare options to enable non-root users to share folders
# with the net usershare command.
# Maximum number of usershare. 0 (default) means that usershare is disabled.
;   usershare max shares = 100
# Allow users who’ve been granted usershare privileges to create
# public shares, not just authenticated ones
   usershare allow guests = yes
#======================= Share Definitions =======================
[homes]
   comment = Home Directories
   browseable = no
# By default, the home directories are exported read-only. Change the
# next parameter to ‘no’ if you want to be able to write to them.
   read only = yes
# File creation mask is set to 0700 for security reasons. If you want to
# create files with group=rw permissions, set next parameter to 0775.
   create mask = 0700
# Directory creation mask is set to 0700 for security reasons. If you want to
# create dirs. with group=rw permissions, set next parameter to 0775.
   directory mask = 0700
# By default, \\server\username shares can be connected to by anyone
# with access to the samba server.
# The following parameter makes sure that only “username” can connect
# to \\server\username
# This might need tweaking when using external authentication schemes
   valid users = %S
# Un-comment the following and create the netlogon directory for Domain Logons
# (you need to configure Samba to act as a domain controller too.)
;[netlogon]
;   comment = Network Logon Service
;   path = /home/samba/netlogon
;   guest ok = yes
;   read only = yes
# Un-comment the following and create the profiles directory to store
# users profiles (see the “logon path” option above)
# (you need to configure Samba to act as a domain controller too.)
# The path below should be writable by all users so that their
# profile directory may be created the first time they log on
;[profiles]
;   comment = Users profiles
;   path = /home/samba/profiles
;   guest ok = no
;   browseable = no
;   create mask = 0600
;   directory mask = 0700
[printers]
   comment = All Printers
   browseable = no
   path = /var/spool/samba
   printable = yes
   guest ok = no
   read only = yes
   create mask = 0700
# Windows clients look for this share name as a source of downloadable
# printer drivers
[print$]
   comment = Printer Drivers
   path = /var/lib/samba/printers
   browseable = yes
   read only = yes
   guest ok = no
# Uncomment to allow remote administration of Windows print drivers.
# You may need to replace ‘lpadmin’ with the name of the group your
# admin users are members of.
# Please note that you also need to set appropriate Unix permissions
# to the drivers directory for these users to have write rights in it
;   write list = root, @lpadmin
[downloads]
path = /hdd
browseable = yes
   read only = no
   guest ok = yes
[Data]
path = /hdd/hd1
browseable = yes
   read only = no
   guest ok = yes
SSH
# Package generated configuration file
# See the sshd_config(5) manpage for details
# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes
# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 1024
# Logging
SyslogFacility AUTH
LogLevel INFO
# Authentication:
LoginGraceTime 120
PermitRootLogin without-password
StrictModes yes
RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile %h/.ssh/authorized_keys
# Don’t read the user’s ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don’t trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes
# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no
# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no
# Change to no to disable tunnelled clear text passwords
#PasswordAuthentication yes
# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no
#MaxStartups 10:30:60
#Banner /etc/issue.net
# Allow client to pass locale environment variables
AcceptEnv LANG LC_*
Subsystem sftp /usr/lib/openssh/sftp-server
# Set this to ‘yes’ to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of “PermitRootLogin without-password”.
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to ‘no’.
UsePAM yes
TRANSMISSION settings.json
{
    “alt-speed-down”: 50, 
    “alt-speed-enabled”: false, 
    “alt-speed-time-begin”: 540, 
    “alt-speed-time-day”: 127, 
    “alt-speed-time-enabled”: false, 
    “alt-speed-time-end”: 1020, 
    “alt-speed-up”: 50, 
    “bind-address-ipv4”: “0.0.0.0”, 
    “bind-address-ipv6”: “::”, 
    “blocklist-enabled”: false, 
    “blocklist-url”: “http://www.example.com/blocklist“, 
    “cache-size-mb”: 4, 
    “dht-enabled”: true, 
    “download-dir”: “/mnt/hd2/dl”, 
    “download-limit”: 100, 
    “download-limit-enabled”: 0, 
    “download-queue-enabled”: true, 
    “download-queue-size”: 5, 
    “encryption”: 1, 
    “idle-seeding-limit”: 30, 
    “idle-seeding-limit-enabled”: false, 
    “incomplete-dir”: “/mnt/h5/dl”, 
    “incomplete-dir-enabled”: false, 
    “lpd-enabled”: false, 
    “max-peers-global”: 200, 
    “message-level”: 1, 
    “peer-congestion-algorithm”: “”, 
    “peer-id-ttl-hours”: 6, 
    “peer-limit-global”: 200, 
    “peer-limit-per-torrent”: 50, 
    “peer-port”: 51413, 
    “peer-port-random-high”: 65535, 
    “peer-port-random-low”: 49152, 
    “peer-port-random-on-start”: false, 
    “peer-socket-tos”: “default”, 
    “pex-enabled”: true, 
    “port-forwarding-enabled”: true, 
    “preallocation”: 1, 
    “prefetch-enabled”: 1, 
    “queue-stalled-enabled”: true, 
    “queue-stalled-minutes”: 30, 
    “ratio-limit”: 2, 
    “ratio-limit-enabled”: false, 
    “rename-partial-files”: true, 
    “rpc-authentication-required”: false, 
    “rpc-bind-address”: “0.0.0.0”, 
    “rpc-enabled”: true, 
    “rpc-password”: “{87gj106666666h98i8h;lo666666666662″, 
    “rpc-port”: 9091, 
    “rpc-url”: “/transmission/”, 
    “rpc-username”: “transmission”, 
    “rpc-whitelist”: “192.168.1.*”, 
    “rpc-whitelist-enabled”: false, 
    “scrape-paused-torrents-enabled”: true, 
    “script-torrent-done-enabled”: false, 
    “script-torrent-done-filename”: “”, 
    “seed-queue-enabled”: false, 
    “seed-queue-size”: 10, 
    “speed-limit-down”: 100, 
    “speed-limit-down-enabled”: false, 
    “speed-limit-up”: 100, 
    “speed-limit-up-enabled”: false, 
    “start-added-torrents”: true, 
    “trash-original-torrent-files”: false, 
    “umask”: 18, 
    “upload-limit”: 100, 
    “upload-limit-enabled”: 0, 
    “upload-slots-per-torrent”: 14, 
    “utp-enabled”: true
}

A few weeks back I bought a Raspberry Pi 2 with a vague idea of using it as a device for downloading torrents and streaming videos. Using a PC for this work seems like an overkill. But work, travel and other stuff didn’t leave enough time and I could work on this project only for a few minutes every week. There were  a few problems and it delayed the whole project further. But after some effort, almost everything is ready and working fairly well. There are still some things which need to be sorted out, but it meets my needs for now. I will keep on tinkering to improve and sort out the kinks. This post is about the equipment, it’s configuration and use. I am not writing down all the details as most of procedures I used are easily found on internet. To begin with, I bought the following stuff:

Raspberry Pi 2 Board.
A plastic case.
Power adapter and USB cable.
A USB WiFi adapter.
HDMI cable.
HDMI to VGA adapter.
Cat5 Ethernet cable.
A memory card with OS pre-installed.
A pen drive I already had. Will replace it later with a hard disk.
Used keyboard, mouse and monitor of my existing PC.

1st Phase, WiFi:

First step of the project was to assemble everything and connecting it up to a monitor which was trivial. essentially it becomes a matchbox sized personal computer. As the seller had already installed an OS on it, I just booted and started working. But the WiFi adapter included just refused to work. I must have spent more time on this adapter troubleshooting than rest of the steps combined. Then I gave up on it, reset the system and downloaded a new version of OS. Surprisingly my older and new USB Wifi adapters both worked fine without any need of installing any drivers.
2nd Phase, Command Line and GUI access:

Once connectivity issue was solved, I configured SSH server and installed NoMachine for remote GUI login as unplugging and plugging in monitor and keyboard wires was becoming annoying. SSH had some problem in beginning, but was fixed easily. After this, I could access the Raspberry from my phone and PC. NoMachine can also be used from android.
3rd Phase, External Storage :

Adding this was pretty straight forward. Make a folder, mount it, apply necessary permissions and make it mount on every boot.
4th Phase, Torrent client :

Installed a torrent client, Transmission. I needed a torrent client which can be accessed via a web GUI. There are 3-4 options available and I tried them all before settling on Transmission. I still can’t get the web interface to run on every boot, but I am working on it and hopefully will be able to sort it out soon. I also tried Deluge and rTorrent, but wasn’t really satisfied with them. In the meanwhile, Transmission works fairly well.
5th Phase, External IP access:

Another step which I still haven’t figured out is how to allow access to Raspberry from an external network. I have downloaded and installed NoIp client which works well. But for some reason, port forwarding is not working as it should. So I can control the setup only when I’m connected to home network. It’s not really a big issue right now and I expect it to be solved soon.

6th Phase, Media Server:

Next step is to stream the videos to my TV and android tablet. Thankfully, it’s a smart TV so there is no need to buy another gadget like Chromecast to enable networking. Enabling this feature on Raspberry pi was achieved by installing MiniDLNA. Takes 2-3 minutes to install and configure. My android tablet can stream movies to TV but can’t play streaming videos by default. I tried ES File Explorer first which worked, but didn’t really liked it that much as it seemed too bloated. Installed iMediaShare which works pretty well.

So this is the basic overview of my new setup of downloading movies and watching them on TV and android tablet. I can access media on my Raspberry Pi, Tablet and  Still needs some fine tuning but does the job for now.

Since last 3 months, I am on an shitty internet connection which as a download limit of just 15 GB and costs an arm and leg. But stuck with it because the only other option in my area is just as bad. So now it happened that this 15 GB download limit was getting over within 4-5 days and rest of the duration the bandwidth gets throttled to snail like 512 Kbps for rest of the month.  All of this data was gone while I was not using any bandwidth intensive application. No torrents, videos, music streaming. Just the usual work on Opera and Chrome browsers and email.

This was bugging me too much because my current ISP (Failtel Fraudband) is notorious for shady business practices and ripping off customers. So to be doubly sure, I downloaded and installed Glasswire application to monitor my bandwidth usage.

Bandwidth usage report

Bandwidth usage report

As clear from the report above, Google Chrome is the largest bandwidth hog even though it’s my secondary browser and it mostly runs in background while I do my work on Opera. All of this bandwidth was consumed in just about 2 hours that I had it on.  While looking for a solution, I  found many people complaining of the same thing and found out that Google Chrome pre-fetches data from some most frequented websites and also automatically downloads some data from other links on the websites you are on.

Make webpages load faster

You can make webpages load faster by telling Google Chrome to prerender (preload) links. Google Chrome does this by predicting what links you might click, preparing them to load instantly for you.

For example:

  • When you’re browsing a blog, you might click “next post” when you’re done reading. The blog can tell Google Chrome to pre-load the “next post,” so the page shows instantly when you click it.
  • When you’re typing a web address in the address bar, Chrome will begin to prerender that page if it’s confident about which site you’re likely to visit (based on your local history). This will make the page show up faster when you hit enter.
    Google’s Instant Pages search feature in Chrome is powered by Chrome’s prerendering technology.

From https://support.google.com/chrome/answer/1385029?hl=en

 

While this is a good option for connections with unlimited bandwidth, it is just a nuisance for others.  This means that the Chrome is pre-fetching data from websites which in a number of instances is just a waste of bandwidth. This option can be found by following steps as explained in above mentioned link:

  1. In the top-right corner of the browser window, click the Chrome menu icon .

  2. Select Settings.

  3. At the bottom of the page, click Show advanced settings.

  4. In the “Privacy” section, check “Prefetch resources to load pages more quickly.” If you want to undo this permission, simply uncheck the box.

As I wanted to save bandwidth, I unchecked the box.  After disabling this option, I kept Chrome running for half an hour and the bandwidth usage was minimal.

While looking for detailed logs, I also found out that Mozilla Thunderbird, which I use as my primary email client was also a big bandwidth hog, downloading 176 MB bandwidth in a single day. While I use it almost all day long, usage of this much data for text emails is way too much. By default, Thunderbird checks for messages every 10 minutes. I increased that interval to 30 minutes in Account Settings as visible in screenshot below.

Increase duration of checking messages in Thunderbird

Apart from that, a major bandwidth hog is the countless number of people sending messages with huge attachment, useless images and too many scammers and spammers with their malicious attachments. In the same menu, you can find option Synchronization & Storage.

Size limit for downloads in Thunderbird

In this, you can tell Thunderbird to not download any message bigger than your specified limit. I put in 1000 KB, but you can use any value you want. Additionally, the option just above “Synchronize the most recent” can also be given a lower value to decrease the amount of data spent on mostly un-needed traffic.

This work was done on Windows 7. I don’t know if the settings are same on Linux, but there is no reason that anything will be different.