A NAS (Network Attached Storage) is a device that serves files on your network. Think of it like a Dropbox, except that you dictate how much storage to add. Not only can you share files around devices, you can (with the proper software) stream content.

However, a NAS (Network Attached Storage) device are very expensive, and that is not even considering the hard drives. Altogether, a two drive NAS can set you back $400 ~ $600. However, having a local area storage is quite convenient, especially  to move files around devices. But given that Dropbox limited the number of devices you can connect in a free account to 3, this was the final push I needed to set up an alternative.

I wanted to set up an NAS with a Raspberry Pi, but I realized that a lot of the instructions out there were outdated or simply wrong. There is one common tutorial that refers to an auto-usb.ext file that doesn't even exist for autofs. This is the procedure that I followed to set up a Raspberry powered NAS in 2019.

Method

Update software

sudo apt update && sudo apt dist-upgrade -y

Set up VNC

sudo apt install realvnc-vnc-server realvnc-vnc-viewer

Enable VNC in Preferences > Raspberry Pi Configuration > Interfaces > VNC > Enable. Get the IP address of the raspberry pi by running:

hostname -I

Now with VNC you can continue on your main device instead of being tethered to a screen.

Install software

sudo apt install ntfs-3g samba samba-common-bin
mkdir /media/1
cp /etc/samba/smb.conf /etc/samba.smb.conf.bak
sudo nano /etc/samba/smb.conf

This installs the software necessary to read a NTFS formatted storage device and the software necessary to set up the NAS. We make a directory at /media/1 to mount our storage device, which means that it is access at the location /media/1. Next, we make a backup and edit the samba configuration file:

In file, add under [global]:

security = user
hosts allow = 192.168.1.0/24

This will apply some security to your samba installation by only allowing hosts from the local network (192.168.1.0-254) and requesting that they log in with a user. If you don't know your local network, run ifconfig. At the end of the file add in:

[public] 
  comment = public storage 
  path = /media/1
  valid users = @users 
  force group = users 
  create mask = 0660 
  directory mask = 0771 
  read only = no

Determine where your external storage is mounted by running:

sudo blkid

Now you want to test by mounting it in the /media/1 folder that we created earlier.

sudo umount /dev/sda1
sudo mount -t auto /dev/sda1 /media/1

This mounts the drive in the folder. Browse to the folder and make sure that you can access the contents. Now try to access the storage using another device connected on the network by browsing to \\[local-pi-ip-address]\public in Windows Explorer. You should be able to see the storage at this point. Now to set up the mounting process automatically:

sudo nano /etc/fstab

Add this to the last line of the file:

/dev/sda1 /media/1 auto noatime,nofail 0 0

This will automatically mount any drive on sda1 to /media/1 on boot.

Congratulations! The Raspberry Pi NAS is now set up.

Some lessons

  1. Get a good SD card. I had a cheap one from Microcenter and it stopped booting about 6 hours into a debugging session. I had to reflash Raspbian on it.
  2. If it doesn't boot, it might be due to a power issue. If it seems to hang after awhile, it could also be a power issue.

Future work

  1. Figure out a way to do power saving features on the pi.
  2. Build a case for the pi.

References

  1. https://howtoraspberrypi.com/create-a-nas-with-your-raspberry-pi-and-samba/
  2. https://pimylifeup.com/raspberry-pi-samba/