Pinterest Stumbleupon Whatsapp
Ads by Google

raspberry pi nas controllerDo you have a couple of external hard drives lying around and a Raspberry Pi? Make a cheap, low powered networked attached storage device out of them. While the end result certainly won’t be as impressive as a $500 NAS device like the Synology DiskStation Synology DiskStation DS413j NAS Review and Giveaway Synology DiskStation DS413j NAS Review and Giveaway To call the Synology DiskStation DS413j a Network Attached Storage (NAS) device is a degrading understatement - but yes, it serves files over the network. To say it has RAID functionality is also somewhat unfair... Read More , it will give you a low-powered bit of network storage – particularly useful if you’re getting weary of having all your data rifled through by the prying eyes of the NSA – you can hide this in the attic.

You’ll need a Raspberry Pi The Top 5 Amazing Uses For Your Raspberry Pi Computer The Top 5 Amazing Uses For Your Raspberry Pi Computer I’ve recently received my Raspberry Pi after a long wait – and I’ve got quite a few plans for it. The problem is, I’m not totally sure which project I want to attempt first. While... Read More , of course, and one or two spare drives. Smaller 2.5″ drives can be powered directly over USB, but we’re going to need a powered hub as the power provided over the RPi’s USB ports is just not enough for them. Alternatively, you can use a USB thumbdrive, or even an SD card. In fact, I’ve used a mix of a USB hard drive and a thumbdrive today, but the procedure is identical.

raspberry pi nas controller

With just one drive, you can still make a shared network storage area, but with two you’ll be able to setup data redundancy in case one fails.

Prepare Your Drives

Start by formatting your drives as NTFS from a desktop. This is for convenience, so that if anything goes wrong we’ll be able to disconnect them from the NAS and still read the data from any PC.

We could format them from the Raspberry Pi, but it will take a few hours and is far quicker to perform from a desktop. Do that now.

Ads by Google

To configure SSH and enable the root user, first create a password for root user:

sudo -i
passwd root

(type your password)

Then run the raspi-config script from the command line, either using sudo or having logged out and in again as root. From advanced options menu, enable SSH.

raspberry pi nas box

After restarting, you should be able to login from another networked machine using (use Putty if you’re on Windows)

SSH root@[IP address]

Once logged in, figure out which devices are your additional drives. I’m assuming you’ll be using two for data redundancy. Type

fdisk -l

to list the attached storage devices. You should see something like this.

raspberry pi nas box

the /dev/mmc partitions are you Pi operating system, mmc referring to the SD card. Confusingly, the /dev/sda1 and /dev/sdb1 are actually nothing to do with the SD card, and those are in fact your attached USB drives. (Originally, “SCSI device”, but now means any attached SATA or storage device)

Install ntfs-3g for linux so we can access the NTFS formatted Windows drives.

apt-get install ntfs-3g

Next, create directories to use as mount points, then mount the drives. I’m keeping it simple here and referring to them as 1 and 2.

mkdir /media/1
mkdir /media/2
mount -t auto /dev/sda1 /media/1
mount -t auto /dev/sdb1 /media/2
mkdir /media/1/shares
mkdir /media/2/shares


Next, we’ll set up Samba. Samba is the network sharing protocol used by Windows (and the newest OSX Mavericks, in fact).

apt-get install samba
apt-get install samba-common-bin
cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
nano /etc/samba/smb.conf

If you’re not familiar with these kind of config files, a # at the start of the line means it is commented out, and therefore not currently set or configured. To enable something, you can either add a new line, or un-comment an existing line to make it active.

We’ll start by enabling user security; press CTRL-W and type “security” to find the relevant section. Remove the # symbol from the line that says

security = user

Lastly, scroll down to the bottom (or hold CTRL V until you reach there) and add as many network shares as you like. Use the following format:

comment = Test share
path = /media/1/shares
valid users = @users
force group = users
create mask = 0660
directory mask = 0771 
read only = no

Only refer to the first mounted drive though – we’ll be syncing this later with the 2nd share to provide redundancy.

Once you’re done, hit CTRL X and then y to save.

create a raspberry pi nas box

Then restart Samba with the following command.

service samba restart

Now, add a new user to your Pi, assuming you don’t want the same login (substitute “jamie” for your own user)

useradd jamie -m -G users

After typing in the following command, you’ll be prompted to enter a password for your user, and confirm it.

passwd jamie

Then we can go ahead and add this system user to Samba. You’ll need to confirm your password again, twice.

smbpasswd -a jamie

Go ahead and test the network share now – it should be visible from your other machines (Windows or Mac), and you should be able to write files to it.

raspberry pi nas controller

The only problem at this point is that the drives will be unmounted when you restart the Pi. To solve this, install autofs.

apt-get install autofs
nano /etc/auto.master

Add the following line underneath +auto.master

/media/ /etc/auto.ext-usb --timeout=10,defaults,user,exec,uid=1000

Now you should be able to restart safely without breaking everything

Data Redundancy

Assuming you installed two drives, we can now setup an automatic script for syncing data from the 1st drive to the 2nd, thereby offering us a backup in case one fails. We’ll use the rsync utility for this.

apt-get install rsync
crontab -e

The crontab in linux is a way of automating tasks; I talked briefly about before when showing you how to automate site backups Automate Your Wordpress Backup With Simple Shell Scripting & CRON Automate Your Wordpress Backup With Simple Shell Scripting & CRON Last time we talked about Wordpress backups, I showed you how incredibly easy it was to backup your entire database and files though SSH with only a few commands. This time, I'm going to show... Read More . Add following line:

30 5 * * * rsync -av --delete /media/1/shares /media/2/shares/

The numbering scheme is used like this:

minute | hour | day-of-the-month | month | day-of-the-week

So in our newly added line, the rsync command wil be run at 5:30 am , every day (the * wildcard meaning “every”, so “every day of every month”)

If you want to go ahead and run the backup immediately, just paste in the rsync command like so

rsync -av --delete /media/1/shares /media/2/shares/

Depending on what you put in the shared folder, it may take a few seconds or longer to give you a report. The great thing about rsync is that it knows which files are updated, added or should be deleted. Go ahead and try the same command again. It should finish instantly, because it knows nothing has changed.

That’s it, finished – you now have your own quick and dirty NAS. Yes, it might not have all the flashy features of a proper NAS, but it gets the job done nicely and for much less power consumption.

Are you having problems? Let us know in the comments and I’ll see what I can do, but please ensure you’re running the latest Raspian image.

  1. Caleb V
    October 20, 2016 at 11:50 pm

    I'm trying this right now, but I'm running into a problem: when I try to restart Samba, it says "Failed to restart samba.service: Unit samba.service is masked.". I tried to unmask it using "sudo systemctl unmask samba.service", but in the end it doesn't do anything. Any ideas?


    Caleb V

  2. SW
    October 14, 2016 at 4:20 am

    Try as I might, I can't get autofs to work! The drive just refuses to mount on boot! When I check /etc/init.d/autofs status it says "failed to read map for /media/" with a few other errors. Any suggestions??

  3. Mark TJ
    January 2, 2016 at 4:03 pm

    All up and running but would be even better if I could mirror the redundancy drive to something like "one drive". Got any ideas on how to do that?

  4. Peter Corbett
    July 12, 2015 at 6:04 pm

    Hi I have just done this my windows 7 laptop picks it up but when I try to access it,it tells me me I don't have permission any idea's please

  5. Owen Page
    June 22, 2015 at 5:34 pm

    Could I use this for music streaming to a HiFi like Sonos?

  6. Semih Tekten
    March 16, 2015 at 3:37 am

    This project is on Pi Hunt's top list!

  7. harguer
    March 3, 2015 at 11:48 pm

    I thinks it's better to use lvm/raid1 instead of using rsync...

  8. Alexis Dominguez
    March 2, 2015 at 1:12 am

    Thanks for the DIY.
    I got it setup but when i acces the drive from my windows machine it says that is only a 7.16GB but the HD is a 1TB?
    Any way to fix that?

    pi@ADraspberry ~ $ sudo fdisk -l

    Disk /dev/mmcblk0: 7948 MB, 7948206080 bytes
    4 heads, 16 sectors/track, 242560 cylinders, total 15523840 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x0009bf4f

    Device Boot Start End Blocks Id System
    /dev/mmcblk0p1 8192 122879 57344 c W95 FAT32 (LBA)
    /dev/mmcblk0p2 122880 15523839 7700480 83 Linux

    Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
    255 heads, 63 sectors/track, 121601 cylinders, total 1953525168 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0xe8900690

    Device Boot Start End Blocks Id System
    /dev/sda1 63 1953520064 976760001 7 HPFS/NTFS/exFAT

    • Owen Page
      June 22, 2015 at 6:03 pm

      How large is your Pi's SD card? You might be seeing that and not the HDD.

      If not check the drives partitioning, you might have several partitions. If this is the case delete the extra partitions and expand the 7GB one to fill the entire drive.

  9. Justin Rowe
    February 21, 2015 at 5:09 pm

    HI there I've tried this Tut 5 times and copied it word for word but I can't access the folder?
    On my mac I get operation cannot be completed because the original item for 'test' can't be found and on my PC the share doesn't even show up?

    Any help would be great, thank you

  10. Joe
    February 15, 2015 at 12:28 am

    Nice article! After reading this, I ordered my Raspberry Pi and set this up for test using USB sticks. Works great, so I'm ordering a couple of 2 TB drives to complete the system. Thanks for the great project. Raspberry Pi rocks!

  11. GB
    November 18, 2013 at 7:36 am

    Hi. Thanks for your tutorial.
    I have three usb hard disks connected via an hub to raspberry ;I followed your instructions
    mkdir /media/1
    mkdir /media/2
    mount -t auto /dev/sda1 /media/1
    mount -t auto /dev/sdb1 /media/2
    mount -t auto /dev/sdc1 /media/3

    but sometimes with fdisk -l command I find sdb1 is associated with disk that I defined sdc1 and viceversa and also in startx I find disk inverted. This is dangerous because I make rsync between disk1 and disk2, but if sdb1 and sdc1 are inverted I loss my data.

    Can you help me?


    • James B
      November 18, 2013 at 9:14 am

      I'm afraid thats a bit beyond my linux knowledge. I'd suggest asking about how to do that on our Answers site:

  12. Michael
    November 4, 2013 at 6:52 pm

    Hi James!

    Great tutorial, I can get the most to work; however I got major issues with autofs part. The line that should be added seem to point to a file (/etc/auto.ext-usb)? This file is missing in my system.

    /media/ /etc/auto.ext-usb --timeout=10,defaults,user,exec,uid=1000

    I looked into some other guides as well and to evaluate the auto.master I stop the autofs service and then I use automount -f -v to get som error messages and those complain about a directory (that is added as default in the auto.master). see messages below:

    Starting automounter version 5.0.7, master map /etc/auto.master
    using kernel protocol version 5.02
    lookup(dir): dir map /etc/auto.master.d missing or not readable
    lookup(file): failed to read included master map dir:/etc/auto.master.d
    lookup(file): failed to read included master map auto.master
    file map /etc/auto.ext-usb not found
    mount_autofs_indirect: failed to read map for /media/
    handle_mounts: mount of /media/ failed!
    master_do_mount: failed to startup mount
    no mounts in table

    My auto.master looks like this (see below)

    # Sample auto.master file
    # This is an automounter map and it has the following format
    # key [ -mount-options-separated-by-comma ] location
    # For details of the format look at autofs(5).
    #/misc /etc/auto.misc
    # NOTE: mounts done from a hosts map will be mounted with the
    # "nosuid" and "nodev" options unless the "suid" and "dev"
    # options are explicitly given.
    #/net -hosts
    # Include /etc/auto.master.d/*.autofs
    # Include central master map if it can be found using
    # nsswitch sources.
    # Note that if there are entries for /net or /misc (as
    # above) in the included master map any keys that are the
    # same will not be seen as the first read key seen takes
    # precedence.
    /media/ /etc/auto.ext-usb --timeout=10,defaults,user,exec,uid=1000

    Have I missed something in the tutorial? Is it possible to get an example on how this auto.ext-usb can look like?

    Best Regards

    • Birdy
      November 21, 2013 at 6:22 pm

      I have the same problem !!
      How does the auto.ext-usb file look like ??

    • James B
      November 21, 2013 at 7:33 pm

      Hmm, sounds like you're running a different flavour of the linux OS, maybe? That bit of the instruction might be specific to Raspian, so you'd have to check with other versions.

    • Birdy
      November 26, 2013 at 8:19 am

      I have 2013.09.25 Raspbian Weezy installed, from

      which version are you running. ??
      Is ist possible to post the auto.ext-usb file or email it to me ???


  13. shywolf91
    November 3, 2013 at 8:53 pm

    Could the nas be access over the internet (outside my local network).

    I need something to access my drives when I go on vacation in mexico.

    • James B
      November 4, 2013 at 10:18 am

      I believe you would need to setup a VPN server on your Pi, then connect to that remotely. Not something I know how to do I'm afraid.

  14. Lino
    October 16, 2013 at 4:24 pm

    Thanks for the reply, James. I think I'll stick to my original plan of getting the Seagate Central.

    Looking forward to other Pi articles!

  15. Lino
    October 16, 2013 at 9:27 am

    Great tutorial!

    I was planning on buying a Seagate Central, but I thought I'd play around with my RasPi and 1TB external HD first.

    I found out that when I stream saved tv shows from the NAS to my laptop (in XBMC) and the other laptops copy files from the NAS, my videos start stuttering and web browsing becomes a bit slow.

    I was planning on just buying a 3TB external hardisk and hooking it up to the RasPi if I got this to work, but will it help the stuttering and the web browsing if I just buy the commercialized NAS like the Seagate Central?

    • James B
      October 16, 2013 at 9:47 am

      Depends on your internal network, I would say. Streaming over wifi is going to be bad whatever else you're doing - but generally I wouldnt try streaming from the Pi anyway. I would say get a real NAS, and make sure your internal cabling is gigabit; forget wifi, unless no other alternative.

  16. Dan
    October 5, 2013 at 1:48 pm

    Try using lidroid file explorer for android. There's a free samba client plugin. Recognized my share immediately.

  17. rakesh
    September 29, 2013 at 9:50 am

    how to access the files from android?

  18. Andrew Donkin
    September 26, 2013 at 12:34 am

    Regarding the comparison of NTFS versus ext4, why not keep your master data in ext4 (or your choice of fast, journaled, Linux filesystem) and rsync it over to an NTFS partition of the same size? You will have the best of both worlds: speed, native permissions, and case sensitivity on the master and convenience on the slave.

    Just be careful not to create two entries in a directory with the same name but different CaSeS, and tweak your rsync invocation to allow some slop in time stamps, permissions, and filenames, and don't put more stuff in the ext4 partition than the NTFS one has room for.

    Thanks for the write-up James: great instructions. You've made my rpi-NAS project kind of a no-brainer :-) One uncertainty remains: do you have any tips for ensuring your external USB drives spin down?

    • James B
      September 27, 2013 at 10:42 am

      Thanks Andrew, that's genius. Unfortunately, I have no idea how to force a drive to spin down, but as far as I know that's something handled in the drive firmware, not an OS thing. So you shouldn't need to.

  19. Daniel Jäger
    September 21, 2013 at 10:56 pm

    Thx al lot for your how to :-) I configured my pi that way and all is working fine.

    I did one more thing to prevented the new created user "jamie " from login via ssh with the following commands:
    sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
    sudo nano /etc/ssh/sshd_config

    I addes the following line at the end of etc/ssh/sshd_config:
    AllowUsers pi

  20. Daniel
    September 21, 2013 at 8:49 pm

    Ran in to a bit of a problem. Same as for Mirko I had problems accessing the files, but managed to fix it using chown.

    Hi guys, great guide!

    But now I cant seem to change rights so that i'm able to write to the disk. when I try to use chmod it returns "Operation not supported" for each some of the files on the disk. (NTFS)

    I do get "drwxrwxrwx 1 share root 4096 Sep 12 21:47 disk1" from "ls -al /mnt/" but still cant write to the disk from windows.

    Anyone with any great ideas of things to try?

  21. Derek
    September 17, 2013 at 8:12 pm

    Pro Tip for Mac clients: Get rid of .DS_Store etc litter with smb.conf's " veto files=" option. Also a setting to auto delete vetos.

  22. Mirko
    September 7, 2013 at 3:02 pm

    OK I figured it out. In case anyone else has my problems here´s how to:

    1) I did not land on my USB drive because I forgott to
    mkdir /media/1/shares
    But the Samba config file pointed exactly there.
    100% my fault.

    2) The reason I could not write to my USB drive was because I followed the tutorial blindly exactly the way it was written.

    It seems that if you

    mkdir /media/1/shares logged in as pi@raspberrypi or somethng else and then later

    useradd jamie -m -G users (or any other user)

    then this new user (as which we try to conect via samba) does not have the rights to the folder made as pi@raspberrypi

    So we have to

    sudo chown jamie /media/1/shares

    in order to ake this "jamies" folder.

    Well I guess I get laughed at now but in case anyone else is a sstupid as I am I hope this helps ;-)


    • James B
      September 9, 2013 at 9:32 am

      Glad you got it sorted. Though the tutorial does say substitue "jamie" for your own username!

  23. Mirko
    September 4, 2013 at 8:28 pm

    Hi James,

    I can´t write. When I conect from my mac I can log in with the credentials set but if I want to copy a file MacFinder asks me for my password and then it can´t write.
    In my folder there´s a file called "pistore.desktop".
    My only explanation was that my mount directories refered me to the SD card instead of the USB drive and that´s why I could not write to it.


  24. Mirko
    September 3, 2013 at 9:29 pm

    Hi there,

    I did the tutorial over twice but I am constantly landing on my SD card instead of my USB drive.
    Now I am a bit lost as to what to do. I can´t redo the
    mount -t auto /dev/sda1 /media/1
    part as it tells me the device is mounted and umount is blocked because it is busy.

    This is my fdisk -l readout:

    fdisk -l

    Disk /dev/mmcblk0: 31.9 GB, 31893487616 bytes
    4 heads, 16 sectors/track, 973312 cylinders, total 62291968 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00047c7a

    Device Boot Start End Blocks Id System
    /dev/mmcblk0p1 8192 122879 57344 c W95 FAT32 (LBA)
    /dev/mmcblk0p2 122880 62291967 31084544 83 Linux
    Note: sector size is 4096 (not 512)

    Disk /dev/sda: 3000.6 GB, 3000590401536 bytes
    255 heads, 63 sectors/track, 45600 cylinders, total 732566016 sectors
    Units = sectors of 1 * 4096 = 4096 bytes
    Sector size (logical/physical): 4096 bytes / 4096 bytes
    I/O size (minimum/optimal): 4096 bytes / 4096 bytes
    Disk identifier: 0x000c5748

    Device Boot Start End Blocks Id System
    /dev/sda1 256 732566015 2930263040 7 HPFS/NTFS/exFAT

    I have a 3 TB USB device atached (just one).

    Since I ran things twice I am afraid other greenhornes like me run into the same problem. So any help is greatly appreciated.


    • James B
      September 4, 2013 at 8:24 am

      Hi Mirko - Ive been confused by the first bit - "constantly landing on SD card instead of USB". It looks like youve got a single 3tb NTFS partition there, which sounds good. Which bit are you having problems with?

  25. Sallal
    August 29, 2013 at 6:24 pm

    That's a pretty awesome tutorial you got there. I'm a total Raspi newb and it helped me a lot! I've actually done even a little more to make my Raspi+HDD compatible with my PS3 and Samsung TV, which apparently only support DLNA Media Servers (I'm not 100% sure about that statement, but anyways...)

    What I did was (root!):
    mkdir /media/1/shares/Music
    mkdir /media/1/shares/Video
    mkdir /media/1/shares/Photo
    apt-get install minidlna
    nano /etc/minidlna.conf

    Look for "media_dir", you'll find it quite at the beginning.
    Change the setting to:

    also change (just below):

    Also uncomment (remove the #) at:

    Save and Exit.
    You are able to start the DLNA by using "service minidlna start", You can also make it start at boot with "update-rc.d minidlna defaults". In case you change the configuration sometime, restart minidlna using "service minidlna force-reload".

    That's it! You should be able to see your Raspi on your PS3, Smart-TV and your WMPlayer now :)

    based on:

  26. Vassili
    August 23, 2013 at 12:34 am

    NTFS is probably one of the worst choices in this case. Other users have gotten 2-4 times faster transfer with ext4. Considering that the bottleneck is the 100Mbit ethernet adapter, those few extra MB/s make a real difference. Also, in general, NFS is significantly faster than Samba on the Pi.

    • James Bruce
      August 23, 2013 at 8:19 am

      Good advice Vassili, though it's still a pretty crap and underpowered NAS by any standard. I still think NTFS is better for data recovery though - if your NAS screws up formatted with EXT4, most people won't be able to get their data back.

  27. Richard Mullens
    August 18, 2013 at 3:31 am

    Everybody seems to assume that we want to use the Raspberry Pi with a windows box - but what if you want to use it to back up a linux environment where file names are case sensitive then surely NTFS is no good for this ?

    Am I correct in this ?

  28. nel6t9
    July 16, 2013 at 8:13 am

    what is the read/write rate to the shared drives on R.Pi? I assume the bottleneck will be the processor of the R.Pi?

    • Karl Rosenqvist
      August 15, 2013 at 7:28 am

      I don't think so. Unlike a x86 Windows machine Pi is well architected and runs Linux so the main CPU won't have much to do. Most likely USB transfer speeds are the bottleneck.

Leave a Reply

Your email address will not be published. Required fields are marked *