2015-05-30 12.56.34Below is a basic guide on how to use your Raspberry Pi as a file server. I will be mounting an external drive and then sharing it across my network using the Pi. I am using the Raspbian image which can be downloaded here.

Mount External USB Hard Drive

Initially you will need to ensure your external hard drive is mounted. To do this first ensure your repositories are up to date by running

sudo apt-get update

You will then need to make a directory to mount your USB drive on. I have called this ‘externaldrive’

sudo mkdir /mnt/externaldrive

Now ensure the ‘Pi’ user is the owner of the mounted drive

sudo chown -R pi:pi /mnt/externaldrive

Depending on the format of the drive you are mounting you will need to install the following:

For NTFS
sudo apt-get install ntfs-3g -y

For exfat
sudo apt-get install exfat-utils -y

You are now able to mount the usb drive
sudo mount -o uid=pi,gid=pi /dev/sda1 /mnt/externaldrive

Mounting the drive automatically on boot

To ensure this drive is mounted automatically on boot you will first need to get the UUID of the drive.

sudo ls -l /dev/disk/by-uuid/

You will see an output like below. I have highlighted the UUID of the sda1 drive. Obviously yours will be different which you will need to make a note of.

total 0
lrwxrwxrwx 1 root root 12 May 14 11:39 0b2bb018-f019-4caa-9ecf-0d62d89aab43 -> ../../dm-1
lrwxrwxrwx 1 root root 12 May 14 11:39 521252e1-5d52-4b72-8ec7-d327ee10b03d -> ../../dm-0
lrwxrwxrwx 1 root root 12 May 14 11:39 f8c983e4-0a23-4ecf-b541-7bc40913e542 -> ../../sda1

You will also need to know the file system of the drive. If you do not know this you can run the following command to view the file system of all drives. Again it is the sda1 drive we will be interested in.

sudo blkid

Now we have all the information we need to edit the ‘fstab’ file.

sudo nano /etc/fstab

Then add the following line to the bottom of the file. Replacing XXXXXXX with the UUID you took a note of earlier and NTFS with the file system of your drive.

UUID=XXXXXXX /mnt/externaldrive NTFS uid=pi,gid=pi 0 0

Now reboot the Pi

sudo reboot

When you Pi comes back up you should be able to browse to your new directory

cd /mnt/externaldrive
ls

Setting up Samba

Install Samba

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

Edit the Samba config file

sudo nano /etc/samba/smb.conf

Uncomment WINS Support by changing

#wins support = no

to this

wins support = yes

Now at the bottom of the config file add the following:

[externaldrive]
comment = External Drive
path = /mnt/externaldrive
read only = no
browseable = yes
public = yes
force user = pi
force user = root
only guest = no

Restart the samba service

sudo service samba restart

You should now be able to access the share by going using one of the following:

IPADDRESS\externaldrive
HOSTNAME\externaldrive

Share