Since I own multiple external hard drives and use those on multiple computers I thought it would be nicer to have them all connected to my local network instead of switching cables. Naturally this can be done very easy using a RaspberryPi. I've tried many ways of sharing disks and connecting to them but only one of those ways seems to be the best by far; SSHFS.
SSH is a secure shell application that allows remote access. SSHFS can use SSH to access a filesystem over this secure connection. It's not only a very secure way to connect but also very fast and stable, even from remote locations. On local networks SSHFS is fast enough for central storage and direct access of audio/video files so ideal for a media center or NAS.
When using autofs on your client pc it's possible to automatically connect to the shared storage when accessing it's configured mountpoint and will be disconnected after a certain period of inactivity.
Setting this up is easy as Pi. This HOWTO explains how to set it up using a Linux client pc using autofs. On the Mac it should work quite similar but you can also use other tools like SSHFS for Mac or Android or WinSSHFS on Windows.
On the RaspberryPi:
Enable the ssh server (is active by default on most OS)
Code: Select all
sudo apt-get install openssh-server
sudo update-rc.d ssh defaults
Mounting external disks in a set location using fstab:
Next we need to mount the disks and make sure they always get mounted in the same location. The most easy way to do this is by mounting them by Label or by uuid. I find labels the most effective way since the uuid changes when you re-partition or format the disk. When using labels you can easily replace a disk without having to re-do any settings.
You can see the label and uuid of a disk by mounting it first and then execute the following:
Code: Select all
ls -l /dev/disk/by-label/Code: Select all
ls -l /dev/disk/by-uuid/In this example the label for /dev/sda1 is ExtHDD_01. Next we need to know the filesystem type of the disk, if you don't know this an easy way to find out is by typing the command;lrwxrwxrwx 1 root root 10 Sep 4 18:35 ExtHDD_01 -> ../../sda1
Code: Select all
mountCode: Select all
sudo mkdir /media/ExtHDD_01Code: Select all
sudo nano /etc/fstabOnce you've added all your disks you can test your configuration by executing:LABEL=ExtHDD_01 /media/ExtHDD_01 xfs default 0 0
Code: Select all
sudo mount -aOnce all disks have been set-up correctly it's time to configure the client.
On the Client PC: (Debian/Ubuntu)
Install the tools we need:
Code: Select all
sudo apt-get install autofs sshfs openssh-clientCode: Select all
cd
mkdir .ssh
cd .ssh
ssh-keygenNext add your key to the server's authorized_keys file:
Code: Select all
ssh-copy-id username@IP-OF-YOUR-RASPBERRYPIYou should now be able to connect with the Pi using the key for authentication. You can test this by connecting to the Pi:
Code: Select all
ssh username@IP-OF-YOUR-RASPBERRYPIConfigure autofs;
To configure autofs we need to create a directory in which to mount the remote filesystems. Also on the client we choose a new directory under /media. Let's create this first:
Code: Select all
sudo mkdir /media/RemoteFSCode: Select all
cat /etc/passwd | grep $USERIn the output you'll see two numbers, the first is the uid and the second the gid.username1000:1000:Full Name,,,:/home/username:/bin/bash
Now we need to add a default configuration for SSHFS in the master configuration file /etc/auto.master.
Code: Select all
sudo nano /etc/auto.masterNext we need to create the sshfs configuration for autofs in which we can configure the remote mounts./media/RemoteFS /etc/auto.sshfs uid=1000,gid=1000,--timeout=30,--ghost
Code: Select all
sudo nano /etc/auto.sshfsMake an entry for all the disks you like to configure or simply make one entry for all mounts under /media on your Pi like this:ExtHDD_01 -fstype=fuse,rw,nodev,nonempty,noatime,allow_other,max_read=65536 :sshfs\#username@IP-OF-YOUR-RASPBERRYPI\:/media/ExtHDD_01
Next restart the autofs daemon:RasPi -fstype=fuse,rw,nodev,nonempty,noatime,allow_other,max_read=65536 :sshfs\#username@IP-OF-YOUR-RASPBERRYPI\:/media
Code: Select all
sudo service autofs restart
ls /media/RemoteFS/