Thursday, November 13, 2014

How to setup your Raspberry Pi as NAS

In a previous post I showed a video of my implementation of Boblight on OpenElec.

This post is dedicated to my setup that consists of two Raspberry Pi's:

  1. Running the OpenElec image acting as a streaming device.
  2. Running the Raspbian image image acting a NAS server and a headless Bittorrent client.
Why the two Pi's?
One can't handle all these tasks.

So, we have the first Pi as a streamer and these are the tasks we have for the second one:
  1. NFS (Network File System) server - to share access to the connected hard drives to NFS enabled devices.
  2. Transmission client - headless Bittorrent client to download content directly to the NAS server.
  3. DLNA server - for DLAN enabled devices that will connect directly
  4. NoIp client - I like having access to my NAS server and Bittorrent client when not at home.

Preparing the RPi

Flashing Raspbian image

All you have to do is download the Raspbian image from here. Then follow the instructions here to flash your SD card with the image you downloaded.

Configuring the system

Pop your SD card into the Pi and turn it on (Make sure to plug in your network cable). Start your favorite SSH application (Mine is Putty) and connect to 'raspberrypi'.


The username is 'pi' and the password is 'raspberry' (Write both username and password without the apostrophes).

Once logged in:
We'll begin with updating our system and repositories:
sudo apt-get update
sudo apt-get upgrade
sudo raspi-config
and select "Expand Root Partition to Fill SD Card" and reboot:
sudo reboot
For the next steps log back using SSH and again after every reboot

Mounting Hard Drives and setting up NTFS

To get NTFS support issue this command:
sudo apt-get install ntfs-3g

I usually like to mount my drives under /media/ not for any particular reason, just a habit.
To do so we will need to find the UUID of our drives and place their info and mounting point in the fstab file to auto mount the drives to the same place every time we reboot.

To get your drive's UUID:
sudo blkid /dev/sda1
Notice that your drive may not be sda1. Next we add it to the end of the file fstab
#My mounts
UUID=8C12261112260136 /media/Ohad_HD ntfs-3g defaults,auto,uid=1000,gid=1000,umask=002 0 0

NFS

To install NFS:
sudo apt-get install nfs-kernel-server

To setup a share do (I am sharing my hard drive that is call Ohad_HD):
sudo mkdir -p /export/Ohad_HD
sudo mount --bind /media/Ohad_HD /export/Ohad_HD
To make this bind happen automatically after every reboot we add this line to the fstab file:
/media/Ohad_HD /export/Ohad_HD none bind 0 0
Finally this is my /etc/exports file:
# /etc/exports: the access control list for filesystems which may be exported
#               to NFS clients.  See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes       hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4        gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes  gss/krb5i(rw,sync,no_subtree_check)
#
/export         *(rw,fsid=0,insecure,no_subtree_check,async)
/export/Ohad_HD *(rw,nohide,insecure,no_subtree_check,async)
Here is a video showing how to setup the NFS drive in XBMC (This is my other Raspberry Pi running OpenElec)

Transmission Client

To install Transmission:
sudo apt-get install transmission-daemon
To setup Transmission:
sudo service transmission-daemon stop
sudo adduser pi debian-transmissionsudo nano /etc/init.d/transmission-daemon
Change the USER variable to value to pi
sudo chown pi -R /var/lib/transmission-daemon/info/sudo chown pi -R /etc/transmission-daemon/settings.json
sudo service transmission-daemon start
Next we will change the settings.
sudo nano /etc/transmission-daemon/settings.json
"download-dir": "/media/Ohad_HD/<Where ever you want>",
"incomplete-dir-enabled": false,
"rpc-authentication-required": false
"rpc-whitelist-enabled": false,

Then we reload the service to make our changes take affect
sudo service transmission-daemon reload

DLNA Server

To install the DLNA server:
sudo apt-get install minidlna
After minidlna is installed edit the file /etc/minidlna.conf
Specifically the line media_dir= with your previously mounted hard drives.
After editing the file issue the following command to reload the new configuration:
sudo service minidlna force-reload