zoola.jpg

header.png


Home
IWH Software
My projects
Retro stuff
Random stuff
About me
Contact me
Admin login




Connecting an external USB drive

You would think connecting an external USB drive to a Pi would be automatically mounted and made available like it is on Windows systems, well it is if you're running a GUI, but I'm not, so I need to do it manually. There are applications like usbmount that will do this for you, but the mount points can vary between boots, and I wanted to set up the external drive to always mount at the same device at the same location all the time with no exception, I did this with the following instructions...

First you will need to create the mount point directory and make it world writable with these commands

pi@Home:/$ sudo mkdir /media/external
pi@Home:/$ sudo chmod 777 /media/external

Please note I had previously formatted the external drive in EXT4 on a Linux machine, but you can use NTFS which is wot Windoze uzes.
Don't use FAT32 which is what it will be formatted as when new, otherwise the maximum file size you can store will be limited to 4GB.
You will only need the following command if you're using a Windows formatted drive (NTFS), which will install the best device driver for the external drive.

pi@Home:/$ sudo apt-get install ntfs-3g

Now if you run the blkid (BLKID) command without the drive connected and note the output, then connect the drive through the powered hub and run it again you end up with something like this...

pi@Home:/$ sudo blkid
/dev/mmcblk0p1: SEC_TYPE="msdos" LABEL="boot" UUID="056E-4E83" TYPE="vfat"
/dev/mmcblk0p2: UUID="af599925-1134-4b6e-8883-fb6a99cd58f1" TYPE="ext4"

pi@Home:# sudo blkid
/dev/mmcblk0p1: SEC_TYPE="msdos" LABEL="boot" UUID="056E-4E83" TYPE="vfat"
/dev/mmcblk0p2: UUID="af599925-1134-4b6e-8883-fb6a99cd58f1" TYPE="ext4"
/dev/sda1: UUID="87a91a41-a13a-4b6c-92b8-2d7b6e3fd31c" TYPE="ext4"

The new entry at /dev/sda1 is your external drive, so note down the UUID number (87a91a41-a13a-4b6c-92b8-2d7b6e3fd31c) and the TYPE entry (ext4) then use the command...

pi@Home:/$ sudo nano /etc/fstab

and using the cursor keys to scroll down, enter this line at the bottom...

UUID="87a91a41-a13a-4b6c-92b8-2d7b6e3fd31c" /media/external ext4 defaults 0 0

Please use your values instead of mine and that's a tab space between the values.
Doing this will always auto mount the USB drive automatically at /media/external at startup.

BTW, usbmount works, but doesn't always mount at the same location in the filesystem, which will be a problem with some scripts used later on.

Now you need to either reboot

pi@Home:/$ sudo reboot

or use the command to mount drives as according to fstab

pi@Home:/$ sudo mount -a

And that's it

© 2020 IWH Software (Ian Hill)