Samba is an easy way to share an external storage to the whole network.
In my case there is a 2TB USB Hard Disk, which I wanted to share to everyone. My router would provide a built-in NAS option, but not everyone does have the luck of owning a router capable of this option and furthermore, where is the fun in that? Let’s get started:
Pre-Samba:
Install raspberian on the SD. Get the image and a good description of the installation on http://www.raspberrypi.org/
After the installation you can give your Raspberry Pi a shiny name and you can also change the overclocking settings. Mine are running medium overclocking settings.
If you own a router who is providing DHCP to the network, I suggest giving your raspberry(s) a static IP address. This will make your life easier and also prevents confusion if you are using more then 1 raspberry.
The MAC address might be needed, for this reason use the command:
1 ifconfig
eth0 is your network adapter.
USB drive mount:
First we need to tell your raspberry where to find the USB drive.
1 sudo apt-get -y install ntfs-3g hfsutils hfsprogs exfat-fuse
driver installation
1 sudo mkdir /media/usb
You can change “usb” to whatever you like
1 tail -f /var/log/messages
Execute this command AFTER you plug in your USB drive. It should prompt something like “sda:”.
CTRL + C
to cancel the message
Depanding on the filesystem we will mount the USB drive now
FAT32:
1 sudo mount -t vfat -o uid=pi,gid=pi /dev/sda /media/usb/
NTFS
1 sudo mount -t ntfs-3g -o uid=pi,gid=pi /dev/sda /media/usb
exFAT
1 sudo mount -t exfat -o force,rw,uid=pi,gid=pi /dev/sda /media/usb
In order to mount the USB drive during every restart we needto do the following steps
1 sudo blkid /dev/sda
This will output an UUID. Note your UUID and procceed to the next step
1 sudo nano -Bw /etc/fstab
Add one of the following at the end of the file (depending on your filesystem)
FAT32
1 UUID=your-uuid /media/usb /vfat defaults,auto,umask=000,users,rw 0
NTFS
1 UUID=your uuid /media/usb ntfs-3g defaults,auto,umask=000,users,rw 0
exFAT
1 UUID=your uuid /media/usb exfat defaults,auto,umask=000,users,rw 0
That’s it, we are done mounting the USB drive. The next step is to install samba:
1 sudo apt-get install -y samba samba-common-bin
After that we need to edit smb.conf
1 sudo nano /etc/samba/smb.conf
uncomment (delete ‘#’) the following line and save
1 # security = user
to
1 security = user
Now we are adding a samba user to the standard user pi
1 sudo smbpasswd -a pi
and add the rights to the USB drive
1 sudo chown -R pi:pi /media/usb
we are now editing smb.conf
1 sudo nano /etc/samba/smb.conf
At the end of the file add the following code. change [share] to whatever you want. This will be the name which is displayed to the users.
123456 [share]path = /media/usbwriteable = yesguest ok = no
save and restart
1 sudo /etc/init.d/samba restart
[1] We are now adding users who may access the USB drive. Replace [user] with a username of your choice.
1 sudo adduser --disabled-password --disabled login [user]
[2] Adding the user to samba. Replace [user] again with the user created in the steop before.
1 sudo smbpasswd -a [user]
We are almost done. The last step is to configure smb.conf:
1 sudo nano /etc/samba/smb.conf
This part now is pretty much customizeable to fit your needs. I will provide a basic configuration and my personal configuration that has 2 users. To add a user simply repeat the steps [1] and [2].
123456789101112131415 [sharename]path = /media/usbwriteable = nowrite list = [user]guest ok = noavailable = yesbrowseable = yesvalid users = [user]
This configuration will provide your user full access to your USB drive. Below you can see my setup which is set up for 2 users, one with full rights to the USB drive and another share that has just access to one folder of the USB drive.
Restart your samba one last time.
1 sudo /etc/init.d./samba restart
We are done!
Credit goes to http://jankarres.de/ who provides very good guides about Raspberry Pi in German. I have made the whole samba setup using his guides.