Is there a way to test the integrity of USB sticks?
I’ve used this in the past, but it is for Windows format only. HOME PAGE OF MISHA CHERKES If it doesn’t hold data you have to have, you could just format it to ext4, and do a bad sector check with fsck -f.
Unfortunately I don’t use Windows. Also I was looking for a test that wasn’t very write intensive. In order to prevent further deterioration. Perhaps something that calculates the size of the disk, writes a big file that fills it, one time, then reads it for comparison.
Perhaps read the entire raw drive using dd or similar and dump the output to /dev/null
Here is the output I see from a broken usb stick on my system:
% dd if=/dev/sde of=/dev/null
dd: reading `/dev/sde1’: Input/output error
30648+0 records in
30648+0 records out
15691776 bytes (16 MB) copied, 9.35671 s, 1.7 MB/s
And doing a dmesg afterwards may show interesting things:
2287.905772] Buffer I/O error on device sde, logical block 924
2287.905784] Buffer I/O error on device sde, logical block 925
2287.905790] Buffer I/O error on device sde, logical block 926
2287.905795] Buffer I/O error on device sde, logical block 927
2287.905801] Buffer I/O error on device sde, logical block 928
2287.905806] Buffer I/O error on device sde, logical block 929
2287.905811] Buffer I/O error on device sde, logical block 930
2287.905817] Buffer I/O error on device sde, logical block 931
2287.905822] Buffer I/O error on device sde, logical block 932
2287.905827] Buffer I/O error on device sde, logical block 933
2287.908637] sd 9:0:0:0: [sde] Unhandled error code
2287.908642] sd 9:0:0:0: [sde] Result: hostbyte=DID_NO_CONNECT driverbyte=DRIVER_OK
2287.908650] sd 9:0:0:0: [sde] CDB: Read(10): 28 00 00 00 1d d0 00 00 10 00
2287.908664] end_request: I/O error, dev sde, sector 7632
2287.908726] sd 9:0:0:0: [sde] Unhandled error code
2287.908731] sd 9:0:0:0: [sde] Result: hostbyte=DID_NO_CONNECT driverbyte=DRIVER_OK
2287.908737] sd 9:0:0:0: [sde] CDB: Read(10): 28 00 00 00 1d e0 00 00 f0 00
2287.908751] end_request: I/O error, dev sde, sector 7648
BTW - some (most?) sticks map out bad blocks, so rewriting or deleting a file with bad blocks may cause the bad blocks to disappear. So the media may appear fine on subsequent scans. For example, for the stick I had trouble with above, I overwrote the device and it appears OK now. It might take a few passes to flush out all the bad blocks…
dd if=/dev/zero of=/dev/sde
dd: writing to `/dev/sde’: Input/output error # <— discovered another bad block.
30905+0 records in
30904+0 records out
15822848 bytes (16 MB) copied, 11.5279 s, 1.4 MB/s