I recently bought a 4TB hard disk and I want to do a read-write badblocks test on this before I start using it. Since running badblocks with -w option would take ages for 4TB, I've thought to first write a pattern on the disk and then use the -t option to read that pattern through badblocks, completing it in hours rather than in days.

The problem is that I couldn't understand how the -t option of badblocks works and I got no search results when searching the web for an example of using badblocks with -t option. From man page, test pattern is a numeric value between 0 and ULONG_MAX-1 (I'm making a wild guess that ULONG_MAX is 2^32), but I'm not sure how to provide the pattern (decimal? hexadecimal? binary? ASCII string with length < 2^(32/8)?). And is the pattern size related to block size?

The other part of the problem is to write a script to fill the hard disk with the pattern. I can write a Ruby script to do that, but a one liner bash command piped through pv would be nice!


Letting badblocks write the pattern in the first place should be no slower than writing it any other way. Especially if you use the -b block-size and -c blocks-at-once options so it doesn't do small reads/writes.

This example overwrites the disk with "random" pattern in 1MiB blocks:

badblocks -v -w -t random -b 4096 -c 256 /dev/thedisk

If there is a problem with speed, it should have some other cause...


Writing a pattern with one tool and reading it with badblocks is not going to be much faster than running badblocks with a single pattern, I imagine.

The pattern needs to be specified in hex, at least that's what I understand from this:
badblocks -t 0x55 -w [...]

Source: https://github.com/autotest/ctcs/blob/master/runin/destructiveblocktstrnd


So after some more research, I came up with a way to utilise the -t option of badblocks (but you should prefer frostschutz's answer (I somehow missed to notice the -c option while asking this question)).

Write 42 all over the hard disk.

yes 4 | tr '\n' 2 | pv -pterb -s 4000G > /dev/sdx

Verify through badblocks

badblocks -vs -t 0x3432 /dev/sdx

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.