Speed up badblocks check

Having ordered an external hard drive from China… let me rephrase that; having ordered a really cheap hard drive from an unknown source at the farthest side of the world, getting it handled by the not so delicate hands of the Mexican post office, and getting it delivered to my door by bicycle, of course I had to check it thoroughly before putting any data in it.

I started with the well known way of checking for bad blocks on a storage device:

badblocks /dev/sdX

This command by default checks for bad blocks only by reading. If you want to also check writing non-destructively, the -n option must be provided.

badblocks -n /dev/sdX

This was what I originally tried, but after 2 hours it had only checked 3% of the entire drive, not acceptable! There has to be a way to improve the performance.

How to speed up badblocks read/write check

First, I recommend you get your hard drive’s block size, I’m not sure if this impacts performance but it’s more reliable:

lsblk -o NAME,PHY-SEC /dev/sdX
sda 512

In case your hard drive is empty or you don’t mind losing its data, use the write mode option (-w). This mode is faster than the -n option but the entire drive contents will be overwritten.

Finally, choose a bigger number of blocks to test at a time using the -c option; the default is 64. By benchmarking I found that 128 was a bit faster but YMMV. The badblocks command accepts a [last block] option, this way you can benchmark different -c values:

time badblocks -b512 -c128 /dev/sdX 1000000

If you want badblocks to show the scan progress, provide the -s option. This is what the final command looks like:

badblocks -b512 -c128 -w -s /dev/sdX

BTW. The drive was 100% free of errors.

Published by

Jesús Sánchez

IT specialist at Quantum Valley.

Leave a Reply

Your email address will not be published. Required fields are marked *