Poor man’s NAS with Raspberry PI 3

Disclaimer: Raspberry PI is using the Micro SD Card to keep the OS files (I’m using Raspbian Jessie) and unfortunately the card storage solution isn’t 100% reliable because of card data corruption. It’s happening rarely, but is happening. Details how to minimize the risks here. All my important files are stored on an external 3.5 HDD with own power source.

The goal:

  1. Easy to access external 2TB drive from intranet via samba
  2. Easy to access my external 2TB drive from internet via owncloud (alternative: scp)
  3. Run the nginx web server secured, pointing to custom domain (eg. https://www.emilian.co.uk) and reverse proxy to few custom urls (details below)
  4. Run plex server (https://plex.emilian.co.uk)
  5. Run subsonic server (https://music.emilian.co.uk)
  6. Run deluge UI (https://deluge.emilian.co.uk) with custom authentication
  7. Dynamic DNS client (http://freedns.afraid.org)

Initial steps

  1. Download Raspbian Lite and unzip to your home directory
  2. Insert a new Micro SD Card into your computer and write the Raspbian image to your card. I’m using OSX so the quick steps are:

We’re ready to unmount the card from your computer and install it in the raspberry pi. Please make sure you connected the network (I prefer wired but wireless is available too) and your Raspberry Pi is powered by min 2.5A (I’m using a cell phone quick charger and that could explain why I’m having card corruption issues). You can find a genuine power supply here.

We’re ready to ssh on our raspberry pi. I’m using a static IP based on MAC address so it’s easy for me to ssh on that IP. There are plenty of tools to scan your network and find the ip of your raspberry pi (a quick one is to use nmap -v -sn My IP is

I’m connecting to my raspberry pi and first I change the default password and create a new user. Then I run raspi-conf to customize the current installation (eg. timezone, setting hostname, set locale (en_US.UTF-8),  expand the boot partition)

I’m adding my user to sudo group

Fix mirror for apt-get (Optional)

If apt mirror is causing issues when doing the update the quick workaround I’m applying is:

1.Open /etc/hosts file with sudo rights $sudo nano /etc/hosts

2.Paste the following lines at the end of /etc/hosts file.


The next step is to ssh with my new user, update my apt repos and start installing packages.

Updating Firmware (Optional)

Your Raspbian installation also included a pretty recent copy of the Raspberry Pi firmware. However, sometimes there are important updates, so I recommend to use the latest firmare version:

Mount external drive

In order to achieve the goal #1 we’ll need to opt for an external HDD drive (I’m using a 2 TB drive, external power supply) formatted as ext4. You can find your external drive by running below command:

Add below line into /etc/fstab file to mount your external drive automatically:

Mount entry in the “/etc/fstab” file shall make this mount permanent across reboot. Reboot and to check if the external disk is mounted in the /nas location.

Now we have assigned a fixed mount point for the external disk drive, which is available under “/nas” directory in our raspberry pi device.

In case our external connected usb disk takes a long time to initiate this automount might fail and you may need to initiate the system mount at a later time. Adding an entry to /etc/rc.local can do the trick. Add below lines before exit line:

Install and configure samba

We’ll use the folder “/nas” where our 2TB external drive is mounted. We’ll share “/nas” using samba. To do this, we need a samba account in our raspberry Pi. We’ll use the user account “iulian” in this case. Enter the following command and type in a password to set the samba password for “iulian” user:

The password you set for your samba share will not affect your login to Raspberry Pi over ssh.

Let’s backup the original smb.config file.

Add the following section in the smb.conf file:

Restart samba service:

Check if samba service is enabled on startup, so that the service starts on reboot (usually it is)

The “[ + ]” indicates the service is active on startup.

You can mount your /nas folder to your local computer and check if the share works as you expect.

Installing nginx and configure reverse proxy

Nginx is a light and modern web server and fits perfectly our raspberry pi configuration.

You should be able to see nginx is up and running by opening your local browser with (raspberry pi assigned ip).

Install PHP 7 (optional)

Raspbian being based on Debian Jessie ships with PHP 5.6 by default. But we want to run the latest PHP version. To install PHP 7 on Raspbian we must switch to the testing branch of Raspbian, commonly known by the codename stretch.

Add below line at the bottom of the file:

By adding this all installs or updates will default to use the newer versions of files available in the stretch release which is not considered 100% stable. To prevent that, we’ll pin all packages to use the jessie release with a higher priority by default. To do this create a preferences file:

Now we’ll need to configure nginx in order to support our needs.