How to Mount a USB Drive on Raspberry Pi

How to Mount a USB Drive on Raspberry Pi

I’ve used USB drives with Raspberry Pi for all kinds of projects, and mounting them is still one of those things I think Linux makes unnecessarily confusing. If you’re new to Raspberry Pi, even finding where to start can be frustrating. Let me show you how to get your USB drive working fast.

In most cases, your Raspberry Pi OS Desktop will automatically mount a USB drive. If needed, the USB drive can be mounted manually from the command line with ‘sudo mount /dev/sda1 /mnt/usb’.

Don’t worry, it’s not that complicated. I’ll show you 2 methods: the manual way (for temporary devices) and the automatic way (for devices you want to use often on your Raspberry Pi). I’ll finish with some bonus tips that you may find useful.

If you’re new to Raspberry Pi or Linux, I’ve got something that can help you right away!
Download my free Linux commands cheat sheet – it’s a quick reference guide with all the essential commands you’ll need to get things done on your Raspberry Pi. Click here to get it for free!

If you click our links and make a purchase, we may earn an affiliate commission. Learn more

Before Mounting the Drive

Before going any further, we need to collect information about your hard drive, such as the identifier and file system type it uses. We’ll also create a new folder to mount the drive in.

Note: If you want to see all these steps in action, I have a video lesson available for the community members. You can join here and watch it directly if you are interested (with 20+ other lessons for Raspberry Pi and many other benefits).

What You Need

Here is the recommended hardware to follow this tutorial:

And as for most projects, adding these optional accessories can make your life easier:

  • A good keyboard and mouse: I use this one, but other options are available (I tested most of them in this comparison).
  • A decent monitor: always easier to follow instructions when you can see what’s going on with the Raspberry Pi, and not having to switch from your computer to the Pi all the time.
  • The best Raspberry Pi case: it’s the one I use all the time. It keeps my Pi protected and cool, a must-have (tested here).

Prepare Raspberry Pi OS

You can follow this tutorial with any Raspberry Pi OS version and nearly any Linux distribution. No prerequisites, just adjust the commands if you are not using a Debian-based distribution.

Before doing anything on your system, start by updating it with:
sudo apt update
sudo apt upgrade

Something not working as expected?
You can get answers from real experts in minutes.
Get help with your setup

And if you plan to plug in a USB drive that uses NTFS (NTFS is mainly for Windows devices and may not be required in your case), check that you have the required package installed:
sudo apt install ntfs-3g

It will tell you if you already have it installed.

Tip: Command lines can be a pain to memorize. I put the essential Linux commands on a printable cheat sheet so you don't have to keep googling them. You can grab the PDF here if you want to save some time.

Connect the USB Drive

You can then plug your device into a free USB port. If you have a recent model, it’s better to plug the USB device into a blue port. USB3 ports are faster overall.

Use the blue ports for USB drives when possible. Keyboard, mouse and other accessories can go on the black ports.

For large external drives, you may need extra power to run the drive properly (or you may see the message “Under-voltage detected!”).

Try adding a powered USB hub to the Raspberry Pi (check this one on Amazon, if you don’t already have one). Your hard drive will not work without that (unless it has its own power supply).

If you are using one, plug the hub into the Raspberry Pi and your hard drive directly into the hub.

And if you don’t have a USB drive yet, here are my two recommendations currently:

  • This USB flash drive from SanDisk: I use it all the time. I rarely use SD cards now and install my new distributions on this instead. I’m pleased with it, as it’s fast and robust.
  • This USB portable SSD: It’s perfect for the Raspberry Pi (almost the same size); it’s one of the fastest options, and I love SanDisk.

We are ready with the prerequisites.
Now, there are two ways to mount your USB drive:

I’ll explain each method in the next sections, so you can pick the one you prefer.

Method 1: Automatically Mount the USB Drive

If you’re using a graphical desktop environment on your system, like Raspberry Pi OS Desktop edition, it’s quite easy. When you plug in a USB drive, the desktop automatically detects it and mounts it using the file manager.

Recommended next step
Master Raspberry Pi in 30 Days

If you want a clearer path than jumping from tutorial to tutorial, my book gives you a step-by-step roadmap to really understand your Raspberry Pi.

Check the book here

Mounting a USB Drive on the Desktop

On the Raspberry Pi OS desktop, a notification will appear in the top right.
Click Open, and it’ll show you the contents of the USB drive.

The USB drive will be automatically mounted under /media/{username}/{drivename}, so for this example above, /media/pat/CES_X64FREO.

From here, you can do any operations with the files on the USB drive like you would with any folder on your system, such as copying or deleting files, and so on.

You can also access the USB drive from the command line, using the path from your file manager.

Unmounting a USB Drive on the Desktop

Unmounting a USB drive on the desktop is super easy. Just look for the eject button and click it. (You can’t be actively using the drive, so close all windows for eject to succeed.)

Now you can unplug the USB stick. You’re done.

The details might differ slightly on other desktop systems, but the overall idea is the same: plug in the USB drive, the system will automatically mount it, and you can find it in the file manager. When you’re done, click eject to unmount it.

Method 2: Manually Mount the USB drive

What if you’re not using a desktop on your Raspberry Pi, or what if your system doesn’t automatically mount USB drives for you? Then you can do it manually. In this section, we’ll learn how to mount a USB drive using the command line.

The big picture steps are:

  • Find the USB’s device name.
  • Create a folder as a mount point.
  • Mount the USB drive to that folder.

Let’s go over each step in detail.

Find the USB’s Device Name

Once the USB is plugged in, we need to know the device name the system assigned it.

Fdisk is a tool to manage disks on Linux.
We’ll use it to display all disks and find your USB drive (full tutorial here).

Start with this command:
sudo fdisk -l

At the end of the output, you should find something like this:

  • First, be sure you’re checking the disk you want to mount.
    Check the drive’s size to know if it is the right one (in this case I plugged a 32GB flash drive, so I’m sure it’s this one).
    If you’re not sure, unplug it and run the command again to see which one disappears.
  • Next, get the device name: here it’s /dev/sda1, we’ll need this later.

If your USB drive hasn’t been formatted yet, you might not see anything here. In that case, you should check my other tutorials on this website first.

Create a Mount Point

On Linux systems, you need to create a new folder to mount the drive to. Generally, we create it in /mnt or /media (read my article to learn more about the Linux file system overall).

Create the directory:
sudo mkdir /mnt/usb

Mount the USB Drive via Command Line

The mount command allows us to mount a device to a specific folder.
In my case, I want to mount /dev/sda1 to /mnt/usb.

The command syntax is this:
sudo mount <DEVICE> <FOLDER> -o <OPTIONS>

So in my case:
sudo mount /dev/sda1 /mnt/usb -o uid=pat,gid=pat

Adapt this value to your system (make sure to replace ‘pat’ in this command with your username).

Note: You can simply use “mount/dev/sda1 /mnt/usb” but adding the -o options for uid and gid allows your user to write files on the USB without having to use root.

Check if you can see your files, and create a new file as a test:
ls -latr /mnt/usb
touch /mnt/usb/test

We got no errors, and the files belong to my user, so I’m all ready to use it.

Unmounting a USB Drive via Command Line

When you’re all done, eject the USB drive by unmounting it.

To unmount a USB drive, use this command:
sudo umount /mnt/usb

(Don’t forget to replace /mnt/usb with the folder you chose as a mount point.)

You can now use USB drives on your Raspberry Pi. USB drives can then be used for multiple things, including:


🛠 This tutorial doesn't work anymore? Report the issue here, so that I can update it!

Something not working? Don't waste hours going in circles. Ask in the RaspberryTips Community and get help from people who've already figured it out. Get unstuck now.

Related Questions

There is no partition on my USB key, so I can’t mount it. What should I do?

The easiest way to create the first partition is to insert this key into a desktop OS (Windows or a Pi Desktop with GParted for example).

If you want to do this on a Raspberry Pi OS Lite instead, use the mkfs command: 
sudo mkfs -t fat32 /dev/sda1

More information here.

How do I auto-mount a USB drive on a minimal system?

Desktop systems will automatically mount your USB drive when you plug it in. But if you’re on a minimal system, you have to mount it manually every time you plug your drive in or boot your Raspberry Pi.

If you use your drive a lot, or even leave the drive plugged in all the time, manually mounting every time isn’t the best way. Instead, you can configure your Raspberry Pi to auto-mount it on boot.

You can auto-mount a USB by putting its UUID into the /etc/fstab file.

Get the USB’s UUID

When you format a disk, the system assigns an ID to the disk. We call this the UUID. It’s a unique identifier we can use to do something specific when you plug it into your Raspberry Pi.

To find the USB drive’s UUID, run this command:
sudo lsblk -f

You’ll get something like this:

  • Find the line corresponding to your drive name (/dev/sda1 for example).
  • Note its corresponding UUID.
  • Also note the filesystem format under the ‘FSTYPE’ column.

Create an Entry in /etc/fstab

/etc/fstab is a configuration file used to mount devices by default when your system starts.
If you save all the information needed here, it automatically mounts the USB to /mnt/usb.

Follow this procedure to add your USB drive to this file:

  • Open the fstab file:
    sudo nano /etc/fstab
  • Add this line at the end:
    UUID=0DEC-3E3A /mnt/usb vfat uid=pat,gid=pat 0 0
    • Replace the UUID with your drive’s identifier.
    • Replace the usernames with your own.
    • Replace vfat with your drive’s filesystem if needed. The format type could be vfat (FAT32), ext4 (Linux filesystem), or ntfs (Windows filesystem).
  • Save & exit (CTRL+X).
  • Reboot the system.

When you restart, your USB drive should automatically be available in the /mnt/usb folder. Raspberry Pi OS will mount it automatically at each boot. If you eject it and want to add it again after the boot, just run “mount -a” or “mount /mnt/usb.”

Specifying the UUID instead of the device name (/dev/sda1) allows us to be sure which drive it is. When you use multiple USB keys, for example, the first connection will be sda1, but you can’t know which one it is physically. With UUID, it’s unique, so you can be sure it’s the right one.

You can create a mount point in /etc/fstab for each device if you want (/mnt/big_drive, /mnt/kingston_key, etc.).

Can I create a script to manually mount my USB drive instead?

Yes, if you don’t want to use /etc/fstab to auto-mount the USB drive every time, you can create a script and only run it when you want to use the USB.

Create a Script

  • Create a new file:
    sudo nano /usr/local/bin/usb-connect.sh
  • Paste these lines:
    #!/bin/bash
    sudo mount /dev/sda1 /mnt/usb -o uid=pat,gid=pat
    echo "USB drive mounted successfully"

    This is a basic script; adapt the values and add what you want.
  • Save and exit (CTRL+O, CTRL+X).
  • Add execution permission:
    sudo chmod +x /usr/local/bin/usb-connect.sh

Create an Alias

Creating an alias allows you to use a short command to run the script instead of the complete command we saw earlier, or the full path to the script.

  • Edit your .bashrc file:
    nano ~/.bashrc
  • Add this line at the end of the file:
    alias usbmount='/usr/local/bin/usb-connect.sh'
  • Save and exit.
  • Close the terminal or end your SSH connection.

Easy Mount

Next time you come into the terminal and plug in your USB key, use:
usbmount

And then it’s done.
No more mount command to remember.

Whenever you’re ready, here are other ways I can help you:

Test Your Raspberry Pi Level (Free): Not sure why everything takes so long on your Raspberry Pi? Take this free 3-minute assessment and see what’s causing the problems.

The RaspberryTips Community: Need help or want to discuss your Raspberry Pi projects with others who actually get it? Join the RaspberryTips Community and get access to private forums, exclusive lessons, and direct help.

Master your Raspberry Pi in 30 days: If you are looking for the best tips to become an expert on Raspberry Pi, this book is for you. Learn useful Linux skills and practice multiple projects with step-by-step guides.

Master Python on Raspberry Pi: Create, understand, and improve any Python script for your Raspberry Pi. Learn the essentials step-by-step without losing time understanding useless concepts.

Master Linux Commands: Overwhelmed with Linux commands? This book is your essential guide to mastering the terminal. It includes practical tips, real-world examples, and a bonus cheat sheet to keep by your side.

You can also find all my recommendations for tools and hardware on this page.

Similar Posts

10 Comments

  1. Thank you Mr. Fromaget for sharing this great post! Do you know how I could automatically mount a camera device using this method or something similar? because Raspberry recognizes it as / run / user / 1000 / gvfs / gphoto2 and can only get its ID using ‘lsusb’ and other commands with ‘usb-devices’ in terminal, I even tried it with an android device, but it was recognized as / run / user / 1000 / gvfs / mtp .. any ideas? I need to use these devices when starting startup with automatic console login, because those devices are only recognized on desktop after using startx.

    1. Yes. If your disk is formatted correctly with enough permissions for your user, it should work.

  2. Thanks, I was able to get this working with 2 external drives & a headless pi.
    I found a problem in my situation : if either one of the USB drives is not connected at boot time, then the pi has some kind of error that stops it from joining the network (wifi)
    So I had to remove the SD card, edit the fstab & comment out the absent drive.
    I wonder if you have any ideas why this would be?

  3. minor mistake in “Create a small script”
    after hours for searching for the bug, i have realised that instead of:
    Paste these lines:
    #!/bin/bash
    sudo mount /dev/sda1 /mnt/usb -o uid=pi,gid=pi echo "USB drive mounted successfully"

    it should have been;
    Paste these lines:
    #!/bin/bash
    sudo mount /dev/sda1 /mnt/usb -o uid=pi,gid=pi
    echo "USB drive mounted successfully"

    please correct this, so that others wont run into the same mistake
    it was still a good way to learn bash scripting, maybe keep it

  4. I changed from defaults to uid=pi,gid=pi in order to make the mounted drive writable for the pi user and now my pi doesn’t start…

Leave a Reply

Community members only
Comments are reserved for RaspberryTips Community members. Join the community to ask questions, get help, and interact with other Raspberry Pi users.

Join the community  or  log in