2

I am using badblocks to simultaneously (a) checking a disk for errors, and (b) do a destructive erase of any data on the disk; using the following command:

badblocks -wsp 0 /dev/sdb1

I passed the option -p 0 in the hopes that this would result in only a single pass, but I am getting multiple passes:

Testing with pattern 0xaa: done
Reading and comparing: done
Testing with pattern 0x55: done
Reading and comparing: done
Testing with pattern 0xff: done
Reading and comparing: 19.01% done, 7:43:47 elapsed. (0/0/0 errors)

From reading the manpage, I can see that the -w option itself includes four passes:

-w Use write-mode test. With this option, badblocks scans for bad blocks by writing some patterns (0xaa, 0x55, 0xff, 0x00) on every block of the device, reading every block and comparing the contents. This option may not be combined with the -n option, as they are mutually exclusive.

This is excessive for my needs. Is there any way to achieve a single destructive pass?

  • 4
    Keep in mind, that the multiple passes are not for erasing the data. They are necessary to find certain errors on your disk. Otherwise you might not find all bad blocks. Consider the case where a bit is always stuck at 1. If you only did test with the 0xff-pattern, you would not be able to find this error. Since badblocks is not designed to erase the data, but to find bad blocks, multiple passes is not considered to be excessive. – Slizzered May 5 '15 at 11:41
  • 1
    @Slizzered Thanks, that's useful to consider. Shouldn't two passes be sufficient in that case? 0xff and 0x00. – Jon Bentley May 5 '15 at 12:09
  • 1
    @Slizzered Thinking about it, I suppose that wouldn't cover the case where writing a 1 would fail, but the bit already has a 1, but I can't think of a scenario where 3 passes would be insufficient (0xff, 0x00, 0xff again) – Jon Bentley May 5 '15 at 12:13
  • 2
    Actually you got it a bit wrong, I think. Writing itself can not be checked against failure. It writes 0xff and immediately checks if there is 0xff written by reading the location from disk. So the stuck 0 is ruled out. Then, it does the same with 0x00 to rule out the stuck 1 error. so 1 pass with each pattern is sufficient. The other ones (alternating pattern of 0 and 1) are against bits that stick together (if I set bit N to 1, bit N+1 also goes to 1 as a result of the error) – Slizzered May 5 '15 at 12:17
3

Upon reading the manpage further, I've solved the problem. -w does indeed do a single pass, as implied from the description of the -p option:

Default is 0, meaning badblocks will exit after the first pass.

A pass consists of four test patterns:

-w Use write-mode test. With this option, badblocks scans for bad blocks by writing some patterns (0xaa, 0x55, 0xff, 0x00) on every block of the device, reading every block and comparing the contents.

The pattern can be overriden using the -t option:

-t test_pattern Specify a test pattern to be read (and written) to disk blocks. The test_pattern may either be a numeric value between 0 and ULONG_MAX-1 inclusive, or the word "random", which specifies that the block should be filled with a random bit pattern. For read/write (-w) and non-destructive (-n) modes, one or more test patterns may be specified by specifying the -t option for each test pattern desired. For read-only mode only a single pattern may be specified and it may not be "random". Read-only testing with a pattern assumes that the specified pattern has previously been written to the disk - if not, large numbers of blocks will fail verification. If multiple patterns are specified then all blocks will be tested with one pattern before proceeding to the next pattern.

E.g.:

badblocks -wst 0 /dev/sdb1

  • What's the relationship between the value -t takes, and the standard patterns (0xaa, 0x55, 0xff, 0x00) badblock's -w usually uses? Is there a code to "0 and ULONG_MAX-1" that I don't know? The man page isn't very clear – Xen2050 Jan 20 '17 at 8:41
  • @Xen2050 the defaults are -t 0 -t 95 -t 197 -t 255 (corresponding to 0x00 0x55 0xaa -0xff). But if you provide the -t parameter, it ignores all the defaults and just runs with the numbers you provided. – Capi Etheriel Jul 28 '17 at 22:36
  • I can't read for the manpage that -w would only do a single pass. ArchWiki only mentions that badblocks -nsv /dev/device does a single pass. – Arch Linux Tux Sep 9 '18 at 12:20
  • 1
    @ArchLinuxTux It is implied from the description of the -p option: "Default is 0, meaning badblocks will exit after the first pass." – Jon Bentley Sep 10 '18 at 17:55

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.