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:

[Backup]
 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:

 +auto.master
 /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.