Simulate a faulty block device with read errors?
It's not a loopback device you're looking for, but rather device-mapper.
Use dmsetup
to create a device backed by the "error" target. It will show up in /dev/mapper/<name>
.
Page 7 of the Device mapper presentation (PDF) has exactly what you're looking for:
dmsetup create bad_disk << EOF
0 8 linear /dev/sdb1 0
8 1 error
9 204791 linear /dev/sdb1 9
EOF
Or leave out the sdb1
parts to and put the "error" target as the device for blocks 0 - 8 (instead of sdb1
) to make a pure error disk.
See also The Device Mapper appendix from "RHEL 5 Logical Volume Manager Administration".
There's also a flakey
target - a combo of linear
and error
that sometimes succeeds. Also a delay
to introduce intentional delays for testing.
It seems like Linux's built-in fault injection capabilities would be a good idea to use.
Blog: http://blog.wpkg.org/2007/11/08/using-fault-injection/
Reference: https://www.kernel.org/doc/Documentation/fault-injection/fault-injection.txt