How to turn your Raspberry Pi into NAS (Network Attached Storage) device

In my previous article, I added an USB HDD (WD PiDrive) to Raspberry Pi and showed you how to make the file system more reliable by setting up software RAID. Now, it is time to turn Raspberry Pi into a NAS (Network Attached Storage) device.

There are many benefits to set up a NAS using Raspberry Pi. Low power and quite operation are the two main reasons that are most important to me. Of course, high performance is needed, there are better solutions out there.

Install Samba

Samba was originally designed for Windows systems to share file and print services. It was later on adopted by many Unix systems and is available under GNU GPL license. To install Samba, run the followings:

sudo apt-get install samba samba-common-bin

Create a directory in your file system for sharing. e.g. /home/disks/raid/netshare

cd /home/disks/raid
mkdir netshare

Next step is to edit smb.conf

sudo emacs /etc/samba/smb.conf

Update the workgroup in smb.conf. For example, if your Windows Workgroup is “MYGROUP”, update workgroup as follows:

workgroup = MYGROUP

At the end of smb.conf add the followings:

[pishare]
comment = Raspberry Pi RAID
path = /home/disks/raid/netshare
browseable = yes
writeable = yes
only guest = no
create mask = 0770
directory mask = 0770
public = no
write list = thomas

(where thomas is the user name)

Also make sure that you apply proper permissions and group in the

“/home/disks/raid/netshare” directory
e.g.

chown thomas /home/disks/raid/netshare
chgrp users /home/disks/raid/netshare
chmod 770 /home/disks/raid/netshare

After saving the edits, restart Samba server as follows

sudo service smbd restart

What it does is that it shares your local folder /home/disks/raid/netshare on your local network as ‘pishare’. By  setting ‘only guest’ and ‘public’ attributes to no, it requires user to login in order to access the pishare network folder

Adding Samba user

Run the following command to add a Samba user on your Raspberry Pi . In the following example, ‘thomas’ is my Unix user name. The following command sets the password for ‘thomas’ to access Samba.

sudo smbpasswd -a thomas
[New SMB password:]  <-- enter a password (could be different from your unix password)

Map the Samba Folder on Windows

On Windows, you may map the Samba folder to a drive. Here is how:

  • Open file explorer.
  • Right click on ‘This PC’

Windows File Explorer

  • Select ‘Map Network Drive’ and it opens the following dialog box. Click on ‘Browse’ button to select the Samba folder made available from your raspberry Pi. In my case, it is \\THOMAS-DESKTOP\pishare
Mapping Raspberry Pi Samba Folder to a Drive on Windows
Mapping Raspberry Pi Samba Folder to a Drive on Windows

 

Done

You will be prompted to enter username ‘thomas’ and your Samba password. Once they are entered, your network drive (Z:) is available.

 

Raspberry Pi as NAS device
Raspberry Pi as NAS device
  • Dick True

    Having difficulty with setting up my NAS device. How to install an USB hard disk (WD PiDrive) to Raspberry Pi went OK. I am now following the procedures of “How to turn your Rpi into NAS device”. I can map drive Z to the pishare folder OK but the program never asks for a username and password. If I go to a command prompt I can see drive Z with a folder called “lost+found”. If I try to copy a file from my PC over to drive Z it says I do not have the authority. So I need a little help in making this thing work. Unfortunately I am not a Linux person but I can follow instructions!

    • Can you try:

      [pishare]
      comment = Raspberry Pi RAID
      path = /home/disks/raid/netshare
      browseable = yes
      writeable = yes
      only guest = no
      create mask = 0770
      directory mask = 0770
      public = no
      write list = thomas

      (where thomas is the user name)

      Also make sure that you apply proper permissions and group in the

      “/home/disks/raid/netshare” directory
      e.g.

      chown thomas /home/disks/raid/netshare
      chgrp users /home/disks/raid/netshare
      chmod 770 /home/disks/raid/netshare

      • Dick True

        Thomas,
        Yes, that worked! I was just not smart enough to do the chown, chgrp and chmod commands. I will do some real testing on Sunday but tonight it is kind of late….

      • Great! I should have included them in the article. I will update it soon. Thanks.

      • Dick True

        The application is running fine for all the windows devices on my internal network. Is it possible for a device running IOS or Android (iPad etc) to access the data out on the RPI’s hard drive? If so, how?

      • I don’t have iOS devices. On Android, I use “ES File Explorer” . I added the RPi drive through LAN -> New. Enter the IP address , share folder name, username and password.

        E.g. “192.168.0.130/pishare” in the server field, where 192.168.0.130 is the IP address of the RPi.

      • Dick True

        Yes, thank you, that worked just fine on my Nexus 7 and then I downloaded “FileExplorer” from apple for my iPad and it works just fine too. You are a great help!