I’m in the process of testing some local video surveillance software and to continue my investigation I need to mount a USB drive to take the strain off the SD card.

Plug it in and find it

I’ve already formatted my usb drive to ext4 so I’ve just plugged it into one of the pis usb ports.

Open a terminal on your pi (either locally or via SSH) and use the following command:

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

This should show you a list of available drives. My example shows the SD card partitions (labelled mmc…) and another drive labelled sda1, this is my USB drive

lrwxrwxrwx 1 root root 15 Nov 29 02:37 72bfc10d-73ec-4d9e-a54a-1cc507ee7ed2 -> ../../mmcblk0p2
lrwxrwxrwx 1 root root 10 Nov 29 02:37 8da04276-eaa8-4f74-9904-4bd8ab2ca80d -> ../../sda1
lrwxrwxrwx 1 root root 15 Nov 29 02:37 CDD4-B453 -> ../../mmcblk0p1

Grab a copy of the UUID for later, in this example, mine is 8da04276-eaa8-4f74-9904-4bd8ab2ca80d.

Now I’m going to create a directory for the mount. I’m calling mine usb.

sudo mkdir /media/usb

Now we need to chown it so our pi login can use it:

sudo chown -R pi: /media/usb

Now we can test that the drive is working by mounting it manually:

sudo mount -t ext4 -o defaults /dev/sda1 /media/usb

I copied a file to it to test that I could do so without needing to use sudo, it was successful.

Now I need to make sure that the drive is available on boot incase I restart my pi at any point:

sudo vi /etc/fstab

Insert the following at the end of the file:

UUID=<uuid-from-earlier> /media/usb ext4 defaults 0

My example:

UUID=8da04276-eaa8-4f74-9904-4bd8ab2ca80d /media/usb ext4 defaults 0

That should be it, I recommend a quick restart to test but be warned, if you mess it up, there’s a chance your pi won’t boot because it may be searching for a drive that doesn’t exist. It can be solved easily but if you’re running headless (like me), it may not be obvious and you may have to plug your pi into a monitor to be able to skip the drive search.