How to Format USB Drives and SD Cards on Linux

By 

Updated on

9 min read

Linux Format USB Drive and SD Card

Before you can use a new USB drive or SD card on Linux, it may need to be partitioned and formatted. Most removable drives come preformatted with FAT32 and work out of the box, but you may need to reformat when switching filesystem types, fixing a corrupted drive, or securely erasing data.

This guide explains how to format a USB drive or SD card on Linux using the parted and mkfs command-line utilities.

Quick Reference

TaskCommand
Identify the devicelsblk
Unmount the devicesudo umount /dev/sdb1
Create MBR partition tablesudo parted /dev/sdb --script -- mklabel msdos
Create GPT partition tablesudo parted /dev/sdb --script -- mklabel gpt
Create a partition (full disk)sudo parted /dev/sdb --script -- mkpart primary fat32 1MiB 100%
Format as FAT32sudo mkfs.vfat -F32 /dev/sdb1
Format as exFATsudo mkfs.exfat /dev/sdb1
Format as EXT4sudo mkfs.ext4 -F /dev/sdb1
Format as NTFSsudo mkfs.ntfs -f /dev/sdb1
Verify partition tablesudo parted /dev/sdb --script print
Warning
Formatting erases all existing data on the drive. If you have important files on the USB drive or SD card, back them up before proceeding.

Prerequisites

The parted utility is pre-installed on most Linux distributions. Verify it is available by running:

Terminal
parted --version

If parted is not installed, install it using your distribution package manager.

On Ubuntu, Debian, and Derivatives:

Terminal
sudo apt update && sudo apt install parted

On Fedora, RHEL, and Derivatives:

Terminal
sudo dnf install parted

Identifying the Device

Insert the USB drive or SD card into your Linux machine and identify the device name using the lsblk command:

Terminal
lsblk

The output lists all available block devices:

output
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
sda      8:0    0 238.5G  0 disk
├─sda1   8:1    0   512M  0 part /boot/efi
├─sda2   8:2    0   237G  0 part /
└─sda3   8:3    0     1G  0 part [SWAP]
sdb      8:16   1  14.4G  0 disk
└─sdb1   8:17   1  14.4G  0 part /media/data

In this example, the USB device is /dev/sdb. The device name varies depending on your system and how many drives are connected.

Before running any formatting command, confirm the device by matching its size and model in the lsblk output.

You can also use the dmesg command to find the device name. After plugging in the drive, run:

Terminal
dmesg | tail -10

The output shows the device name assigned by the kernel:

output
[  +0.000232] sd 1:0:0:0: [sdb] 30218842 512-byte logical blocks: (15.5 GB/14.4 GiB)
Warning
Double-check the device name before proceeding. Formatting the wrong device (such as your system disk) will result in data loss.

Unmounting the Device

If the drive is currently mounted, you must unmount it before formatting. Formatting a mounted device can corrupt data.

Check if any partitions on the device are mounted:

Terminal
mount | grep sdb

If the output shows a mount point, unmount it:

Terminal
sudo umount /dev/sdb1

If the device has multiple partitions, unmount each one.

Choosing a Filesystem

Before formatting, choose the filesystem that fits your use case:

FilesystemMax File SizeCross-PlatformBest For
FAT324 GBLinux, macOS, WindowsSmall USB drives, boot media, maximum compatibility
exFAT16 EBLinux, macOS, WindowsLarge USB drives, files over 4 GB, cross-platform use
EXT416 TBLinux onlyLinux-only drives, external storage for Linux systems
NTFS16 TBWindows, Linux (read/write)Drives shared primarily with Windows

Formatting with FAT32

FAT32 is the most widely compatible filesystem. Use it for drives that need to work across all operating systems. Note that FAT32 has a 4 GB file size limit; if you need to store files larger than 4 GB, use exFAT instead.

Create an MBR partition table:

Terminal
sudo parted /dev/sdb --script -- mklabel msdos

Create a FAT32 partition that uses the entire disk:

Terminal
sudo parted /dev/sdb --script -- mkpart primary fat32 1MiB 100%

Format the partition as FAT32:

Terminal
sudo mkfs.vfat -F32 /dev/sdb1

Verify the partition table:

Terminal
sudo parted /dev/sdb --script print
output
Model: Kingston DataTraveler 3.0 (scsi)
Disk /dev/sdb: 15.5GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  15.5GB  15.5GB  primary  fat32        lba

Formatting with exFAT

exFAT is the recommended filesystem for USB drives and SD cards that need to work on Linux, macOS, and Windows without the 4 GB file size limitation of FAT32.

First, install the exFAT utilities if they are not already available:

On Ubuntu, Debian, and Derivatives:

Terminal
sudo apt install exfatprogs

On Fedora, RHEL, and Derivatives:

Terminal
sudo dnf install exfatprogs

Create an MBR partition table:

Terminal
sudo parted /dev/sdb --script -- mklabel msdos

Create a partition that uses the entire disk:

Terminal
sudo parted /dev/sdb --script -- mkpart primary 1MiB 100%

Format the partition as exFAT:

Terminal
sudo mkfs.exfat /dev/sdb1

Formatting with EXT4

Use EXT4 if the drive will only be used on Linux systems. EXT4 supports Linux file permissions, large files, and journaling.

Create a GPT partition table:

Terminal
sudo parted /dev/sdb --script -- mklabel gpt

Create an EXT4 partition that uses the entire disk:

Terminal
sudo parted /dev/sdb --script -- mkpart primary ext4 0% 100%

Format the partition as EXT4:

Terminal
sudo mkfs.ext4 -F /dev/sdb1

Verify the partition table:

Terminal
sudo parted /dev/sdb --script print
output
Model: Kingston DataTraveler 3.0 (scsi)
Disk /dev/sdb: 15.5GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  15.5GB  15.5GB  ext4         primary

Formatting with NTFS

Use NTFS for drives that will be shared primarily with Windows systems. Linux supports NTFS read and write through the ntfs-3g driver, which is included on most distributions.

Install the NTFS utilities if needed:

On Ubuntu, Debian, and Derivatives:

Terminal
sudo apt install ntfs-3g

Create an MBR partition table:

Terminal
sudo parted /dev/sdb --script -- mklabel msdos

Create a partition that uses the entire disk:

Terminal
sudo parted /dev/sdb --script -- mkpart primary ntfs 1MiB 100%

Format the partition as NTFS. The -f flag performs a quick format:

Terminal
sudo mkfs.ntfs -f /dev/sdb1

Format Using GNOME Disks

If you prefer a graphical tool, GNOME Disks is the simplest option and comes pre-installed on Ubuntu, Fedora, and most GNOME-based desktops. If it is missing, install it with sudo apt install gnome-disk-utility on Ubuntu and Debian, or sudo dnf install gnome-disk-utility on Fedora and RHEL.

Open the Disks application and select your USB drive or SD card from the list on the left. Confirm you picked the correct device by checking its size and model, then click the stop (square) button to unmount any mounted partitions.

To format a single partition, select it and open the partition menu (the gear icon), then choose Format Partition. Enter a volume name, pick the filesystem (FAT for cross-platform use, Ext4 for Linux only, or NTFS for Windows), and click Format. To wipe the whole drive and recreate the partition table, open the drive menu (the three-dot icon in the top-right corner) and choose Format Disk instead.

GNOME Disks Format Volume dialog with the filesystem type set to FAT for cross-platform use

Securely Wiping the Drive (Optional)

If you are giving the drive away or disposing of it, you can overwrite all data so it cannot be recovered by data recovery tools. This step is not necessary for normal reformatting.

Overwrite the entire drive with zeros:

Terminal
sudo dd if=/dev/zero of=/dev/sdb bs=4096 status=progress

The process takes some time depending on the size of the drive. When complete, dd prints a “No space left on device” message, which is expected:

output
15455776768 bytes (15 GB, 14 GiB) copied, 780 s, 19.8 MB/s
dd: error writing '/dev/sdb': No space left on device

After wiping, proceed with creating a new partition table and formatting as described above.

Troubleshooting

“Device or resource busy” when formatting
The device is still mounted. Unmount all partitions on the device with sudo umount /dev/sdb* before formatting.

“Permission denied”
Formatting requires root privileges. Make sure you are using sudo with all parted, mkfs, and dd commands.

Drive is not detected after inserting
Try a different USB port. Run dmesg | tail -20 to check if the kernel recognized the device. If no output appears, the drive or port may be faulty.

“Unable to satisfy all constraints on the partition”
The alignment or size values in the mkpart command conflict. Use 1MiB as the start value and 100% as the end value to let parted handle alignment automatically.

Formatted drive is read-only
Some SD cards have a physical write-protect switch on the side. Check that the switch is in the unlocked position. For USB drives, check dmesg output for write protection messages.

FAT32 does not allow files larger than 4 GB
FAT32 has a 4 GB file size limit. Format the drive as exFAT instead, which supports files of virtually any size and is compatible with Linux, macOS, and Windows.

FAQ

Which filesystem should I use for a USB drive?
Use exFAT if you need cross-platform compatibility with files over 4 GB. Use FAT32 for maximum compatibility with older devices. Use EXT4 if the drive will only be used on Linux systems.

Do I need to create a partition table, or can I format the raw device?
You can technically format a raw device without a partition table (sudo mkfs.ext4 /dev/sdb), but creating a partition table first is recommended. Some operating systems and devices do not recognize drives without a partition table.

What is the difference between MBR and GPT partition tables?
MBR (Master Boot Record) is the older standard, supports up to 4 primary partitions, and works with drives up to 2 TB. GPT (GUID Partition Table) supports many more partitions and drives larger than 2 TB. Use MBR when you need broad compatibility with older devices and firmware. Use GPT for modern systems and larger drives.

How do I format a drive using a graphical tool?
You can use either GNOME Disks or GParted. In GNOME Disks, select the drive, unmount the partition, open the partition menu, choose Format Partition, pick the filesystem, and confirm. In GParted, select the drive from the dropdown menu, create a new partition table if needed, add a partition with the desired filesystem, and click Apply.

Can I recover data after formatting?
A standard format only removes the filesystem metadata, not the actual data. Tools like testdisk or photorec may recover files. Overwriting with dd reduces recoverability, but on flash-based media (USB drives, SD cards, SSDs) secure erasure is not always guaranteed because of wear leveling.

Conclusion

To format a USB drive or SD card on Linux, identify the device with lsblk, unmount it, create a partition table with parted, and format the partition with mkfs. Choose FAT32 or exFAT for cross-platform use and EXT4 for Linux-only drives.

Linuxize Weekly Newsletter

A quick weekly roundup of new tutorials, news, and tips.

About the authors

Dejan Panovski

Dejan Panovski

Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.

View author page