Raspberry Pi: NAS server

I have been wanting to set up my Raspberry Pi as a Network Attached Storage (NAS) drive for quite some time. I eventually got a chance yesterday to give it a go. Unfortunately the Raspberry Pi USB port can’t power my external hard drive and I don’t have a USB hub at the moment, so I just used a 16GB flash drive.
First you need to format your external drive with NTFS. Then place a file on it. Any file will do. I chose a text document so that I can open it and view it on the Pi. Once you have set up your drive, turn off your RasPi, plug the drive into the USB port and then turn on the RasPi. It is safer to plug the USB in when the RasPi is off because some versions don’t have poly fuses on the USB ports.
Once booted up, log in and check to see if the drive is connected.
  • sudo fdisk -l

You can see that my connected drive is right at the bottom. The drive is called sda and because there is only one partition, it is called sda1.
Next you need to create a folder where your drive is going to be mounted into. I called mine myHadrDrive. You also need to give the folder root access so that when you connect to it you are able to read from it and write to it.
  • sudo mkdir /mnt/myHardDrive
  • sudo chmod 0777 myHardDrive
Next you need to mount the hard drive to the folder that has just been created. Open fstab and add the following line to the bottom of the file where it reflects your setup.
  • sudo nano /etc/fstab

Mount the drive
  • sudo mount -a
Now we need to install and set up the Samba server. This will allow a windows machine to connect to the RasPi over the network. Start by installing the following packages using apt-get.
  • sudo apt-get install samba
  • sudo apt-get install samba-common-bin
  • sudo apt-get install ntfs-config
  • sudo apt-get install ntfs-3g
Once all of those packages are installed, edit the Samba configuration file. It took me a while to get this right but with the help of this video, I managed to get it. 
  • sudo nano /etc/samba/smb.conf
Replace the entire file with the following:

#======================= Global Settings =======================
workgroup = WORKGROUP
server string = raspnas server
netbios name = raspnas
dns proxy = no
### Logging
log file = /var/log/samba/log.%m
max log size = 1000
syslog = 0
panic action = /usr/share/samba/panic-action %d
### Authentication
security = user
map to guest = pi
#======================= Sharered Folders =======================
path = /mnt/myHardDrive
guest ok = yes
guest account = ftp
browseable = yes
read only = no
create mask = 0777
directory mask = 0777
writeable = yes
admin users = everyone

A few points to note:
  • WORKGROUP is the workgroup that the drive will be connected to
  • raspnas is the name of he drive on the network
  • path is the folder that you set up earlier
  • Change the file according to your setup
Lastly you need to restart the Samba service and add the user to the Samba database
  • sudo service samba restart
  • sudo smbpasswd -a pi
Now your Samba server is set up. You still need to do one last thing. You need to make sure that the drive gets connected at startup.
  • sudo apt-get install autofs
Add the following line to the bottom of the config file
  • sudo nano /etc/auto.master

Reboot your RasPi and then you should be able to log on to the shared drive using your Windows machine.
I hope this has helped anyone who was stuck. If you still have any problems leave a message in the comments and I’ll try help as best I can.