Format Any Storage Device: SD Card, USB Drive, or Hard Drive

How to fully wipe and reformat an SD card, USB drive, or external hard drive on Linux — zero every sector, create a fresh partition table, and format for any use case.

Intermediate Updated 7 min read Tested on Linux Mint 22.3 Cinnamon (Ubuntu 24.04 Noble base); also tested on Zorin OS 18.1 Pro Hardware Lenovo ThinkPad L14 Gen 2 (Intel i5-1135G7, 16GB RAM, Intel Iris Xe, 1366x768); tested with a 16 GB SD card

What This Guide Achieves

Completely wipe a storage device — SD card, USB flash drive, or external hard drive — down to the raw hardware, then rebuild it with a fresh partition table and filesystem. The result is a clean device with no leftover data, no corrupted metadata, and no remnants of a previous OS install or filesystem.


The Problem (Windows User Perspective)

On Windows, “formatting” a drive usually means a quick format — it rewrites the filesystem index but leaves all the old data physically on disk. It is fast but does not actually clean anything deeply.

On Linux you can do a full format that writes zeros to every single sector before creating the new filesystem. This eliminates corrupted sectors, wipes leftover data, and gives the device a genuinely clean state — useful when a card is behaving strangely, was previously used as a bootable drive, or is being repurposed.


Before You Start

Identify Your Device Type

DeviceTypical Linux nameExample
SD card (built-in slot)/dev/mmcblkX/dev/mmcblk0
USB flash drive/dev/sdX/dev/sdb
External hard drive (USB)/dev/sdX/dev/sdc
Second internal HDD/SSD/dev/sdX/dev/sda

Choose Your Filesystem

Pick the filesystem that matches how the device will be used:

FilesystemFile size limitBest for
exFATNoneSD cards, USB drives used across Windows / Mac / Linux / Android 5.0+ — the modern default for portable storage
FAT324 GB per fileMaximum compatibility — old cameras, Android 4.x, car audio systems, any device from before ~2013
ext4NoneLinux-only drives — external backup drives used with Timeshift or rsync
NTFSNoneDrives that will primarily be used with Windows but also readable on Linux

For most portable storage in 2024, exFAT is the right choice.


Step 1: Identify the Device

Plug in the device and run:

lsblk

Sample output with an SD card inserted:

NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS
mmcblk0     179:0    0  14.4G  0 disk
└─mmcblk0p1 179:1    0  14.4G  0 part /media/mohsin/823A-1A12
nvme0n1     259:0    0 476.9G  0 disk
├─nvme0n1p1 259:1    0   487M  0 part /boot/efi
├─nvme0n1p2 259:2    0 167.6G  0 part /
...

Confirm your target device by its size. In the example above:

  • mmcblk0 (14.4 GB) is the SD card
  • nvme0n1 (476.9 GB) is the system drive — do not touch this

CRITICAL: Every command from here uses /dev/mmcblk0 as the example. Replace it with your actual device name. Running dd on the wrong device will silently destroy whatever is there — your system drive, another USB drive, anything. Verify the size before proceeding.


Step 2: Unmount the Device

If the device has a mountpoint shown in lsblk, unmount it. Unmount each partition individually:

sudo umount /dev/mmcblk0p1

For a USB drive with multiple partitions:

sudo umount /dev/sdb1
sudo umount /dev/sdb2

Verify it is unmounted — the MOUNTPOINTS column should now be empty:

lsblk

Step 3: Wipe Every Sector with Zeros

This is the step that makes the format genuinely deep. dd writes zeros to every single sector from start to finish:

sudo dd if=/dev/zero of=/dev/mmcblk0 bs=4M status=progress conv=fsync

Replace /dev/mmcblk0 with your device. For a USB drive it would be /dev/sdb.

FlagMeaning
if=/dev/zeroRead an endless stream of zeros as input
of=/dev/mmcblk0Write to the entire device (not a partition)
bs=4MWrite in 4 MB chunks for efficiency
status=progressShow live bytes written and speed
conv=fsyncFlush all buffered writes to disk before dd exits

The command finishes with:

15472787456 bytes (15 GB, 14 GiB) copied, 1638 s, 9.4 MB/s
dd: error writing '/dev/mmcblk0': No space left on device

“No space left on device” is the expected and correct ending. It means dd reached the last sector and ran out of device to write to. Every byte is now zero.

Estimated time

Device sizeUSB 2.0 (~10 MB/s)USB 3.0 (~80 MB/s)
16 GB~27 min~4 min
32 GB~55 min~7 min
64 GB~110 min~14 min
500 GB~14 hours~1.75 hours

For large external hard drives: The wipe will take many hours. This is normal. You can run it overnight. If you only want to clean the filesystem without a full wipe, skip to Step 4 — but the full wipe is what gives you a genuinely fresh device.


Step 4: Create a Fresh Partition Table

sudo fdisk /dev/mmcblk0

Inside fdisk, type each of the following and press Enter after each:

g

Creates a new GPT partition table (erases any previous partition layout).

n

Creates a new partition. Accept all three defaults by pressing Enter three times — this creates a single partition using the full device.

w

Writes the changes to disk and exits fdisk.

Full expected output:

Command (m for help): g
Created a new GPT disklabel (GUID: AF59B419-...).

Command (m for help): n
Partition number (1-128, default 1):
First sector (2048-30228446, default 2048):
Last sector ... (default 30226431):
Created a new partition 1 of type 'Linux filesystem' and of size 14.4 GiB.

Command (m for help): w
The partition table has been altered.
Syncing disks.

Step 5: Format the Partition

Run the command for your chosen filesystem. Use the partition (mmcblk0p1, sdb1), not the whole device.

sudo apt install exfatprogs -y
sudo mkfs.exfat -n "STORAGE" /dev/mmcblk0p1

FAT32 (maximum compatibility)

sudo mkfs.fat -F32 -n "STORAGE" /dev/mmcblk0p1

ext4 (Linux backup drives)

sudo mkfs.ext4 -L "STORAGE" /dev/mmcblk0p1

NTFS (Windows-primary drives)

sudo apt install ntfs-3g -y
sudo mkntfs -f -L "STORAGE" /dev/mmcblk0p1

Change "STORAGE" to any label you want. Keep it short and avoid spaces for maximum compatibility.


Step 6: Verify

Confirm the filesystem, label, and UUID were written correctly:

lsblk -f /dev/mmcblk0

Expected output after exFAT format:

NAME        FSTYPE FSVER LABEL   UUID
mmcblk0
└─mmcblk0p1 exfat  1.0   STORAGE FBFF-3318

All three — FSTYPE, LABEL, and UUID — should be populated. If FSTYPE is blank, the format did not complete correctly and should be repeated.


Step 7: Safe Ejection

USB drives and external hard drives

udisksctl power-off -b /dev/sdb

This spins down the drive and cuts USB power. The drive is safe to physically remove once the command returns.

SD cards in a built-in card reader

udisksctl power-off does not work for built-in slots (no USB power to cut). Unmount and remove manually:

sudo umount /dev/mmcblk0p1 2>/dev/null; echo "Safe to remove"

Physically pull the card after the prompt returns.


What Didn’t Work

ApproachWhy
Formatting via the Files app (Nautilus)Only does a quick format — rewrites the filesystem header but leaves all old data in place
mkfs without dd firstCreates a new filesystem on top of the old one — metadata from the previous OS install, bootloader, or partition layout can still confuse some devices
udisksctl power-off on a built-in SD slotReturns “No usb device” — built-in readers are not USB devices; just unmount and pull
Running dd on a mounted partitiondd can still run but the OS may be writing to the device simultaneously, causing a corrupted wipe

Discussion