2013-01-06

HOWTO: stress-test a USB flash drive for bad blocks in Linux

Once upon a time you may like to test your USB flash drive [or maybe a SATA HDD, who knows] for bad blocks.

First of all, backup all the data stored on the target drive;
then you should unmount any mounted partitions located on that drive:
# umount /dev/sdz1
Then you can begin the tests (CAUTION: these tests will destroy all the stored data on the tested drive).

You can use dd utility to fill the drive with zeros:
# dd if=/dev/zero of=/dev/sdz
or with pseudorandom data:
# dd if=/dev/urandom of=/dev/sdz
and it will stop unexpectedly on a bad block.

And there's also a little more handy utility called badblocks:
# badblocks -wso /tmp/badblocks.log /dev/sdz
It will sequentially fill the entire /dev/sdz device with some patterns (0xAA, 0x55, 0xFF, 0x00), then read and compare the read data with an actual pattern. A list of bad blocks will be written to /tmp/badblocks.log file.

References:

No comments:

Post a Comment