In this guide you’ll see how to completely wipe and format a USB disk as FAT32 using only the command line (bash).

⚠️ Warning: these commands permanently erase all data on the disk. In the examples below the USB disk is /dev/sda. Make sure you replace it with the correct device on your system, or you could wipe the wrong disk.

1. Detect the partition

List all disks and partitions to identify your USB device:

sudo fdisk -l

2. Unmount the disk

Unmount every partition of the USB disk before modifying it:

sudo umount /dev/sda?*

3. Wipe the file system

Remove all existing file system, RAID and partition-table signatures from the disk:

sudo wipefs -a /dev/sda

Example output:

/dev/sda: 5 bytes were erased at offset 0x00008001 (iso9660): 43 44 30 30 31
/dev/sda: 8 bytes were erased at offset 0x00000200 (gpt): 45 46 49 20 50 41 52 54
/dev/sda: 8 bytes were erased at offset 0x3a3affe00 (gpt): 45 46 49 20 50 41 52 54
/dev/sda: 2 bytes were erased at offset 0x000001fe (PMBR): 55 aa
/dev/sda: calling ioctl to re-read partition table: Success

4. Create a new partition table

Create an MBR (msdos) partition table with a single primary FAT32 partition spanning the whole disk:

sudo parted -s /dev/sda mklabel msdos mkpart primary fat32 1MiB 100%

5. Format using FAT32

Format the new partition as FAT32 and give it the label USB:

sudo mkfs.fat -F 32 -n USB /dev/sda1

Example output:

mkfs.fat 4.2 (2021-01-31)

That’s it: your USB disk is now clean and formatted as FAT32, ready to be used on Linux, Windows and macOS.

Categories: BashServer