Setup the Raspberry Pi as a NAS

Setup the Raspberry Pi as a NAS

The Raspberry Pi is a great device with many possibilities and one such great use is as a NAS server for your LAN.

The Raspberry Pi by itself is limited by the space it can offer so you will need to add a USB SATA storage device like the Thermaltake BlacX attached to the Pi with a drive size of your preference, my own is a 1TB drive with NTFS shared to Windows OS and MAC OS systems for access.

First install, NTFS support:

$ sudo apt-get install ntfs-3g

Create the mount directory and mount it:

$ sudo mkdir /media/ext

Mount as NTFS as user id pi:

$ sudo mount -t auto /dev/sda1 /media/ext

Create a share directory”

$ sudo mkdir /media/ext/share

Install Samba support:

$ sudo apt-get install samba samba-common-bin

Edit Samba config and create the share drive:

$ sudo nano /etc/samba/smb.conf

Remove the # symbol from the security = user line (by highlighting it with the cursor and pressing delete) to enable username/password verification for the Samba shares.

Next, we’re going to add an entirely new section to the configuration file. Scroll all the way down to the very bottom of the file and enter the following text:

comment = Backup Folder
path = /media/ext/share
valid users = @users
force group = users
browsable = yes
create mask = 0660
directory mask = 0771
read only = no

Press CTRL+X to exit, press Y when asked if you want to keep changes and overwrite the existing configuration file. When back at the command prompt enter the following command to restart the Samba daemons:

$ sudo /etc/init.d/samba restart

At this point we need to add in a user that can access the Pi’s Samba shares. We’re going to make an account with the username backups and the password backups4pi. You can make your username and password whatever you wish. To do so type the following commands:

$ sudo useradd backups -m -G users
$ sudo passwd backups

You’ll be prompted to type in the password twice to confirm. After confirming the password, it’s time to add “backups” as a legitimate Samba user. Enter the following command:

$ sudo smbpasswd -a backups

Edit fstab and add the entry for the mount:

$ sudo nano /etc/fstab

This will open up the file systems table in nano so we can add a few quick entries. Within the nano editor add the following lines:

/dev/sda1 /media/ext auto noatime 0 0

This will install the auto USB mounting system:

$ sudo apt-get install autofs

However we need to set up a config file to allow the auto mounting of the USB disk:

$ sudo vi /etc/auto.master

At the end of the file is +auto.master. You need to add the following below the +auto.master entry:

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

That’s all you need and can now access the share from any system in your LAN.

  • To_O

    Great post, thanks.
    But… Why NTFS ? If you use samba, you could use ext3 or ext4 or other file system.

  • Yedmundi II

    Since this is a USB2.0 based filesystem being shared over 100m ethernet, is there a particular filesystem that is best optimized for a slow physical connection?

    Seems ok for a NAS sharing infrequently access data, but on a modern gig speed LAN, there are plenty of inexpensive build options that include gig ethernet and native SATA that might be a better fit for a NAS appliance.

    For a NAS appliance, the one thing you are missing is the appliance front end. I personally like your approach of configuring Samba directly, however there are some nice free NAS front ends that should work great on the Pi.

    Also, what distro are you using? It appears to be a Debian variant (Ubuntu perhaps?), but you don’t specifically say. There are so many distros to choose from for the Pi, the more novice users might need some basic background information to get started on the right foot.

    To me the beauty of a small system like the raspberry PI is not going to be in the traditional roles of a Linux system , rather it is in roles where the small size is used to an advantage… Like adding web and other features to a TV set, or imbedding into a robot or other project. To that end, building this into the case of an external drive might be a good way to exploit the best features of the Pi…