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.
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:
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:
In the dialog window, enter the IP-address of your Raspberry Pi and the configured share name “INTERNAL” as shown below.
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.
After that, we are connected with the Raspberry Pi and we can save and share our files.
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!
Back to the Raspberry Pi sharing directory, we must also see the newly created files, like that:
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.
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.
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:
10. Now we have to reboot and check if the external disk was mounted automatically.
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.
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.
Now we can see the external sharing directory with the test file “external.file” inside.
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.
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.
- Download the Raspberry Pi 3 NAS image (using the link above).
- 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.
- Insert the SD card into your Raspbian device and watch the configuration to be completed automatically.
- To finish the setup, input your Raspberry Pi IP address.
- After that, connect to the IP address you’ve provided in the previous step via Chromium browser (or whatever you use on your Pi).
- Set up the username and the password (the username is “admin” by default).
- The interface is quite user-friendly, so you’ll be able to add your hard drive by purely following the guidelines.
- Don’t forget to enable the service by entering the SMB/CIFS directory and pushing the switch-on button.
- You can also enable the guest access in the “Shares” directory (it’s optional).
- Then… You’re done!
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:
- Download the latest image. I’d advise you to choose “NAS4Free-rpi2-SD-10.3.0.3.4529.img” (download the image).
- Create an SD card with the image on it. Use Win32DiskImager and the same example guide we’ve mentioned earlier.
- Insert the SD card into your Raspbian device and let the installation run automatically.
- To finish the setup, input your Raspberry Pi IP address.
- 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.
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:
- You can synchronize the data between different devices, using multiple ARM boards, or even use them cross platform way (x86 + ARM).
- Your data and files are accessible from anywhere in the world, as this is a cloud service.
- With Dropbox, it’s possible to set up backup for your Raspberry Pi NAS system
- You can get the history of changes because Dropbox backs up files several times a day keeping all the versions of files saved.
- Dropbox itself provides a great customer technical support.
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).