Reformatting a USB Flash Drive

From rdiez's Personal Wiki
Jump to navigationJump to search

Reformatting a USB flash drive can be difficult. For example, GParted often gets confused with USB flash drives that have been formatted with a Linux boot image. When GParted starts, you get a warning that the sector size is wrong, and the total USB flash drive size is incorrect too. Linux quietly automounts such USB flash drives as read only, and you are then surprised that you cannot create any files on them. Completely cleaning a USB flash drive under Microsoft Windows can be difficult too.

These are the steps to wipe out the partition table and optionally format the USB disk with FAT32:

  • Attach the USB disk.
  • Unmount (not "eject") with your favourite file manager any filesystems on the USB device that get automatically mounted.
  • Find out what the USB disk is called on your system:
sudo fdisk -l
  • Run the following commands in order to clear the partition table:
sudo fdisk /dev/sdX
p  # print the partition table
o  # create a new empty DOS partition table
That could be enough. Afterwards, you can format the USB disk with the normal system tools. If you wish, you can create a FAT32 partition with fdisk too:
n  # add a new partition
t  # change a partition type
   # Choose partition type 'b' W95 FAT32
   #                    or 'c' W95 FAT32 (LBA)
Do not forget to write your changes before you exit fdisk.
w  # write table to disk and exit
  • If your system automounts the USB disk again, unmount (not "eject") again any filesystems on the disk.
  • If you created a FAT32 partition, format it like this:
sudo mkfs  -t vfat  -n "USB16GB"  /dev/sdXY
Make sure to enter a label that is different from the old one. A new label will help you avoid confusion if your system stubbornly remembers the old partition.
  • Eject the USB disk with your favourite file manager. Otherwise, sometimes it remains half-mounted in Linux and causes further confusion.