How To Format a Corrupted USB Thumb Drive on Linux

There are plenty of how-to pages linuxpendriveon formatting a thumb drive on Linux, but most don’t show the fool proof way of doing it. After using a thumb drive in the Nintendo Wii, my son was convinced that it could not be reused, because Windows couldn’t see it when he plugged it in. A lot of Linux how-tos have the same problem. Others rely on tools that you may not have installed. This how-to avoids both problems.

To reformat any USB thumb drive for use on Linux or Windows:

  1. Be 100% sure that there is nothing you want on the thumb drive
  2. Run the following command: sudo fdisk -l
  3. When prompted [sudo] password for uname, enter your password
  4. You should see something like:
    Disk /dev/sda: 500.1 GB, 500107862016 bytes
    255 heads, 63 sectors/track, 60801 cylinders, total 976773168 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 4096 bytes
    I/O size (minimum/optimal): 4096 bytes / 4096 bytes
    Disk identifier: 0x00004e9a
    
    Device Boot Start End Blocks Id System
    /dev/sda1 * 2048 960366591 480182272 83 Linux
    /dev/sda2 960368638 976771071 8201217 5 Extended
    Partition 2 does not start on physical sector boundary.
    /dev/sda5 960368640 976771071 8201216 82 Linux swap / Solaris
  5. Plug in the thumb drive
  6. Run sudo fdisk -l again
  7. You should see a new Disk /dev in the output, which is the device Linux has assigned to your thumb drive:
    Disk /dev/sdb: 7876 MB, 7876902912 bytes
    256 heads, 39 sectors/track, 1540 cylinders, total 15384576 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0xc3072e18
  8. If the thumb drive has a valid partition table, you can skip to the last step. If it has one, you should see something like:
       Device Boot      Start         End      Blocks   Id  System
    /dev/sdb1   *          63    15384575     7692256+   c  W95 FAT32 (LBA)
  9. Otherwise, substituting the device displayed in step 7 for /dev/sdb, run:
    sudo fdisk /dev/sdb
  10. If the thumb drive has no usable file system on it (like the thumb drive written by the Nintendo Wii), you’ll see something like this:
    Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
    Building a new DOS disklabel with disk identifier 0x219a4410.
    Changes will remain in memory only, until you decide to write them.
    After that, of course, the previous content won't be recoverable.
    Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
    Command (m for help):
  11. Enter: w
  12. You should see:
    The partition table has been altered!
    Calling ioctl() to re-read partition table.
    Syncing disks.
  13. Run: sudo fdisk /dev/sdb
  14. At the Command prompt, enter: p
  15. You should see something like:
    Disk /dev/sdb: 4244 MB, 4244647936 bytes
    131 heads, 62 sectors/track, 1020 cylinders, total 8290328 sectors
    Units = sectors of 1 * 512 = 512 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x219a4410
  16. At the Command promt, enter: n
  17. When prompted for the Partition type, enter: p
  18. For the Partition number, enter: 1
  19. For the First sector, enter the lowest number in the range given (e.g. 2048)
  20. For the Last sector, use the largest number in the range given (e.g. 8290327), assuming you want to have only one big partition on your thumb drive
  21. At the Command prompt, enter: w
  22. Run the following command to create an empty filesystem on the thumb drive:
    sudo mkdosfs -F 32 -I /dev/sdb1

Note: You have to be careful to get the device names correct. /dev/sdb is the device name of the drive (the whole thumb drive), whereas /dev/sdb1 is the device name of the first (and possibly only) file system partition on the drive.

Advertisements

About jimbelton

I'm a software developer, and a writer of both fiction and non-fiction, and I blog about movies, books, and philosophy. My interest in religious philosophy and the search for the truth inspires much of my writing.
This entry was posted in linux and tagged , , , , , , , , . Bookmark the permalink.

Leave a Comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s