martijnvanbrummelen / nwipe

nwipe secure disk eraser
GNU General Public License v2.0
797 stars 86 forks source link

Bad blocks handling of nwipe #618

Closed Knogle closed 1 month ago

Knogle commented 1 month ago

Ahoy! I hope you’re doing well.

I’ve modified my mount-loop script to create loopback devices with a random number of bad blocks. When I use dd to write data to every block, it eventually encounters a bad block, resulting in the following error:

dd: error reading '/dev/mapper/faulty-loop-loop0': Input/output error
0+0 records in
0+0 records out
0 bytes copied, 0.000136647 s, 0.0 kB/s

However, when I use nwipe, it completes without any issues. Does nwipe only detect bad blocks if they fail during the wiping process?

Knogle commented 1 month ago

Okay my bad, now it works fine! Didn't clean up old loopback devices. Screenshot from 2024-10-18 05-55-39

PartialVolume commented 1 month ago

That's a useful feature. How does it achieve one or more bad blocks in a loop device?

Are they contiguous bad blocks or single random location bad blocks?

Knogle commented 1 month ago

That's a useful feature. How does it achieve one or more bad blocks in a loop device?

Are they contiguous bad blocks or single random location bad blocks?

Hey. Yeah it's quite advanced now.

This script simulates bad blocks using the following steps:

  1. Loop Device Setup: It sets up a loop device from a file, which simulates a block device using the losetup command.

  2. Faulty Block Simulation: When using the faultymount or faultymountfs options, the script creates a loop device and simulates faulty blocks by setting up a Device Mapper (DM) table using the dmsetup command. The faulty blocks are passed as arguments (e.g., block numbers or ranges).

    • The Device Mapper table is used to define how blocks are mapped. In this case, some blocks are mapped to an "error" target to simulate failures when those blocks are accessed.
    • The script parses the faulty blocks provided as input (e.g., 500-510) and creates the DM table. The valid blocks are mapped normally, and the specified faulty blocks are mapped as errors, which effectively "corrupts" those blocks.

So you can manually specifiy specific blocks to be bad. faultymount 1G 500,1000 Create a 1G-sized loop device with blocks 500 and 1000 faulty."

Or a whole range of blocks.

faultymountfs 1G 500-510 Same as above but also create a filesystem and mount it, blocks 500 to 510 faulty."

But don't forget, in this case write to the /dev/mapper device, not the underlying loop device directly.

https://github.com/Knogle/mount-loop

Are there maybe any more functions that could be useful?

PartialVolume commented 1 month ago

Thanks for the detailed description, I think I'll fork that and start using it for my own tests.

I can't think of any new features at the moment, but if I do I'll be sure to let you know.