Turn Raspberry into a small NAS with samba

I got a Raspberry Pi Model B. It’s cheap and I want to do some experiments for fun.

Experiment #1: I have a 1T external HDD (FAT) and I want to turn Raspberry into a very basic NAS.

I used:

  • 1 External USB HDD (with external power supply)
  • 1 ethernet cable CAT. 5 (10/100) or better
  • 1 HDMI cable and monitor / tv
  • 1 smartphone microusb battery charger
  • 1 SDHC (for the OS)
  • Raspbian “wheezy” (tested on 2012-08-16 release)
  • 1 modem router for connectivity (4 port)
  • 1 Windows PC plugged to the router

I flashed Raspbian into a class 10 SDHC, I follow this useful howto about to turn on HDMI instead of TV and voilà, I got a down-scaled debian system into a silent, little board that I charge with the smartphone charger via microusb (5V, 700mA).

I plug a wireless mouse and keyboard on the first USB port, and then I plug my external drive on the second. Debian read the FAT partition well (mounted on /media/MYDRIVE), but now I have to turn it into a wannabe-NAS.

Shall we dance? With Samba!

I plug the RJ-45 ethernet connector from my modem router into the Raspberry Pi and I follow this howto in Italian.

$ is a pi console (Start > Accessories > LXTerminal)
# is a root console (Start > Accessories > Root terminal)

# adduser guest --home=/home/public --shell=/bin/false --disabled-password
# sudo chmod -R 0700 /home/public
# chown -R guest.guest /home/public
$ sudo apt-get install samba smbfs

Then I have a new user “guest” with no password authentication. The howto covers the creation of a shared home (/home/public) but I do something slightly different (WORKGROUP is my local network name):

editing /etc/samba/smb.conf

## Browsing/Identification ###
# Change this to the workgroup/NT-domain name your Samba server will part of
   workgroup = WORKGROUP

####### Authentication #######
   security = share

   obey pam restrictions = yes
   guest account = guest
   invalid users = root

And now the most interesting part:

[MYDRIVE]
comment = Mydrive
read only = no
locking = no
path = /media/MYDRIVE
guest ok = yes
force user = pi

Where /media/MYDRIVE is the path to your external usb drive.

And then:

# /etc/init.d/samba restart

to apply.

As this howto explains, the “force user” allows a user (i.e. guest) to get the files from a device mounted by another user (i.e. pi, the default raspbian user).

Have fun

Now on the Windows machine on the Network panel I look for RASPBERRYPI and inside it I find the “mydrive” folder, with all the files from MYDRIVE within. I play a 720p video without slowdown. And so, the cheap NAS experiment is successfully completed.

Tags: , , , , , , , ,

13 responses to “Turn Raspberry into a small NAS with samba”

  1. sid5427 says :

    nice one !

    was wondering another thing

    did you try using an USB hub and connecting 2 or more external hard drives ?

    I would assume i’ll need to ‘mount’ the two hard drives separately i.e. having two mydrive folders ?

    • chirale says :

      Not yet but yes, you have to add a new section to smb.conf using a different mount point and a different header. So change Mydrive into something else on the second declaration. Be careful not to drain too much power from the Pi, I suggest you to plug only externally powered devices. Thank you for reading!

  2. Lele says :

    Thank You, very useful article!
    Lele.

  3. Bleuarff says :

    simple and straightforward, works like a charme. Thanks a lot!

  4. Fanie says :

    Awesome stuff!!! Thanks!!! Any Idea on getting it to list on AllShare?

  5. joohnny says :

    Hi there,

    Thanks fot his post. I’ve been starting using this method a few weeks ago and it worked fine. Now, I’ve got a crash when I was in vacation : samba was not running anymore when I came back home (pidof samba returns nothing). I don’t know if the power has been cut or not. How can I find a crash report? I saw on the smb.conf that there is a script /usr/share/samba/panic-action that should have been executed. Unfortulately, I don’t know the script language and don’t understand where the infos have been sent. Thanks for help.

    • chirale says :

      Thank you for reading and commenting. Logs are usually stored in /var/log/samba/ you’ll probably find a hint about what happens inside that directory typing: “sudo bash” and then “less +G /var/log/samba/filename-to-read”.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 33 other followers

%d bloggers like this: