How to format and mount a USB drive on Raspberry Pi?


Mounting and formatting USB drives on Linux isn’t the easiest thing to do. This is especially true if you are on a console-only operating system, like Raspberry Pi OS Lite.
Today, I’ll show you how to format and mount a USB drive on your Raspberry Pi, whether in terminal or graphic mode. It’s a 3-step process:

The first step is to properly identify the device to use (name, partition and file system). Then it can be formatted with a tool like Gparted, and Raspberry Pi OS should mount the USB drive automatically after that (on Desktop versions).

In this guide, I’ll explain everything you need to know, so you don’t need any prior knowledge.
I’ll start with a file system introduction, and then walk you through the 3 steps above.

By the way, if you are looking for an external drive, I highly recommend this one from SanDisk. It’s a very affordable SSD, so you can use it for backups or Retropie ROMs, but you can also install your system on it. It’s the perfect companion for your Raspberry Pi.

File system theory

x
Best retro-gaming solution
Download the Pi Glossary!
If you are lost in all these new words and abbreviations, request my free Raspberry Pi glossary here (PDF format)!

Let’s start with a short introduction about everything you need to understand before going further.

File systems

Basically, file systems are the way your files will be saved on the device.
It doesn’t matter if it’s a USB drive, a hard disk or a SD card.
It’s a convention on how files are stored on the disk if you want.

Each operating system has its favorite file system, but Linux, and so Raspberry Pi OS, can read and write any file system.
Sometimes it may require an additional package, but it is possible.

Here are the most used file systems right now:

  • Linux: EXT3 and EXT4
  • Windows: NTFS and FAT32
  • Apple: APFS, HFS+

Each file system has its own advantages and disadvantages, but this isn’t the focus of today’s post.
Most of the time you will use EXT4 to keep your USB drive on Linux / Raspberry Pi OS, and one of the others if you want to make it readable on another platform.

If you need help getting started on Raspberry Pi, I have an entire course to guide you through your first steps. I’ll help you use the perfect hardware, plug everything in and install your first system. You’ll also do your first project with me, just to make sure you are ready for the next level. Get all the information on this page if you are interested.

Raspberry Pi Bootcamp
Sale: 10% off today.
Take it to the next level.
I'm here to help you get started on Raspberry Pi.
Learn all the skills you need in the correct order.

Partitions

Another thing to understand is “partition”.
As the name says, a partition is a specific part on the disk.

On Windows, you can have C: and D: for example.
On Linux, you generally have a /boot, / and swap partition.

Most of the time you will only have one USB key.
But it’s something to know if you try to read a hard drive from an old computer for example.
You can also have one partition for Linux and another for Windows on the same USB drive (FAT32 and EXT4 for example).

Devices management on Linux

On a desktop operating system, managing internal or external hard drive is easy.
Everything is either plug and play, or you have a tool to do all the complicated stuff for you.

But without a desktop, you need to know how it works in the background:).
When you plug a device into your Raspberry Pi, the system will assign it to a virtual disk, in the /dev location, for example /dev/sdb.
The partitions of this disk will be accessible on /dev/sdb1, /dev/sdb2, etc. (for a USB drive you probably have only one).

But you can’t access files directly here, as it’s a virtual drive.
Before to use it, you need to mount the drive in another location.
Most of the time it’s in /media : /media/usb for example.

In this guide I’ll show you how to do this, but you need to understand how it works before trying something.

Format the USB drive from the Raspberry Pi

There isn’t really a right order in which way to show you format and mount.
So, if your drive is correctly formatted, and you just want to mount it on the Raspberry Pi, you can skip this part and go directly to the mounting step.

If you are still here, I’ll show you how to format a USB drive from both environment (Desktop or Lite).

Format USB drives from the Desktop

The graphic way is the easiest way to deal with this.
You have a tool named “gparted” that do all the work for you:

  • If needed, install “gparted” from the main menu > Preferences > Add / Remove software.
    I have it on Raspberry Pi OS Full, but iI don’t know if it is available on Desktop.
  • Then, open the main menu again, and go to System tools > GParted.
  • Enter your password, and you’ll get a window like this:
    gparted partition manager
  • Then right-click on the partition and choose “Format to” to select the file system you want to use.
  • Click on the green tick on top to confirm and apply changes.

That’s it, you now know how to format a USB drive on Raspberry Pi OS Desktop :).
If you don’t already have a partition on your drive, it’s the same process (as simple as right-click > new).

There are many great apps on Raspberry Pi OS with Desktop that can make your life easier. Check this article if you want to discover the most useful you should install on your Raspberry Pi.

Format USB drives with a command line

As usual, the Raspberry Pi OS Lite way is less straightforward :).

Find the virtual drive name

Before doing anything else, you need to find the device name.
Follow this steps to find it:

  • We’ll use “fdisk” to list the current devices on the Raspberry Pi.
  • Use the command below:
    sudo fdisk -l
  • A list will appear, and most of the time your USB drive is the last item, so it’s easy to read.
    In my case I can see this:
    fdisk raspberry pi
  • Take note of the partition name (under Device on the last line).
    If no partition, just remember the Disk name (/dev/sda here).

We can now move to the format part.

A bit lost in the Linux command line? Check this article first, which will give you the most important commands to remember, and a free cheat sheet you can download to have the commands at your fingertips.

Format or reformat the entire disk

If you need to create a partition, or want to rebuild a new partition table, you have to use fdisk again.

Here are the steps to follow to create a new partition:

  • In this case, I have an empty USB key, without partition (fdisk -l):

    So I can’t mount or format it directly, I first need to create one.
  • Start fdisk:
    sudo fdisk /dev/sda
  • Use the following commands shortcuts in fdisk:
    • Create a new partition table : g (for GPT, use help for other format)
    • Create a new partition : n
      You can keep the default values for a single partition.
    • Confirm with Y to remove the signature.
    • And finally write and exit fdisk: w
  • When you run fdisk -l again, you’ll see a new partition.
    You can follow the next part to format it the way you want.

If you are using a larger external drive (like the one I recommend), you can repeat this process to create several partitions. For example, you can use different file systems, or have one for each specific application.

Format the partition

If you already have a partition on the drive, and just want to erase it or change the file system type, here is what you need to do:

  • The command format is easy, the syntax is the following:
    sudo mkfs.FILETYPE DEVICE
    Just replace FILETYPE and DEVICE by what you want
  • Here are the most common examples:
    sudo mkfs.ext4 /dev/sda1
    sudo mkfs.vfat /dev/sda1
    sudo mkfs.ntfs /dev/sda1

    That’s all!

A bit lost in the Linux command line? Check this article first, which will give you the most important commands to remember, and a free cheat sheet you can download to have the commands at your fingertips.

Mount your USB drive

Let’s now learn how to mount a USB drive on your Raspberry Pi :).

Master your Raspberry Pi in 30 days
Sale: 10% off today.
Download the eBook.
Uncover the secrets of the Raspberry Pi in a 30 days challenge.
Learn useful Linux skills and practice multiples projects.

Mount a USB drive on Desktop

On Raspberry Pi OS Desktop (or Full), it’s straightforward.
The operating system manages everything for you :).

  • Plug your device to a free USB port.
  • Wait a few seconds, a window pops up asking if you want to open the file manager to access it:
    insert usb drive raspberry pi
    The device is already mounted.
  • Click “OK” to open the file manager.
    An icon is also available on the desktop for you to access it later.

Note: I’m doing this tutorial with Raspberry Pi OS Full, if you have any issue with Raspberry Pi OS Desktop, check the prerequisites in the following part.

Mount a USB drive with a command

On a Lite version, it isn’t the same process.
You can plug your drive, but nothing happens :).
There are a few steps to follow in order to access it.

Find the virtual drive name

Note: skip this if you already learn how to do it in the format part 🙂.

Before doing anything else, you need to find the current name of the drive.
Once you plug it in, Raspbian will detect the drive and partitions, and assign a name to it.
Follow this procedure to find it:

  • We’ll use “fdisk” to list the current devices on the Raspberry Pi.
  • Use the command below:
    sudo fdisk -l
  • A list will appear, and most of the time your USB drive is the last item, so it’s easy to read.
    In my case, I have this:
    fdisk raspberry pi
  • You have two things to note (squared in red):
    • The partition name given by Raspberry Pi OS: /dev/sda1 here.
    • The file system type: FAT32 here.
  • Once you know this, you have everything you need to move forward.

If you are not sure which one is your drive, the disk size may help you select the correct one (7.5G in my case).
My SD card is 32G and is always identified as /dev/mmcblk0.

Mount the drive

Now that you know the device and partition name, use the following procedure to mount it:

  • Create a new folder in /media.
    We’ll mount the USB drive in this folder, but you need to create it before:
    sudo mkdir /media/usb
  • Mount the drive to this place with this simple command:
    sudo mount /dev/sda1 /media/usb -o umask=000
    Don’t forget to replace parameters if needed.
    The syntax is “mount [PARTITION] [FOLDER]”.
    The -o allows you to add extra options.
    Most of the time you will need to add the umask option to allow the “pi” user to write on the device.

There are many other options you can use.
Check the “man mount” command or the online help here to learn more about this.

Unmount the drive

To update the drive, you have to use “umount” like this:
sudo umount /media/usb

It’s the correct way to unplug your device, to be sure everything will be saved.

Automatic mount on boot

As you’ll quickly see, you need to use the mount command each time you reboot your Raspberry Pi.

But there is something you can do to mount it automatically on boot:

  • Get the partition id of your device:
    sudo blkid
  • You’ll get something like this:

    The PARTUUID is the value square in red, on the /dev/sdb1 line.
  • Open the /etc/fstab file:
    sudo nano /etc/fstab
  • Paste this line, or something similar depending on your values:
    PARTUUID=b951dfde-01 /media/usb ntfs defaults,umask=000 0 0
  • Fstab is a file to store drives and options related to it.
    And if the drive is plugged on boot, it will mount it directly.
  • Save and exit (CTRL+O, CTRL+X).

Now you can reboot your system and check that everything works fine.

Video

Still a bit lost in this whole process? I created a video for you, it’ll probably be clearer after watching this:

Conclusion

Get My Cheat Sheet!
Grab your free PDF file with all the commands you need to know on Raspberry Pi!

That’s it, you know everything you need to manage USB drives on your Raspberry Pi.
And it’s the same commands on Linux, to manager any disks (external or internal), so great work!

Do you have other tips to share to manage USB drives on Raspberry Pi?

Related tutorials that might be useful for you:

If you have any comment, suggestion or just want to chat with us about this tutorial,
you can post your messages in the community on Patreon. See you there!

Raspberry Pi Resources

Not sure where to start?
Understand everything about the Raspberry Pi, stop searching for help all the time, and finally enjoy completing your projects.
Watch the Raspberry Pi Bootcamp course now

Master your Raspberry Pi in 30 days
Don’t want the basic stuff only? 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 multiples projects with step-by-step guides.
Download the e-book

VIP Community
If you just want to hang out with me and show your support, you can also join the Patreon community. I share behind-the-scenes content there and give you early access to my content. You’ll also get a shoutout when you join.
More details here

Need help to build something with Python?
Create, understand and improve any Python script for your Raspberry Pi.
Learn the essentials, step-by-step, without losing time understanding useless concepts.
Get the e-book now

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


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


Patrick Fromaget

I'm the lead author and owner of RaspberryTips.com. My goal is to help you with your Raspberry Pi problems using detailed guides and tutorials. In real life, I'm a Linux system administrator with a web developer experience.

Recent Posts

Master your Raspberry Pi in 30 days

Download this eBook and discover:
1. Secrets from my 20-years Linux experience 2. Many step-by-step projects for your Raspberry Pi 3. How to save time by learning the right way
DOWNLOAD YOUR COPY
10% OFF FOR A LIMITED TIME WITH THIS LINK
DON'T MISS IT!
close-link
Master your Raspberry Pi - 10% off