NAS on Raspberry Pi

This article is about setting up network storage on Raspbian (follow the link to view the article on my corporate blog)

1. What is a NAS Server

A (Network Attached Storage) NAS Server is a network storage system to serve and share files to other client computers in a local area network. 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 a 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 for the NAS storage system are the media storage devices, mainly hard disks. If you have more then one storage device mounted on your NAS server, the storage devices can arranged via a RAID controller (Redundant Array of Independent Disks) into logical and redundant storage containers for redundancy and security 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.

2. What is a 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 four 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 documentation, we use the newest “Raspbian Stretch” operation system, released at 2017-08-16 with the kernel version 4.9.

3. Why NAS Server on Raspberry Pi

Raspberry Pi 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 RaspPI saves a lot of money because it consumes a very small amount of energy. Due to its small size, the RaspPI can be placed on nearly any place.

This all makes the Raspberry Pi an ideal candidate for your own small NAS storage system.

4. Alternatives NAS Server on Raspberry PI

As an alternative to your own NAS you can use ready build NAS storage server applications like Openmediavault, Freenas, nas4free and more to install on your Raspberry PI. These application packages are easy to install and comes with a Web-Interface to configure and manage the storage and file sharing to other users in the network.

5. Setup a NAS Server on Raspberry PI

In this document we want setup 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.

5.1 Requirements

For this project we need a Raspberry PI2 or Pi3 with a running Rasbian and ready connected to your network. Make sure you have access to the terminal or logged in to the Raspberry PI via ssh a connection.

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

5.2 Prepare your RaspPI

We assume that the operating system Rasbian is already installed and running on the Raspberry PI.

Connect your Raspberry PI to the Network via a wired connection or via WLAN and open a terminal. In this documentation we use the last raspbian version running the kernel 4.9.

The first step we need to do is to make sure all packages are the latest  version.

sudo apt-get update sudo apt-get upgrade

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

5.3 Install and Setup Samba Server

To share files from our NAS server we need to install the samba package. This includes all required programs and configurations files to setup the smb protocol.

sudo apt-get install samba samba-common-bin

After the installation we need to configure the smb services.

5.3.1 Create an internal share

In the first step, we configure a sharing of an internal directory. For this case we create the directory INTERNAL in the home path of our pi user. mkdir /home/pi/INTERNAL

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.


   comment = internal Files

   browseable = yes

   path = /home/pi/INTERNAL

   writeable = Yes

   create mask = 0777

   directory mask = 0777

   browseable = Yes

   public = yes

To access to the sharing we need to allow the user pi to be a samba user.

sudo smbpasswd -a pi

You have to enter a password twice.

Restart the samba server.

sudo /etc/init.d/samba restart

5.3.2 Connect the internal share

Now we move 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 chose “Map network drive” from the Menu.

In the dialog enter the ip address of the raspberry pi and the configured share name “INTERNAL” as shown below.

Note: Be sure you replace the with your own ip address.

Now enter the username “pi” and the password we setup with the smbpasswd command.

Now we are connected with the Raspberry PI and we can save and share our files.

For testing, we create a directory “Directory” and inside this directory we create a “Document.rtf” file.

We wend back to the Raspberry PI and inside our sharing directory we will see the new created files.

5.3.3 Prepare an external disk

If we want to provide a larger amount of file space we connect an external USB drive to the Raspberry PI.

In this document we use a 1TB external USB disk with a ntfs file system to expand our storage pool.

With the command lsblk we can check all 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 PasPI. As we can see,

the sda device contains one partition sda1 with a size of 931.5 Gb.

The sda1 partition contains a ntfs file system. To mount this file system we need to install the ntfs-3g package.

sudo apt-get install ntfs-3g If it is done, we can mount the external disk to the new directory.

To automatically mount a disk to the system, we have to modify the /etc/fstab file with the last line as you can see below.

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

As you can see above, the external disk partition /dev/sda1 is already mounted to the /EXTERNAL mount point.

For testing purposes, we create a directory and a file inside the / EXTERNAL directory.

5.3.4 Create an external share

Now we are ready to share the external disk to the network. For that, we have to add the following configuration part to the end of /etc/samba/smb.conf file.


   comment =  external Files

   browseable = yes

   path = /EXTERNAL

   writeable = Yes

   create mask = 0777

   directory mask = 0777

   browseable = Yes

   public = yes

Restart the samba server. sudo /etc/init.d/samba restart

5.3.5 Connect the external share

Now we move over to a Windows 7 client to check if the external share is also available in the network.

As described in Section 5.3.2 we map the external sharing on 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.

5. Final notice

You can further expand the storage capabilities of the RPi by adding cloud services like Google Drive or Dorpbox using ExaGear. This gives you the possibility to save data from anywhere to everyone.

Pros and Cons of the NAS on Raspberry PI:

The great advantages of Raspberry PI are, it is very small, costs less than 40 USD and consumes very little energy. Disadvantages are, hard drives can only connected via USB interface and give you a performance loss compared to hard disks running over SATA. Also the setting up of RAID is not recommended over USB hard disks as this is very error sensitive.

Also, note that with ExaGear Desktop you can run almost any x86 app on any ARM-based device including, but not limited to Raspberry Pi, Odroid, Banana Pi, Beagleboard, Cubox, Jetson, Cubieboard and many others.

Source: NAS on Raspberry Pi

About The Author

Muhammad Bilal

I am highly skilled and motivated individual with a Master's degree in Computer Science. I have extensive experience in technical writing and a deep understanding of SEO practices.

Scroll to Top