7

I am using badblocks to 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
  • 7
    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, 2015 at 11:41
  • 1
    @Slizzered Thanks, that's useful to consider. Shouldn't two passes be sufficient in that case? 0xff and 0x00. May 5, 2015 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) May 5, 2015 at 12:13
  • 3
    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, 2015 at 12:17

2 Answers 2

11

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.


Example command and output:

# badblocks -wsvt 0 /dev/sdz
Checking for bad blocks in read-write mode
From block 0 to 488386583
Testing with pattern 0x00: done                                                 
Reading and comparing: done                                                 
Pass completed, 0 bad blocks found. (0/0/0 errors)
4
  • I don't get it. What about the entire discussion you had in the comments with @Slizzered? I think the most reasonable flags to use are -wsv (taking the -t 0 out from your answer here). I agree that 4 entire passes is a long time to wait and we often don't have that long to wait (my 14TB drives would take 72 hrs). And maybe most issues if there are issues will crop up within the first test. But it's really supposed to do a full pass of all 4 of those patterns... that's what the answer should be. I guess it's subjective because the meaning of "pass" is kind of up for debate here.
    – Steven Lu
    Aug 25, 2022 at 3:13
  • 1
    Keep in mind you can run badblocks in parallel. So if you had 10 of these drives to check you could do a full check on them in the ~72 hours instead of the unacceptable quantity of time that would be 720 hours (30 days).
    – Steven Lu
    Aug 25, 2022 at 3:15
  • @StevenLu Thanks for spotting that. Actually it was my question that was at fault rather than my answer. My aim when I wrote this was to destroy the data rather than check for errors. I've edited the question accordingly. Aug 25, 2022 at 10:15
  • Ah, that makes more sense then. I do believe though for a really secure erase you'll also need multiple passes, I suppose letting it do all 4 passes ought to accomplish that well.
    – Steven Lu
    Aug 25, 2022 at 18:41
0

If the goal was to destroy the data rather than looking for errors, then you could just use

dd if=/dev/zero of=/dev/sdX status=progress

where X is the letter of your target device.

But if you are really worried about the data on your disk, you can run dd multiple times, use other tools like wipe or shred or just let badblocks do its job. It all depends on the time you are willing to invest in deleting the data.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .