You are on page 1of 4

Lifewire

How To Fix A Broken USB Drive


Using Linux
by Gary Newell 42
Updated October 05, 2018

Sometimes when people create a Linux USB drive they find that the drive seems to
become unusable. This guide will show you how to format the USB drive again
using Linux so that you can copy files to it and use it as you ordinarily would.

After you have followed this guide your USB drive will be usable on any system
capable of reading a FAT32 partition. Anybody familiar with Windows will notice that
the fdisk tool used within Linux is much like the diskpart tool.

Delete The Partitions Using FDisk

01 Open a terminal window and type the following command:

sudo fdisk -l

This will tell you which drives are available and it also gives you details
of the partitions on the drives.

In Windows a drive is distinguished by its drive letter or in


the case of the diskpart tool each drive has a number.

In Linux a drive is a device and a device is handled much


like any other file. Therefore the drives are named /dev/sda,
/dev/sdb, /dev/sdc and so on.

Look for the drive which has the same capacity as your USB drive. For
example on an 8 gigabyte drive it will be reported as 7.5 gigabytes.
02 When you have the correct drive type the following command:

sudo fdisk /dev/sdX

Note: Replace the X with the correct drive letter.

03 This will open a new prompt called "Command". The "m" key is very
helpful with this tool but basically you need to know 2 of the
commands.

The first is delete.

04 Enter d and press the Enter key. If your USB drive has more than one
partition it will ask you to enter a number for the partition you wish to
delete. If your drive only has one partition then it will be marked for
deletion.

If you have multiple partitions keep entering d and then enter partition
1 until there are no partitions left to be marked for deletion.

05 The next step is to write the changes to the drive.

Enter w and press return.

06 You now have a USB drive with no partitions. At this stage it is


completely unusable.

Create A New Partition

01 Within the terminal window open fdisk again as you did before by
specifying the name of the USB device file:

sudo fdisk /dev/sdX

As before replace the X with the correct drive letter.

02 Enter N to create a new partition.

03 You will be asked to choose between creating a primary or extended


partition. Choose p for primary.

04 The next step is to choose a partition number. You only need to create
1 partition so enter 1 and press Enter.

05 Finally you need to choose the start and end sector numbers. To use
the whole drive press return twice to keep the default options.

06 Enter w and press return.

Refresh The Partition Table

A message may appear stating that the kernel is still using the old partition table.

Enter the following into the terminal window:

sudo partprobe

The partprobe tool informs the kernel or partition of table changes. This saves you
having to reboot your 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. This is not overly ube-d

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

As before replace the X with the correct drive letter.

Summary

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

You might also like