In this guide, we’re going to use a Raspberry Pi to mount a USB drive. We show you both how Raspbian automatically mounts a drive and how to do it manually.
If you’re looking to have this drive accessible over your network, then the Raspberry Pi samba server is better suited for your needs.
If you want to see how to do this project visually, then be sure to check out my video below. It will take you through all the necessary steps to getting your USB drive mounted correctly. If you do like the video, then be sure to subscribe to stay up to date on all my projects, guides and much more.
You will need some basic equipment for setting up a Raspberry Pi mounted USB drive.
Note: If you plan on using an external hard drive, then it is highly likely you will need a powered USB hub. This recommendation is because the Raspberry Pi is unable to output enough power via the USB ports to power the drive.
Raspberry Pi: Mount a USB Drive Automatically
In the latest version of Raspbian (Jessie), your USB drives should be automatically mounted when it is connected to the Pi. It is important to know if you do upgrade to Jessie from wheezy there might be compatibility problems with older projects & tutorials.
If you want to check where your drive has been mounted, you can simply use the following command:
sudo cat /proc/mounts
This will output quite a bit of text. Any USB drives are typically at the bottom of the text as shown in the image below.
As you can see my drive located at
/dev/sda1 has been automatically mounted to
The automatic mounting done by Raspbian will be fine for most projects and just regular use. It will retain its mount location whenever you remove and re-insert the drive since it uses the UUID of the drive for the mount folder name. You can also find out the UUID by using the following command:
ls -l /dev/disk/by-uuid.
You might come across problems if you wish to allow access to the drive to a specific user that isn’t the default user. In our next step, we will mount the drive using the fstab file and force permissions of a given user and group.
Raspberry Pi: Mount a USB Drive Manually
If you want to permanently mount the drive with a specific user, then we will need to set up the drive in the fstab file.
1. Firstly install the following package if you’re using an NTFS drive.
sudo apt-get install ntfs-3g
2. Now if you don’t know the drive UUID, then we will need to get it. You can get a list of drives and their UUID that is currently connected to the Pi by running the following command.
ls -l /dev/disk/by-uuid
3. Now there is likely to be quite a few drives listed. Simply look for any drive that has an address of /sda* where * is a number. In my example, it is 1, so we will use the UUID of CA1C-06BC to mount to.
4. Now it is important that we create a clean directory to mount the USB too. To create the directory, enter the following:
sudo mkdir /media/usb1
5. Next, we will need to obtain both the uid and the gid. These numbers are important as we will need them to set the correct permissions for the USB drive. To get the gid enter the following command. (If you’re using a different user than pi then make sure you update the username in the following commands).
id -g pi
6. Get the uid enter the following command.
id -u pi
7. Next, we need to make an edit to the fstab file. It is the file that is called on boot up to set up the drives. To edit this file, enter the following command:
sudo nano /etc/fstab
8. Now add the following line to the bottom of this file. Remember to update the line with all the relevant details for your USB drive. (For example, your drive will have a different UUID)
UUID=CA1C-06BC /media/usb1 auto nofail,uid=enter_uid_here,gid=enter_gid_here,noatime 0 0
9. Now since the Pi automatically mounts the drive, we will need to unmount the drive. A simple way to do this is to use the following command (Replace /dev/sda1 with the address relevant to your Pi).
sudo umount /dev/sda1
10. Now you can use the following command, and your drives should become mounted.
sudo mount -a
11. If you want to make sure the drives are restored after the Pi has been shut down then simply run the following command:
12. The drives should be automatically mounted after the Raspberry Pi has finished rebooting.
Hopefully, you have your drive mounted to the Raspberry Pi now. If you have any troubles, then be sure to check out the troubleshooting guide below.
These following issues will most likely arise only for when you manually mount the drive.
One of the biggest problems that you will come across with mounting a drive is permissions. If you’re finding that you can’t read/write files to the mounted drive, then it is likely that the drive is mounted as the wrong user or group.
Another problem you may come across is the drive not being mounted on boot. There have been some changes to Raspbian and the Raspberry Pi that might cause issues with mount the drive in time. The best way to work around this would be to add the following lines before the exit 0 line in the /etc/rc.local file.
sleep 20 sudo mount -a
Hopefully, you are now able to set up a Raspberry Pi mount USB drive. If you are having issues with the mount, I missed something or anything else then feel free to drop a comment below. We also have plenty of Raspberry Pi beginner projects that you should take a look at if you’re looking to do doing something cool with your Pi.