14

My USB stick looks dead :

victor@X301A1:~$ umount /dev/sdc1

victor@X301A1:~$ sudo mkfs -t vfat /dev/sdc1
mkfs.vfat 3.0.12 (29 Oct 2011)
mkfs.vfat: unable to open /dev/sdc1: Read-only file system

victor@X301A1:~$ sudo hdparm -r0 /dev/sdc1
/dev/sdc1:
 setting readonly to 0 (off)
 readonly      =  0 (off)

victor@X301A1:~$ sudo fsck -n /dev/sdc1
fsck de util-linux 2.20.1
dosfsck 3.0.12, 29 Oct 2011, FAT32, LFN
/.Trash-1000/files/sans_titre
 Start does point to root directory. Deleting dir. 
/.Trash-1000/files/Bus CAN
 Start does point to root directory. Deleting dir. 
Reclaimed 190903 unused clusters (781938688 bytes).
Free cluster summary wrong (1001897 vs. really 1383698)
  Auto-correcting.
Leaving file system unchanged.
/dev/sdc1: 8052 files, 566660/1950358 clusters

Is there anyway for me to recover my USB stick ? Thank

1
  • my problem was a read only monster 128gb (aka pos). seems that a combination of things was required. i changed everything i could with a "sudo nautilus" of changing permissions, numerous installs (none of which worked). only when the drive went to rw could i do the dd, which took a very long time.
    – dwpbike
    Jun 14, 2016 at 0:51

2 Answers 2

31

Well, one could try zero'ing the raw block device to see if that can work. If you can write to that then you may be able to create a clean partition table, create a new partition and format that.

Suppose the USB stick is on /dev/sdc, first make sure /dev/sdc1 is unmounted:

umount /dev/sdc1

See if you can then clear the partition table, say by copying a bunch of zeros over the first few K

sudo dd if=/dev/zero of=/dev/sdc bs=512 count=16

If that works, see if you can write zeros to the whole device without it failing. To easily see if the kernel can't write to the device, first clear the current kernel messages and throw them away using:

sudo dmesg -c > /dev/null

..then zero the entire device:

sudo dd if=/dev/zero of=/dev/sdc bs=1M

..this will take a while. dd will complete when the raw block device is completely written to, or an error has occurred.

Then, check to see if the kernel has complained about the device, using:

dmesg

..if you see a load of error messages then you know that the USB stick is probably not in good condition.

However, if this works fine run fdisk or parted to create the partitions from clean, e.g. with fdisk I use:

sudo fdisk /dev/sdc
Command (m for help): n
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-7796735, default 2048): <return>
Last sector, +sectors or +size{K,M,G} (2048-7796735, default 7796735): <return>
Command (m for help): t
Hex code (type L to list codes): 6
Command (m for help): w

..note just press return for the First and Last sector questions, fdisk will chose the correct defaults (which will be different to my example above). And then format the partition with VFAT:

sudo mkfs.vfat /dev/sdc1

and then remove and re-insert the drive. It should be cleanly formatted.

6
  • Périphérique Amorce Début Fin Blocs Id Système /dev/sdb1 * 32 15633407 7816688 b W95 FAT32 victor@X301A1:~$ sudo dd if=/dev/zero of=/dev/sdb bs=512 count=16 dd: ouverture de «/dev/sdb»: Système de fichiers accessible en lecture seulement (Means : read only file system) Nov 30, 2012 at 8:22
  • Phenomenally detailed and accurate answer. I needed to know the zeroing the partition table information and stayed for the rest. Accurate down to the last command.
    – Kaobear
    Dec 27, 2014 at 15:51
  • 1
    Add status=progress option to dd (GNU Coreutils 8.24+ required) in order to display a progress. Nov 18, 2016 at 20:23
  • status=progress does not seem to show the progress
    – 030
    Sep 28, 2017 at 16:33
  • Warning: the dd command may take a long while. For my 128GB usb stick it took ~50 minutes!
    – Bach
    May 22, 2018 at 11:53
2

You can simply format it using gparted. If that doesn't work, as documented here, you can :

  1. Plug in your USB drive. Watch it appear on your desktop.
  2. Choose System>Administration>Partition Editor (enter your password)
  3. In Partition Editor, choose Gparted>Devices, and then the device that corresponds to your flash drive (which I determined by looking at the total size of the disks)
  4. Unmount the drive: Select it in the list, then choose Partition>Unmount.
  5. Choose Partition>Check. A window will pop up on the bottom saying that this one task is pending. BE SURE THAT NO OTHER TASKS ARE PENDING.
  6. Click "Apply", and "Apply" again in the confirmation dialog window.
  7. When Gparted is done with the check, it will re-mount the drive and open it in a new window.
1
  • Gparted cannot format the USB key because it is a read only device. I have no hardware switch on the key Nov 30, 2012 at 8:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .