Friday, 29 June 2018

Attaching an external hard drive to a Raspberry Pi

This post was covers installing an external USB hard drive to a Raspberry Pi 3 B+ running Raspbian Stretch Lite.

Firstly, I had terrible trouble getting my Seagate Expansion 2 TB USB 3.0 Desktop 3.5 Inch External Hard Drive to work correctly. Endless permission issues, problems with Samba, you name it.

The key to solving these issues was to install the NTFS-3G driver rather than using the standard NTFS driver when mounting the drive. I’ll cover that as I go in the steps described below.

Step 1

I started with the Raspberry Pi shutdown and simply attached the drive to a vacant USB port on the Pi. I the powered up the drive and then the Pi.

Step 2

SSH to the Raspberry Pi as usual. I then ran the following command to see what drives were now attached.

sudo blkid


image

I looked for the new Seagate drive which in this case was /dev/sda2. I made a note of the information, especially the UUID which I used later.

Step 3

So, I’m skipping all the trial and error here but the next significant thing to do is install the NTFS-3G driver using apt-get.

sudo apt-get install ntfs-3g


image

Step 4

Time to mount the drive on the file system. I chose to mount the drive under /media rather than /mnt or any other location. So, I created a folder specifically for the drive (/media/seagateHDD) then mounted the drive to that folder.

cd /media
mkdir seagateHDD
sudo mount /dev/sda2 /media/seagateHDD/ -t ntfs-3g

 NB: Note the use of the –t ntfs-3g option.

image

This proved the drive could be mounted and that it worked. As you can see permissions are wide open.

Step 5

Now we need to set up the system to reconnect the drive at start-up. For this I modified the fstab file.

sudo nano /etc/fstab


SNAGHTMLdb69cc 

And added the following line. Note the use of the UUID rather than /dev/sda2. This helps to ensure the same drive gets reattached just in case the device changes.

UUID=FC82A10F82A0D006 /media/seagateHDD ntfs-3g defaults 0 0


image

Step 6

Time to install Samba. Firstly I installed Samba using apt-get.

sudo apt-get install samba samba-common-bin


image

When that was done I edited the samba configuration file.

sudo nano /etc/samba/smb.conf

And added the following section.

[media]
     writeable = yes
     public = yes
     directory mode = 0777
     path = /media/seagateHDD/Media
     comment = Pi shared media folder
     create mode = 0777

Note that there was an existing folder called Media on the drive. I chose to make that folder accessible via Samba.

image

The a quick restart of Samba to read the new configuration.

sudo /etc/init.d/samba restart

Step 7

Test from Windows. I just added a Media Location mapped to my Raspberry Pi’s IP address and the media share and that was it!