Instead of cryptsetup + shred, I used cryptsetup + pv (cat should work instead of pv too, but it would not be giving any progress info) and pointed stdin to /dev/zero:
cryptsetup open /dev/device eld --type plain --cipher aes-xts-plain64
</dev/zero pv >/dev/mapper/eld
This has the advantage (as compared to dd) that no obscure arguments need to be specified and performance over a SATA 3.3 6Gb/s link is good (>200MiB/s).
pv still failed when the end was reached, but I have checked that nevertheless it did overwrite the whole logical device with zeroes. Which means dm-crypt overwrote the whole hard drive with pseudo-random bytes.
Now hard drive errors can be checked in at least two ways:
1.Looking for degraded SMART data (like reallocated sectors) in the output of
smartctl -a /dev/device
2.Reading data from /dev/mapper/eld and checking that all read bytes have value zero. Running cmp command from diffutils to do this comparison:
cmp -l -b /dev/zero /dev/mapper/eld
It will either print byte address of the first mismatch and exit with error, or it won't find any mismatch and then it will print "cmp EOF on /dev/mapper/eld ..." (and still exit with error).
Mismatch means that either hard drive has a permanent failure of record at that position, or it can be a random error that will not repeat exactly at the same position.
On the first run of cmp, I indeed got an error already after 8 seconds, which I was very surprised to see. SMART data did not show any degradation, and syslog didn't reveal any error messages regarding the hard drive.
I then tried to run the cmp command again to check if the record error is real, but the mismatch at that position didn't occur again. It was some random error in the whole read+evaluate process. So don't rely on a single run of cmp command; in case a mismatch is found, run it again. If the error disappears, then ignore the first mismatch or maybe try once again. If the error persists, then return the hard drive to the seller as it is most probably defective and its degradation in time may be faster compared to a healthy hard drive.
.