Fix bad sectors on flash memory

by 3eee3   Last Updated June 14, 2018 14:01 PM

I have a flash disk possibly with bas sectors. When I try to copy data to it, it works fine until somewhere around 460Mb, and then the files start getting corrupted. The corruption happens only when I unmount and remove the drive, before unmounting, the files are fine. The linux program 'badblocks' doesn't find any bad blocks. I tried formatting it, but that didn't have any effect. I used Fat 16 and 32, and both had the same problem. Is there a way to test for bad blocks after unmounting and how do I fix them?

Answers 2

I guess you have synchronization problem... Before unmount do the synchronization by sync command.

If this solution will not resolve your problem, you can try hard format your USB stick by 'dd' command

sudo dd if=/dev/zero of=/dev/sd?

then create partition and do a format.

Either those solutions will not work say bye to your stick..

Sencer H.
Sencer H.
January 06, 2012 14:51 PM

You can't.

From my experience USB flash memory doesn't remap bad blocks like a hard disks do. Once you get a write or read error - the drive is pretty much trash, as you can no longer trust it with any of your data. Many drives will seemingly perform writes without problems, but then give you corrupt data during reads.

Perform a test with f3

F3 stands for Fight Fake Flash or Fight Flash Fraud It's a tool designed to perform write/read tests on flash memory (or other media) to discriminate working, failing and fake flash memory.

To test your drive with f3:

  1. Install the F3 tool: apt install f3
  2. Format and mount the drive you want to test
  3. Open terminal in the root directory of your drive
  4. Execute this command: f3write .; f3read .; - this will first create test files, then read them back comparing to expected output. You'll get a detailed report on the write/read speeds and errors encountered while reading the data.
    1. After the test is over you can remove all test files rm *.h2w

If the test reports errors - my advice is to throw away the drive and buy something form a reputable vendor (for example: Kingston, pqi, Verbatim, Silicon Power). Cheap no-names tend to have a varying quality, sometimes abominable. Every now and then I deal with a batch of flash drives where 50% of the units are trash.

PS: I handle thousands of pendrives at work and I've developed an in-house tool based on f3 to conveniently test massive amounts of drives.

June 14, 2018 13:16 PM

Related Questions