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.

First, you must properly identify the device to use (name, partition and file system). Then it can be formatted with a tool like Gparted. After that, Raspberry Pi OS should mount the USB drive automatically (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.

If you are looking to quickly progress on Raspberry Pi, you can check out my e-book here. It’s a 30-day challenge, where you learn one new thing every day until you become a Raspberry Pi expert. The first third of the book teaches you the basics, but the following chapters include projects you can try on your own.

File system theory

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 an SD card. It’s a convention on how files are stored on the disk.

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.

Partitions

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

On Windows, you can have C: and D: for example. On Linux, you generally have a /boot, / and swap partition. Here is a screenshot of my computer partitions to give you an idea:

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

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 an 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 partition). But you can’t access files directly here, as it’s a virtual drive.

Before using it, you need tomount” the drive in another location.
It can be anywhere, but most of the time the default mounting points are kept 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.

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.

Format the USB drive from the Raspberry Pi

There isn’t really a right order in which way to show you the 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 environments (Desktop or Lite).

Format USB drives from Desktop

Using the desktop interface is the easiest way to format USB drives.
You have a tool named “gparted” that does all the work for you:

  • If needed, install “gparted” from the main menu > Preferences > Add / Remove software.
    I already have it on Raspberry Pi OS Full, but I don’t thing it’s installed by default on other versions.
    Another option would be to prepare the USB drive on your other computer, for example I have an article on this website explaining how to create partitions on Ubuntu. Feel free to read it and follow the steps on your computer if you prefer.
    • Once Gparted installed, 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).

    I have a complete guide about Gparted on Raspberry Pi, click on the link to learn more about it.

    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, doing the same thing on Raspberry Pi OS Lite isn’t as straightforward.

    Find the virtual drive name

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

    Get My Commands Cheat Sheet!
    Grab your free PDF file with all the commands you need to know on Raspberry Pi!
    • 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.

    Are you a bit lost in the Linux command line? Check this article first, for the most important commands to remember, and a free downloadable cheat sheet so you can 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:

    • For this example, 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 formats)
      • Create a new partition: n
        You can keep the default values for a single partition.
        Just press Enter after each question.
      • 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 syntax is the following:
      sudo mkfs.FILETYPE DEVICE
      Just replace FILETYPE and DEVICE with 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!

    Mount your USB drive

    Now that the USB drive is ready (formatted with at least one partition), let’s see how to mount it on your Raspberry Pi :).

    Mount a USB drive on the Desktop

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

    • Plug your device into a free USB port.
      If you have a recent model, use the blue ports if possible (faster speed).
    • 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 later.

    Note: I’m doing this tutorial with Raspberry Pi OS Full, if you have any issues 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 in 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 did it in the format part and remember the device name.

    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, assigned 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 standard users 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

    Before unplugging 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 in 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

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

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

    If you are looking for exclusive tutorials, I post a new course each month, available for premium members only. Join the community to get access to all of them right now!

    Conclusion

    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 manage 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:

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

    Additional 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 multiple projects with step-by-step guides.
    Download the e-book.

    VIP Community
    If you just want to hang out with me and other Raspberry Pi fans, you can also join the community. I share exclusive tutorials and behind-the-scenes content there. Premium members can also visit the website without ads.
    More details here.

    Need help building 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.

    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