How to Format USB Drives and SD Cards on Linux

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
For a printable quick reference, see the parted cheatsheet .
| Task | Command |
|---|---|
| Identify the device | lsblk |
| Unmount the device | sudo umount /dev/sdb1 |
| Create MBR partition table | sudo parted /dev/sdb --script -- mklabel msdos |
| Create GPT partition table | sudo parted /dev/sdb --script -- mklabel gpt |
| Create a partition (full disk) | sudo parted /dev/sdb --script -- mkpart primary fat32 1MiB 100% |
| Format as FAT32 | sudo mkfs.vfat -F32 /dev/sdb1 |
| Format as exFAT | sudo mkfs.exfat /dev/sdb1 |
| Format as EXT4 | sudo mkfs.ext4 -F /dev/sdb1 |
| Format as NTFS | sudo mkfs.ntfs -f /dev/sdb1 |
| Verify partition table | sudo parted /dev/sdb --script print |
Prerequisites
The parted utility is pre-installed on most Linux distributions. Verify it is available by running:
parted --versionIf parted is not installed, install it using your distribution package manager.
On Ubuntu, Debian, and Derivatives:
sudo apt update && sudo apt install partedOn Fedora, RHEL, and Derivatives:
sudo dnf install partedIdentifying the Device
Insert the USB drive or SD card into your Linux machine and identify the device name using the lsblk command:
lsblkThe output lists all available block devices:
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/dataIn this example, the USB device is /dev/sdb. The device name varies depending on your system and how many drives are connected. If the relationship between disks, partitions, and filesystems is unclear, our guide on block devices, partitions, and filesystems
covers the terminology used below.
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:
dmesg | tail -10The output shows the device name assigned by the kernel:
[ +0.000232] sd 1:0:0:0: [sdb] 30218842 512-byte logical blocks: (15.5 GB/14.4 GiB)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:
mount | grep sdbIf the output shows a mount point, unmount it:
sudo umount /dev/sdb1If the device has multiple partitions, unmount each one.
Choosing a Filesystem
Before formatting, choose the filesystem that fits your use case:
| Filesystem | Max File Size | Cross-Platform | Best For |
|---|---|---|---|
| FAT32 | 4 GB | Linux, macOS, Windows | Small USB drives, boot media, maximum compatibility |
| exFAT | 16 EB | Linux, macOS, Windows | Large USB drives, files over 4 GB, cross-platform use |
| EXT4 | 16 TB | Linux only | Linux-only drives, external storage for Linux systems |
| NTFS | 16 TB | Windows, 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:
sudo parted /dev/sdb --script -- mklabel msdosCreate a FAT32 partition that uses the entire disk:
sudo parted /dev/sdb --script -- mkpart primary fat32 1MiB 100%Format the partition as FAT32:
sudo mkfs.vfat -F32 /dev/sdb1Verify the partition table:
sudo parted /dev/sdb --script printModel: 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 lbaFormatting 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:
sudo apt install exfatprogsOn Fedora, RHEL, and Derivatives:
sudo dnf install exfatprogsCreate an MBR partition table:
sudo parted /dev/sdb --script -- mklabel msdosCreate a partition that uses the entire disk. The ntfs hint sets the MBR partition type to 0x07, which exFAT also uses for compatibility with Windows. It does not create an NTFS filesystem:
sudo parted /dev/sdb --script -- mkpart primary ntfs 1MiB 100%Format the partition as exFAT:
sudo mkfs.exfat /dev/sdb1Formatting 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:
sudo parted /dev/sdb --script -- mklabel gptCreate an EXT4 partition that uses the entire disk:
sudo parted /dev/sdb --script -- mkpart primary ext4 0% 100%Format the partition as EXT4:
sudo mkfs.ext4 -F /dev/sdb1Verify the partition table:
sudo parted /dev/sdb --script printModel: 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 primaryFormatting with NTFS
Use NTFS for drives that will be shared primarily with Windows systems. Linux can read and write NTFS through the in-kernel ntfs3 driver, introduced in kernel 5.15, or the ntfs-3g userspace driver. Which driver is available and used depends on your distribution and kernel configuration. Creating the filesystem is a separate matter, because mkfs.ntfs comes from the NTFS-3G userspace tools, which are not always present by default.
Install the NTFS utilities if needed:
On Ubuntu, Debian, and Derivatives:
sudo apt install ntfs-3gOn Fedora, RHEL, and Derivatives:
On RHEL and its derivatives, enable EPEL
before installing ntfsprogs.
sudo dnf install ntfsprogsCreate an MBR partition table:
sudo parted /dev/sdb --script -- mklabel msdosCreate a partition that uses the entire disk:
sudo parted /dev/sdb --script -- mkpart primary ntfs 1MiB 100%Format the partition as NTFS. The -f flag performs a quick format:
sudo mkfs.ntfs -f /dev/sdb1Format 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.

Format Using GParted
GParted is the other common graphical option, and it is the better choice when you need to change the partition layout rather than only format an existing partition. Install it with sudo apt install gparted on Ubuntu and Debian, or sudo dnf install gparted on Fedora. On RHEL 8/9 and their derivatives, enable EPEL
before running the dnf command.
Launch GParted and select the USB drive or SD card from the device dropdown in the top-right corner. Check the size and device path before continuing, because GParted opens on the first disk it finds, which is usually your system drive. If a partition on the device is mounted, right-click it and choose Unmount.
To start from a clean drive, open the Device menu and choose Create Partition Table, then pick msdos for broad compatibility or gpt for drives larger than 2 TB. Creating a new partition table removes all existing partitions on the drive. Click Apply in that dialog to write the new partition table immediately.
Then right-click the unallocated space, choose New, select the filesystem from the File system dropdown, and click Add. Creating and formatting the new partition is queued, so these operations run when you click the green check mark to apply them.
Securely Wiping the Drive (Optional)
If you are giving the drive away or disposing of it, you can overwrite the drive to reduce the chance of recovering old files. This step is not necessary for normal reformatting.
dd cannot overwrite. Do not rely on zero-filling alone to sanitize flash storage containing sensitive data.Overwrite the entire drive with zeros using dd
:
sudo dd if=/dev/zero of=/dev/sdb bs=4096 status=progressThe 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:
15455776768 bytes (15 GB, 14 GiB) copied, 780 s, 19.8 MB/s
dd: error writing '/dev/sdb': No space left on deviceAfter 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. Both parted and the fdisk
command can create either type.
How do I format a drive using a graphical tool?
Use GNOME Disks for a quick format of a single partition, or GParted when you also need to change the partition layout. Both tools are covered in the sections above.
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.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

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