Occasionally you might find that you need to mount a USB to a Raspberry Pi to access or transfer some data to the onboard MicroSD card. Most of the time you will be running some flavour of linux which does not automatically mount the USB like Windows traditional would. You have to do that yourself in Linux Land.
Mounting a USB:
First up we will need to run the following command:
ls -l /dev/disk/by-uuid/
This will show a list of devices that are connected to the Raspberry Pi. Generally the line that refers to “/sda” is the device. Note down the ID. In this example, my ID is 18A9-9943.
Next you will need to create a mount point. This is a directory that will point to the contents of your flash drive. To make this directory run the following command.
sudo mkdir /media/usb
I’m using USB here, but you can use what ever name you like. Keep it short as it saves typing something longer or more complicated.
Next we need to make sure the Pi user owns the folder:
sudo chown -R pi:pi /media/usb
You will only need to do this step once.
To mount the USB run the following command:
sudo mount /dev/sda1 /media/usb -o uid=pi,gid=pi
This will mount trhe drive so that the ordinary Pi user can write to it. Omitting the “-o uid=pi,gid=pi” would mean you could only write to it using sudo.
You should now be able to read and write to the USB by using the /media/usb directory. Anything you place into this folder will be placed onto the USB.
Un-Mounting a USB
You dont need to manually un-mount if you shutdown your Pi but if you need to remove the drive at any other time you should un-mount the USB first. Only the user that mounts the USB can un-mount the USB. Learnt that the hard way. :)
To un-mount the USB run the following command: