Badblocks

Another tips/reminder post for when I’ll need it again in the future.

When I get a new hard drive, or I’m getting rid of one, I like to make sure the drive is properly wiped-out and that it’s in a good working state. It turns out that there’s a software doing both of that: badblocks. Note that wiping out an SSD is different and this doesn’t really apply.

Checking hard drive’s block size

This is an optional part, but seems useful in some cases to specify the disk’s block size to badblocks.

Install blockdev first if necessary, on Debian: sudo apt install util-linux

Get the block size: sudo blockdev --getbsz /dev/sdX (replace sdX by the hard drive you want to check)

Installing badblocks

On Debian: sudo apt install e2fsprogs

Using badblocks

Note: the data on the drive will be lost as testing it requires writing on the whole disk.

I usually run badblocks this way:

sudo badblocks -s -v -w -b 4096 -c 65536 -t 0xaa -t 0x55 -t 0xff -t 0x00 -t random -o /tmp/badblocks.txt /dev/sdX

Here is a detail of the used options:

Again, this is a destructive operation, make sure you run it on the right drive.

Comments Add one by sending me an email.