Sistema de blogs Diarium
Universidad de Salamanca
Pablo Gallardo's Blog
My professional web log about IT, Cybersecurity & Project Management
 

How to fix an unreadable USB Flash Drive on Ubuntu

Sometimes USB memory sticks just become unreadable, probably because we have remove it from the port before unmount it or because we had to force to stop a process that was operating with it. In any case, we would like to fix our USB to avoid loosing a valuable storage device.

Some OS, like Windows or MacOS X, seem to not react when USB is plugged. This is why I use GNU/Linux to fix this issue.

Instructions

Detailed steps to solve issue below.

1. Identify path of mounted unit

Before plugging the USB flash drive, check the devices in your system by using this command in terminal:

lsblk

First level of hierarchy represents devices, and second level represents the partitions inside that device.

Plug the USB, and run command again:

lsblk

There will be a new device on list. In my case, device was “sdb” and partition “sdb1″. In this post, I write “sdX” and “sdX0″ whenever I make reference to  device and partition, respectively.

An alternative to lsblk command would be:

sudo fdisk -l

2. Delete USB

Use another command to delete all content on device.

sudo dd if=/dev/zero of=/dev/sdX

Remember substitute the path by the one that corresponds to you.

It takes time, be patient. For me, it took more than an hour for a 16 GB USB from a laptop from 2010.

When it finished, if I run a lsblk, I only see device “sdX” without any other partition. In some other tutorials I have read, it considers there are partitions below “sdX” (like sdX1). This is not my case, so I had to add the following step.

3. Create partition table

There are two main of partition table types, and both are covered in this post:

  1. msdos: Master Boot Record (MBR)
  2. gpt: GUID Partition Table (GPT)

If you are looking for any other partition table type, you have to look further on other sources. They are not covered on this post.

Perform only one of the following options, depending on whether you want mMBR or gpt.

3.1. Create an MBR partition table

Format USB by typing the command below.

sudo fdisk /dev/sdX

Remember to substitute the path with the one that applies to your device.

If partition table is not created, it will create a DOS disk label (msdos) without prompting.

In the command line from fdisk, confirm that you want to write changes by typing:

w

Changes will be confirmed.

3.2. Create a gpt partition table

To create a GUID Partition Table (gpt) partition table, I use “parted” command instead of “fdisk”.

Type this command:

sudo parted /dev/sdX

Then:

mklabel GPT

You may need to confirm warnings:

Warning: The existing disk label on /dev/sdX will be destroyed and all data on
this disk will be lost. Do you want to continue?
Yes/No?

Type ‘Y’ and press enter to confirm.

4. Create partition

In this step, we are creating the first partition for the gparted.

Type:

sudo fdisk /dev/sdX

Remember to substitute the path with the one that applies to you.

Now start creating a new partition by entering command:

n

Now you need to choose any of the following options, depending whether you had selected msdos or gdp partition table.

4.1. Create partition on MBR partition table

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

Partition number (1-128, default 1):

When prompted to choose between creating a primary or extended partition, choose p for primary. This step only applies for MBR partition tables.

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

First sector (34-30310366, default 2048):

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

Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-30310366, default 30310366):

To apply changes to USB flash drive, enter w, then press return.

4.2. Create partition on gpt partition table

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

First sector (34-30310366, default 2048):

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

Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-30310366, default 30310366):

Then new partition is created.

Created a new partition 1 of type 'Linux filesystem' and of size 00 GiB

Sometimes after partition table is GPD, system asks whether you want to remove signature. As this is a new partition and you are not resizing an existing one, you can accept to remove the signature.

Partition #0 contains a vfat signature.
Do you want to remove the signature? [Y]es/[N]o:

To apply changes to USB flash drive, enter w, then press return.

5. Format partition

Format USB by typing the corresponding command in terminal. The command may vary depending on the USB format you want to appy (FAT32, NTFS, ext4, etc.)

Check the list of different file systems if you want to check it.

Remember to substitute the path with the one that applies to you.

FAT

sudo mkfs.vfat /dev/sdX0

FAT32

sudo mkfs.vfat -F 32 /dev/sdX0

NTFS

sudo mkfs.ntfs -f /dev/sdX0

Ext4

sudo mkfs.ext4 -f /dev/sdX0

6. Modify USB label

mlabel is a command utility included in MTools package.

Use this command:

sudo mlabel -i /dev/sdX0 ::<labelname>

Remember to substitute the partition path with the one that applies to you, and <labelname> by the label name you want to apply. Also remember to keep the two colons.

You might be also interested in…

External references

pmgallardo

About pmgallardo

I studied Computer Science at University of Salamanca. Since then, I have been working first as developer and then as SAP consutant. This blog is about problems I dealt when using computers, and more important, the solutions I found. Whenever I am on an issue and suddenlly I have a flash that leads me to a solution, I document my discoveries in a post.

, , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,

No comments yet.

Leave a Reply


*

Política de privacidad
Studii Salmantini. Campus de excelencia internacional