Must-Know Linux Commands to Format, Mount & Use USB Drives
You’re probably used to plugging in a USB stick and seeing it pop up in your desktop interface. But on a server, it’s a different story: nothing happens. No icons, no notifications, nothing. That’s when you need to know a few simple commands, and I’ll show you exactly which ones in this article.
USB drives can be manually formatted and mounted on Linux by detecting the device with lsblk or fdisk. Drives can be partitioned with fdisk or parted and formatted with mkfs. Finally, they can be accessed with the mount command.
If you want to learn how to fully prepare, format, and mount a USB drive from start to finish, including adjusting permissions when needed, keep reading! I’ll walk you through the whole process with clear examples you can follow.
If you need help with 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 system. Click here to get it for free!
Detecting a USB Drive
The first step in using a USB on Linux is to detect it when it is plugged in. In Windows OS, when you plug in a USB, you get a notification and can access the USB from your file explorer.
Most modern Linux distributions, like Ubuntu with GNOME, also have similar functionality: When you plug in a USB, it is automatically mounted and shown in your left dock bar.
However, if you are running Linux without a desktop environment or if the USB is not formatted correctly, then this default functionality will not work. In that case, we must first understand how and where to find our USB device using the Linux terminal.
The fdisk command is the most common way of detecting hard disks and USBs connected to a Linux computer. You can run the following command to get a list of all storage devices connected to your computer:sudo fdisk -l
You might have to scroll and find your exact device from the output of this command. The cleanest way to identify your device in this list is to focus on its size and disk model and correlate these with the known values of the USB devices you have plugged in.
Another method to check all storage devices attached to your Linux computer is to use the lsblk command.
By default, all Linux devices are in the /dev/ directory. Storage devices, such as hard disks and USB drives, are represented with the prefix “sd,” which stands for SCSI Disk. The letter following “sd” serves as a unique identifier for each device (for example, a, b, or c).
Members get an ad-free version of every guide, plus exclusive project support.
Join the Community | Sign In
Therefore, another way to search for all storage devices connected to your Linux computer is to run this command:ls /dev/sd*
Note: Want to see how to manage USB drives by using commands only? I have a video lesson on this topic just for community members. Join here to watch, and get access to 30+ other lessons for Raspberry Pi along with many other benefits!
Grab This Cheat Sheet!
I've compiled the must-know commands in a simple PDF for quick reference.
Download now
Based on the screenshots above, our Linux computer has two connected storage devices: sda, our hard disk containing the operating system, and sdb, our USB drive. Also, sda is partitioned into sda1 and sda2, while sdb has no partitions.
So, to access our USB device, we need to partition it properly.
Preparing the USB – Partitioning
Having identified the unique identifier for our USB in the previous section, we are ready to prepare it for use.
The first step is to partition it. However, you can skip this step if your USB is already partitioned and you can see a partition like /dev/sdb1.
Two main tools are available for partitioning USB drives: fdisk and parted. fdisk is recommended for most beginners, while parted is more powerful but slightly more complex. You can choose only one and use that (you don’t need to use them both)
fdisk
To partition your USB drive using fdisk, follow these steps:
- Run the following command to start fdisk on your USB drive (replace /dev/sdX with your USB drive identified in the previous section):
sudo fdisk /dev/sdX
- Next, type n and press Enter.

- Enter the selections for your partition (you can use the default selections if you want to use the whole drive as a single USB partition).

- Finally, you can type w and press Enter to create the partition.

parted
Alternatively, if you are using parted, you can follow these steps:
- Run the parted command line utility using the command (replace /dev/sdX with your USB drive identified in the previous section):
sudo parted /dev/sdX
- Now you can create a new partition using the command:
mkpart primary ext4 0% 100%
- Finally, you can quit the command line utility by typing quit and pressing Enter.
You can verify that your partition has been created by running the following command:sudo fdisk -l
As you can see, our new partition has been created and labelled /dev/sdb1. We are now ready to format our USB.
Quick note: If you find it hard to remember all these commands, I’ve put them all on a one-page cheat sheet. You can download it for free here so you have it handy whenever you're working on a project.
Formatting the USB
After creating a partition on our USB drive, the next step is to format it with the right file system. A file system organizes and manages files on a storage device, defining how data is stored and accessed.
Grab This Cheat Sheet!
I've compiled the must-know commands in a simple PDF for quick reference.
Download now
Note: Formatting a USB will remove all data stored on it. If you are trying to mount and read data that already exists on your USB, you should skip this step and go directly to the Mounting USB section.
The primary tool for formatting a file system is the `mkfs` command. However, before formatting, we must determine which file system we want for our partition. The three central file systems commonly used are NTFS, ext4, and VFAT.
| File System Type | VFAT (Virtual File Allocation Table) | NTFS (New Technology File System) | EXT (Extended File System) |
| Use Case | Ideal for small storage devices (USB drives, memory cards) and legacy systems. | Linux has limited support in Windows via third-party drivers. | Preferred for Linux filesystems, scalable for servers and desktops. |
| Supported Operating Systems | Windows, macOS, Linux, various embedded systems. | Windows, limited read-only support in macOS and Linux. | 16 TB (with 64kb clusters) |
| Max File Size | 4 GB (FAT32) | 16 TB (with 64kB clusters) | 16 GB to 16 TB (EXT4) |
| Security Features | Basic file attributes. | File permissions, encryption, disk quotas, and journaling. | File permissions, journaling (EXT3/4). |
If you want to create a USB partition for transferring data between multiple machines that run different operating systems, I recommend using VFAT partitioning. However, choose a partition type based on your specific use case.
VFAT
To create a partition using the VFAT file system, you can use the following command:sudo mkfs.vfat /dev/sdX1
EXT4
To create a partition using the ext4 file system, you can use the following command:sudo mkfs.ext4 /dev/sdX1
You might also like: Tired of Raspberry Pi OS? Level up with these top-rated systems.
NTFS
To create a partition using the NTFS file system, you can use the following command:sudo mkfs.ntfs /dev/sdX1
Once formatted, you can confirm the file system of your partition using the command:sudo lsblk -f
Having properly partitioned and formatted our USB drive, we are now ready to mount it and transfer data.
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.
Mounting & Unmounting USB
If your USB is formatted correctly, accessing the data on it typically involves several steps:
- Mount the USB drive.
- Copy or move the data from the USB to your desired location.
- Unmount the USB before removing it from your device.
Let’s go over all these steps with the commands you can use for each.
Mounting and Accessing the Data
Grab This Cheat Sheet!
I've compiled the must-know commands in a simple PDF for quick reference.
Download now
Mounting the device is straightforward. All you need is the name of the partition and the desired mount point. Typically, USB drives are mounted in Linux at /media/<user>/<mount_point>.
However, when manually mounting a partition, /mnt/ location is usually used instead.
In the end, you can always use whichever mount point you prefer.
To mount our USB, we can use the following command:sudo mount /dev/sdx1 /mnt -o rw,uid=$(id -u),gid=$(id -g)
You can now verify that your USB has been mounted by using the command:lsblk
Now you can navigate to /mnt/ in a file browser to access the USB:
Alternatively, you can use command line tools like cd, ls, mv, and cp to move and view files to and from the USB.
For more details, check out our full guide to the mount command.
Syncing and Unmounting USB
Before physically removing the USB, it is recommended to sync and unmount the partition after completing all file operations, such as copying and moving items, to avoid data corruption due to unsafe removal.
You might also like: Yes, you can access your Pi from anywhere. Here's how.
You can sync and unmount your partition using the command:sync /mnt && sudo umount /mnt
This is analogous to ejecting the USB on Windows or macOS before physically removing the drive from your computer.
Stuck on this project? Ask me or other Pi users in the RaspberryTips Community. We help each other out and you'll get answers quick. Join and fix it together.
Adjusting Permissions (If Needed)
Sometimes, after mounting a USB drive, you might find that you can’t create, modify, or delete files. This usually happens because the root user owns the USB, especially if you mounted it manually or formatted it with a Linux-native file system like ext4.
Grab This Cheat Sheet!
I've compiled the must-know commands in a simple PDF for quick reference.
Download now
Linux uses a permission system that controls which users can access or modify files. If you don’t have the correct permissions for the USB mount point, you’ll need to change them using chown (change owner) and chmod (change access rights.)
To look at the present ownership and permissions for a folder, you can run this command:ls / -al
There are three important fields here: the first column is the file type + permission string (drwxr-xr-x), the third and fourth columns are the user owner (root), and the group owner (root).
All Linux files and folders belong to a user and a group. This guide will help you understand file permissions and how they can generally be managed in Linux.
To change ownership of the USB to your user account, you can run:sudo chown <User Name>:<Group Name> /your/mount/point
This command gives your current user ownership of the /mnt directory (where we mounted the USB earlier).
If you also want to adjust permissions to ensure read/write access, you can use:sudo chmod u+rwx /your/mount/point![]()
This allows the owner (you) to read, write, and execute within that directory.
Tip: If your USB is formatted as FAT or NTFS, permissions are handled differently since these file systems don’t support Linux-style ownership. In that case, you can add the uid and gid options directly in the mount command:sudo mount /dev/sdX1 /mnt -o uid=$(id -u),gid=$(id -g)
Once you’ve adjusted permissions, you can copy, create, or delete files on the USB as needed.
And that’s it! Using just the terminal, you can detect, partition, format, mount, and use USB drives on any Linux system. Once you get the hang of it, manually managing USB drives is not that complicated.
You might also like: Turn your Raspberry Pi into a money-making machine
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.
You can also find all my recommendations for tools and hardware on this page.
