Of course, it's better to back up the suspect one.
Of course, it's better to back up the suspect one.
That strategy adds O(n^2) reads on top of O(n) writes, though.
Even reads don't come for free on modern multi-level cell NAND (due to read disturb), and for just a thousand blocks, you'd end up reading the first block a million times.
That's to say nothing of the time this would take.
Reading that back (either the full device or a random sample) should pretty quickly identify whether things are still in their expected location.
A too-simple scheme is likely to be detected (and bypassed!) by the firmware a nearly no time.
Conceptually,
# tee /dev/DEVICE </dev/random | sha256sum
# echo 1 > /proc/sys/vm/drop_caches
# sha256sum /dev/DEVICE
though I wouldn't expect this exact command sequence to work unless tee's buffer size divides /dev/DEVICE's capacity and tee errors out writing past the end of /dev/DEVICE before writing to stdout.the drive size divided by 4MB, so dd with bs=4M and fixed count
(with oflag=direct you don't even need to drop caches)
The "write the block #'s to the given block" would help identify where a fraudulent device goes wrong.
But for just checking if a device is storing data 100% correctly then your way would probably be more robust. :)