Hasty Briefsbeta

Bilingual

Corrupting a ZFS File on Purpose

9 hours ago
  • #corruption
  • #filesystem
  • #ZFS
  • ZFS normally prevents corruption, but developers sometimes need controlled corruption for testing self-healing and observing system responses.
  • Use `zinject` for quick corruption without understanding the underlying disk layout; it injects checksum errors into live pools.
  • For educational purposes, manually corrupt a file on a throwaway pool built from file-based 'disks' using `dd` and hex editors.
  • The process involves mapping a file to its DVA (Data Virtual Address), adjusting for ZFS's reserved 4 MiB area, and calculating sector offsets.
  • Compression must be turned off (`zfs set compression=off`) to ensure predictable block sizes and avoid confusion with compressed data.
  • In RAIDZ2, the block mapping involves splitting data across child devices with parity; manually calculating column offsets is essential for targeted corruption.
  • After exporting the pool and corrupting the backing file with `dd conv=notrunc`, importing and scrubbing reveals errors: single vdevs show permanent errors, RAIDZ2 heals via parity.