Skip to content

Instantly share code, notes, and snippets.

@sadanand1120
Last active January 31, 2025 00:30
Show Gist options
  • Save sadanand1120/c7c7c0c247bd937c5a2201a4a4a623fc to your computer and use it in GitHub Desktop.
Save sadanand1120/c7c7c0c247bd937c5a2201a4a4a623fc to your computer and use it in GitHub Desktop.
Steps to cleanly format a usb/ssd to any filesystem (ext4, ntfs, exfat, fat32) on Ubuntu

Completely format a USB, SSD from ubuntu

  • lsblk and check the mount point, e.g., /dev/sda which might have different partitions like /dev/sda1 etc
  • sudo umount /dev/sda*. Use sudo umount -l /dev/sda* if something refuses to unmount
  • sudo fdisk /dev/sda to delete all partitions one-by-one:
    • Press p to print the current partitions
    • Press d to delete each partition (repeat for all).
    • Press w to write changes and exit.
    • HINT: just keep doing d until you get no partitions remaining to be deleted, then do w and exit.
  • sudo parted /dev/sda mklabel gpt to create a new GPT partition table
  • sudo parted -a optimal /dev/sda mkpart primary 0% 100% creates a new parition (/dev/sda1)
  • Format the partition (/dev/sda1) with your preferred file system (below USB_DRIVE is just the assigned name, anything works):
    • sudo mkfs.exfat -n USB_DRIVE /dev/sda1 for exFAT (Best for universal use); Works on Windows, Mac, Linux
    • sudo mkfs.ntfs -f -L USB_DRIVE /dev/sda1 for NTFS; Originally only for Windows, but now with ntfs-3g, also works on Linux
    • sudo mkfs.vfat -F 32 -n USB_DRIVE /dev/sda1 for FAT32; Works everywhere but has a 4GB file size limit
    • sudo mkfs.ext4 -L USB_DRIVE /dev/sda1 for ext4; Linux-only
  • Safely eject and remove.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment