How to Fix a Broken USB Drive Using Linux

If a USB flash drive stops working, here's what to do

If you create a Linux USB drive and the drive becomes unusable, format the USB drive using the fdisk tool in Linux so that you can copy files to it and use it as you ordinarily would. The fdisk tool is similar to the diskpart tool in Windows. After you reformat the USB drive, it will be usable on any system that reads FAT32 partitions.

These procedures erase everything on the USB drive. Backup the files on the drive before you reformat it.

Delete the Partitions Using FDisk

The first step is to delete any partitions on the USB drive.

  1. Open a terminal window, then type the following command:

    sudo fdisk -l

    This shows which drives are available and gives details of the partitions on the drives.

    • In Windows, a drive is distinguished by a drive letter. In the diskpart tool, each drive has a number.
    • In Linux, a drive is a device, and a device is handled like other files. The drives are named /dev/sda, /dev/sdb, /dev/sdc, and so on.

    Look for the drive which has a similar capacity as the USB drive. For example, on an 8-gigabyte drive, it is reported as 7.5 gigabytes.

  2. When you have the correct drive, type the following command:

    sudo fdisk /dev/sdX

    Replace the X with the correct drive letter.

  3. At the Command prompt, enter d, then press the Enter key. If the USB drive has more than one partition, you are prompted to enter a number for the partition you want to delete. If the drive only has one partition, it is marked for deletion.

    If you want to delete multiple partitions, enter d, then enter partition 1 until no partitions are left to be marked for deletion.

  4. Type w, then press the Enter key to write the changes to the drive.

  5. You now have a USB drive with no partitions. At this stage, it is completely unusable.

Create a New Partition

The second step is to create a new partition on the USB drive.

  1. In the terminal window, open fdisk by specifying the name of the USB device file:

    sudo fdisk /dev/sdX

    Replace the X with the correct drive letter.

  2. Enter n to create a new partition.

  3. When prompted to choose between creating a primary or extended partition, choose p for primary.

  4. Choose a partition number. You only need to create 1 partition, so enter 1, then press Enter.

  5. Choose the start and end sector numbers. To use the whole drive, press the Enter key twice to keep the default options.

  6. Enter w, then press return.

Refresh the Partition Table

A message may appear stating that the kernel is using the old partition table. When this happens, enter the following in the terminal window:

sudo partprobe

The partprobe tool informs the kernel or partition of the table changes. This saves you from having to reboot the computer. There are a couple of switches you can use with it.

The minus d switch lets you try it without it updating the kernel. The d stands for dry run.

sudo partprobe -d

This provides a summary of the partition table:

sudo partprobe -s

With output similar to the following:

/dev/sda: gpt partitions 1 2 3 4
/dev/sdb: msdos partitions 1

Create a FAT Filesystem

The final step is to create the FAT filesystem.

Enter the following command into the terminal window:

sudo mkfs.vfat -F 32 /dev/sdX1

Replace the X with the letter for your USB drive.

Mount the Drive

To mount the drive, run the following commands:

sudo mkdir /mnt/sdX1
sudo mount /dev/sdX1 /mnt/sdX1

Replace the X with the correct drive letter.

You should now be able to use the USB drive on any computer and copy files to and from the drive as normal.