In search for a way to simulate disk errors, I learned about the device-mapper targets dm-flakey and dm-delay, which can be used to simulate a flakey or slow disk, respectively.
Simply wrap the disk (with an already created file system) in either device to simulate I/O errors or delays.
For example to simulate errors on sdb 10% of the time:
# dmsetup create sdb-flakey --table="0 `blockdev --getsize /dev/sdb` flakey /dev/sdb 0 9 1
# mount /dev/mapper/sdb-flakey /mnt/flakey
# <testing>
# umount /mnt/flakey/
# dmsetup remove sdb-flakey
or to add a 500ms delay on sdb:
dmsetup create d0 --table="0 `blockdev --getsize /dev/sdb` delay /dev/sdb 0 500"
Further documention:
- https://www.kernel.org/doc/Documentation/device-mapper/dm-flakey.txt
- https://www.kernel.org/doc/Documentation/device-mapper/delay.txt