Building NAS on Raspberry Pi is a very smart way to create DIY NAS for safe and efficient file management. NAS (or Network Attached Storage) Server is a network storage system to serve and share files to other client computers in a local network area. This enables multiple users to access and share the same file storage.

The NAS server can use different file sharing protocols to share the data via the network. The mainly used protocol is SMB (Server Message Block).

Additional protocols are NFS (Network File System), FTP (File Transfer Protocol), SFTP (Secure File Transfer Protocol), SCP (Secure Copy) and more.

The main hardware components of the NAS storage system are the media storage devices, mainly hard drives. If you have more than one storage device mounted on your NAS server, the storage devices can be arranged via a RAID controller (Redundant Array of Independent Disks) into logical and redundant storage containers for redundancy and safety reason. There are various RAID levels to protect the data in case of a disk failure. The most common are RAID-0, RAID-1 and RAID-5.

Advantages of building NAS on Raspberry Pi

Raspberry Pi is a mini computer build on a single PCB board, slightly larger than a credit card. It has a wired local area network (LAN) and 4 USB-Ports for different external devices like keyboard and mouse or external storage devices.

The optimized operating system for the Raspberry Pi 2 and the Raspberry PI 3 is Raspbian, a free and open source software based on Debian. Also, there are a couple of alternative operating systems available for the Raspberry Pi. In this article, we will use the newest “Raspbian Stretch” operation system, released at 2017-08-16 with the Kernel version 4.9.

Well, concerning the advantages of making up Raspberry Pi NAS hosting device, RPI is a mini-computer with the full performance of a Linux-based operating system and contains almost all functions of a large server system.

On the other hand, the Raspi saves a lot of money because it’s really cheap and consumes a very small amount of energy. Due to its small size, the RPi can be placed almost everywhere as it occupies a very small space. RPi board can be used for an almost unlimited number of projects, like running Plex media server, playing retro games with a game emulator built on the Pi and much more.

All of that features make the Raspberry Pi an ideal candidate for your own small NAS storage system.

Setup a NAS Server on Raspberry Pi

In this article, we will set up a simple NAS server from scratch, based on the SMB protocol. The goal is to save files on the NAS server and share them between different computer clients. For this project, we’ll need a Raspberry Pi 2 or Pi3 with a running Rasbian and connected to some Network. Make sure you have access to the terminal or you’re logged in to the Raspberry Pi via SSH connection.

For the file storage, we need an external USB Hard-drive with a storage capacity of your choice.

Prepare your RPi

Let’s assume that the Raspbian operating system is already installed and running on RPi. Connect your device to the Network via a wired connection or via WLAN and open a terminal.

Check if the Kernel Raspbian version is right for setting up NAS on RPi

On the first step, we need to make sure that all packages are of the latest version.

$ sudo apt-get update
$ sudo apt-get upgrade

If the Raspbian is up to date, we are ready to setup our NAS server.

Install and Setup Samba Server

1. To share files from our NAS server we need to install the Samba package. This includes all required apps and configuration files to setup the SMB protocol.

$ sudo apt-get install samba samba-common-bin

2. After the installation, we need to configure the smb services. For that, we need to configure a sharing of an internal directory. For this case, we will create the directory and name it “INTERNAL” in the home path of our Pi user:

Configure Internal directory on Raspbian for NAS

3. Now open the /etc/samba/smb.conf file in an editor of your choice and enter the configuration options for the INTERNAL sharing at the end of the file like shown below.

[INTERNAL]
comment = internal Files
browseable = yes
path = /home/pi/INTERNAL
writeable = Yes
create mask = 0777
directory mask = 0777
browseable = Yes
public = yes

Bear it in your mind that the file must be modified under the root rights. Otherwise, the changes won’t be implemented. There is a very quick and simple way to open the file under the root:

$ sudo leafpad /etc/samba/smb.conf

You’ll see the editor window to input the data we’ve mentioned above.

4. After that, you need to get an access to the sharing, we’ve just created. For that, the user Pi should be allowed to be the Samba user.

$ sudo smbpasswd -a pi

Then, enter a password twice and restart the Samba server.

$ sudo /etc/init.d/samba restart

5. Now we are moving over to a Windows 7 client to check if the Samba server is configured correctly and we have access to our sharing directory.

On Windows open the Explorer and choose “Map network drive” from the Menu:

Check if the Samba server works properly for Raspberry Pi NAS project

In the dialog window, enter the IP-address of your Raspberry Pi and the configured share name “INTERNAL” as shown below.

Check the Samba within NAS on Raspberry Pi by entering the RPi IP address

Note: Be sure you replace the 192.168.17.73 with your own IP address and enable both ticks. Now enter the username “pi” and the password we’ve set up with the smbpasswd command earlier.

Enter the Samba username for Raspberry Pi NAS server setup

After that, we are connected with the Raspberry Pi and we can save and share our files.

Connect to Raspberry Pi for creating and sharing files with NAS on Raspbian

To make sure everything is OK, we can create a directory “Directory” and inside this directory, we can create a “Dokument.rtf” file. If all the operations are done and you can find this file, so our system is working the right way!

Create a file to test the Samba server for Raspberry Pi NAS project

Back to the Raspberry Pi sharing directory, we must also see the newly created files, like that:

Check the created test file in INTERNAL directory on Raspbian within the RPi NAS server project

Prepare an external drive

If we want to provide a larger amount of file space we connect an external USB drive to Raspberry Pi. In this tutorial, we are going to use a 1TB external USB HDD with an NTFS file system to expand our storage pool.

6. So, connect the external USB hard drive to the device. With the command lsblk, we can check all the connected devices.

Check the devices connected to NAS on Raspberry

As you see above, the mmcblk0 device is the SD card which contains two partitions for the Raspbian operating system. The sda device is the external USB disk already connected to the RasPi. As we can see, the sda device contains one partition sda1 with a size of 931.5 Gb. The sda1 partition contains an NTFS file system.

7. To mount this file system we need to install the “ntfs-3g” package.

$ sudo apt-get install ntfs-3g

8. The next step is to create an “EXTERNAL” folder:

$ sudo mkdir /EXTERNAL

So, I should mention one important thing on this step. It looks like the latest models of Raspberry Pi 2 and Raspberry Pi 3 can automatically mount the devices. According to my personal experience, once an HDD is connected, the Raspbian creates a folder with a name “New Folder” or alike and mounts your device to it. If you face the same, simply fulfill the following command to unmount the device from the needless folder:

$ sudo umount /media/pi/New\ Folder/

If it is done, we can mount the external drive to the new directory.

Mount the external drive to your NAS on Raspberry Pi

9. To automatically mount an HDD to the system, we have to modify the /etc/fstab file. For that, I advise to use the root command mentioned before to open up the file:

$ sudo leafpad /etc/fstab

In the editor, input the data outlined in the picture below:

Modify the fstab for your Raspberry Pi NAS system

10. Now we have to reboot and check if the external disk was mounted automatically.

Check if the RPi NAS external disk has been mounted

As you can see above, the external hard drive partition /dev/sda1 is already mounted to the EXTERNAL mount point. For testing purposes, we can create a directory and a file inside the EXTERNAL directory.

Testing the Raspbian NAS

Create an external share

Now we are ready to share the external disk to the network.

1. For that, firstly, we have to add the following configuration part to the end of /etc/samba/smb.conf file. Don’t forget to use the special command for opening the file:

$ sudo leafpad /etc/samba/smb.conf

As soon as the file opens up, copy the data set below:

[EXTERNAL]
comment = external Files
browseable = yes
path = /EXTERNAL
writeable = Yes
create mask = 0777
directory mask = 0777
browseable = Yes
public = yes

2. Then, we can restart the Samba server.

$ sudo /etc/init.d/samba restart

3. On the next step, we’ll move over to a Windows 7 client to check if the external share is also available in the Network. As described earlier, we map the external sharing in the same way, with the “EXTERNAL” instead of “INTERNAL” sharing name.

Checking the external share of the DIY Raspberry Pi NAS server

Now we can see the external sharing directory with the test file “external.file” inside.

Check your own NAS on Raspberry Pi by finding the external file in the right directory

If the result is as described and shown on the last picture, so you’re all set with your own and stable universal Raspberry Pi NAS system, ready to use for any purpose of your choice!

Other Alternatives for NAS Server on Raspberry

As an alternative to your own NAS, you can use ready built NAS storage server applications like Openmediavault, Freenas, Nas4free, and others. These application packages are easy to install and comes with a Web-Interface to configure. They are made for managing the storage and file sharing to other users within the Network.

Openmediavault as a NAS alternative on Raspberry Pi

As the first alternative, let’s look through the Openmediavault service. This is a web based NAS service for Debian Linux (Jessie) devices, including the Raspberry Pi ones. For the RPi option, there is a Raspberry Pi 3 image (download from here). As soon as you have it on your device, the installation process is pretty simple.

  1. Download the Raspberry Pi 3 NAS image (using the link above).
  2. Create an SD card for Raspbian with the proper OMV image on it. For that, we can use the Win32DiskImager app just the same way, as we have used it for setting up Raspberry Pi Backup.
  3. Insert the SD card into your Raspbian device and watch the configuration to be completed automatically.
  4. To finish the setup, input your Raspberry Pi IP address.
  5. After that, connect to the IP address you’ve provided in the previous step via Chromium browser (or whatever you use on your Pi).
  6. Set up the username and the password (the username is “admin” by default).
  7. The interface is quite user-friendly, so you’ll be able to add your hard drive by purely following the guidelines.
  8. Don’t forget to enable the service by entering the SMB/CIFS directory and pushing the switch-on button.
  9. You can also enable the guest access in the “Shares” directory (it’s optional).
  10. Then… You’re done!

Nas4Free as an alternative RPi based NAS

Another service to your consideration is Nas4Free. Generally, this app is very close to the OMV we’ve just described. The only thing is that the installation process a little bit simpler and faster, to my opinion. Nas4Free has almost the same features and capabilities. To set up Nas4Free on your Raspbian, follow these few simple steps:

  1. Download the latest image. I’d advise you to choose “NAS4Free-rpi2-SD-10.3.0.3.4529.img” (download the image).
  2. Create an SD card with the image on it. Use Win32DiskImager and the same example guide we’ve mentioned earlier.
  3. Insert the SD card into your Raspbian device and let the installation run automatically.
  4. To finish the setup, input your Raspberry Pi IP address.
  5. You are all set!

While using Nas4Free with on RPi remember 2 simple notes. Firstly, the image of 11.x will is released only for RPi2 and 3. And secondly, it is highly recommended to overclock your Raspberry Pi from 600 MHz to 900 MHz. For that, you need to enable the Power Daemon in the System|Advanced settings of your Raspberry Pi.

FreeNAS as an alternative for NAS on Raspberry

For the last thing, I’d like to say a few words about FreeNAS, as another alternative for RPi NAS. It is an online Open Source and BSD Licensed service for sharing and storing files using any hardware platform, including ARM-based devices.

Telling the truth, Freenas is considered to be not the best variant for building up NAS on Raspberry. This is not only the personal opinion, but the community thinks the same (check the StackExchange thread here). In a nutshell, FreeNAS is aimed to be used within really big (even huge) projects and requires a powerful computer. The 8GB of RAM is required for the FreeNAS 11 to be run properly, which, obviously, can’t be met by even the latest 2017 model of Raspberry Pi (you can make sure on their download page).

Still, there is a common way to install FreeNAS on Raspberry Pi using the combination of ExaGear and Wine, but even the 3D hardware graphics acceleration, provided by ExaGear Desktop, won’t get you acceptable performance. Anyway, you are free to try that scheme. 

Final notes

In conclusion, we have gained a lot of information on different ways of making up your own NAS on the Raspberry Pi devices (or implement the same to any AMR-based hardware). Obviously, there are a lot of pros as well as cons at the same time of using NAS on Raspberry Pi.

The great advantages of Raspberry Pi are its very small size, cheap price(less than 40 USD) and very little energy consumption device. Disadvantages include the fact, that hard drives can only be connected via USB interface and have a possibility of a performance loss compared to hard drives running over SATA. Also, the setting up RAID over USB HDDs is not recommended as this type of devices are very error sensitive.

You can further expand the storage capabilities of the RPi by adding cloud services like Google Drive or Dropbox on Raspbian with the help of ExaGear Desktop. Using Dropbox on Raspbian or any other ARM (set up on with ExaGear) for the purpose of building up the NAS system have a number of advantages:

  1. You can synchronize the data between different devices, using multiple ARM boards, or even use them cross platform way (x86 + ARM).
  2. Your data and files are accessible from anywhere in the world, as this is a cloud service.
  3. With Dropbox, it’s possible to set up backup for your Raspberry Pi NAS system
  4. You can get the history of changes because Dropbox backs up files several times a day keeping all the versions of files saved.
  5. Dropbox itself provides a great customer technical support.

Connect your RPi to Dropbox to make your own NAS on Raspberry Pi better

Moreover, accompanied by ExaGear Desktop software, you have the possibility to save data from anywhere to any type of an ARM device (including, but not limited to Raspberry Pi, Odroid, Banana Pi, Beagleboard, Cubox, Jetson, Cubieboard and many others).