Simulate a faulty block device with read errors?

前端 未结 4 1192
离开以前
离开以前 2020-12-08 16:17

I\'m looking for an easier way to test my application against faulty block devices that generate i/o read errors when certain blocks are read. Trying to use a physical hard

4条回答
  •  遥遥无期
    2020-12-08 16:56

    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/.

    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".

提交回复
热议问题