The goal. simulate data corruption on a virtual block device to demonstatre data integrity features of ZFS.
The Setup. Ubuntu 20.04 LTS with zfs installed
zpool create tank mirror disk0 disk1
echo “gibberish” > test.txt
md5sum tets.txt
test.txt
zfs snap tank@snap
zdb -ddddd tank@snap
…reveals the block where our test file is 0:1234567:8910 or something like that
dd if=/dev/disk0.img bs=512 skip=$(((0x1234567 / 512) + (0x400000 / 512))) count=1 | hexdump -C
…Shows the clear test of or test.txt file
…This should be the line that corrupts the file
dd if=/dev/urandom of=/dev/disk0.img bs=512 seek=$(((0x1234567 / 512) + (0x400000 / 512))) count=1
…that looks like that did it lets do it to the other disk
dd if=/dev/urandom of=/dev/disk1.img bs=512 seek=$(((0x1234567 / 512) + (0x400000 / 512))) count=1
…okay now we check the img files
dd if=/dev/disk0.img bs=512 skip=$(((0x1234567 / 512) + (0x400000 / 512))) count=1 | hexdump -C
… that did it! lets run the checksum
ITS THE SAME!
HOW?
HOW DO YOU CORRUPT A SECTOR ON A DISK AND NOT DAMAGE THE DATA THAT’S ON IT!?
zpool scrub tank
zpool status tank
…DEGRADED
permanent errors on test.txt
cat test.txt
…reveals the original text of the file
md5sum test.txt
… checksum unchanged
Conclusion. zfs detected that there was corrupted data, but fixed it before I could calculate the sum OR Linux is doing something in the background that I am not aware of OR I’m missing something that’s obvious, but can’t figure out or understand. Can anybody with the appropriate experience point me in the right direction?
If you want to view the basis for what I’m doing check out this awesome article by Bryan Erlich called " Causing ZFS corruption for fun and profit (and quality assurance purposes)" It’s hosted by datto engineering.