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?
I guess you have synchronization problem... Before unmount do the synchronization by
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..
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 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
apt install f3
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.
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.