Badblocks

January 21st 2021

Badblocks is a Linux software that tests a drive for bad blocks. It can do this non-destructively or destructively. It is a good tool to check if a drive is healthy, and can withstand general use. Badblocks will not run on a mounted drive to prevent data loss and false errors.

The command below does a non-destructive test on the drive /dev/sdb and stores the results in the file badsectors.log.

sudo badblocks -nsv /dev/sdb >badsectors.log

The command below does a destructive test. This writes 5 random patterns to all the blocks on the device, then compares the data to ensure data integrity. If you made partitions on this drive before running this command, those partitions are now lost.

 sudo badblocks -wsv /dev/sdb >badsectors.log

The command below does a destructive test with two custom patterns, the first uses the pattern 100 while the second is a randomly generated number. As before, if there was data on the drive before running this test, that data is now lost for ever.

 sudo badblocks -wsv -t 100 -t random /dev/sdb >badsectors.log
This post is written by Gouthaman Raveendran, licensed under CC BY-NC 4.0.