Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulate a faulty block device with read errors?

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 drive with known bad blocks is a pain and I would like to find a software solution if one exists.

I did find the Linux Disk Failure Simulation Driver which allows creating an interface that can be configured to generate errors when certain ranges of blocks are read, but it is for the 2.4 Linux Kernel and hasn't been updated for 2.6.

What would be perfect would be an losetup and loop driver that also allowed you to configure it to return read errors when attempting to read from a given set of blocks.

like image 770
SteveG Avatar asked Dec 08 '09 23:12

SteveG


People also ask

What are the possible causes for the device has a bad block?

Possible Causes for the Device Has a Bad Block Issue. You may be curious about the possible causes of this problem. According to the reports we have explored, here are possible causes for the Device DeviceHarddisk0DR0 has a Bad Block issue: There are bad sectors on the hard drive. Or any corrupted file system appears in the health sector.

Is it possible to return a read error from a block?

What would be perfect would be an losetup and loop driver that also allowed you to configure it to return read errors when attempting to read from a given set of blocks. Show activity on this post. 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.

How to test if hard disk has a bad block error?

Here is a full guide as follow: 1 Download this tool and install it. Then launch this tool to enter the main interface. ... 2 Select the hard disk with the device harddisk0 dr0 has a bad block error and select the Surface Test feature from the left action panel. 3 Inside the disk surface test window, click on the Start Now button. More items...

How to fix “the device \device\harddisk0\DR0 has a bad block” error?

CHKDSK scan is the most common way to fix “the Device \Device\Harddisk0\DR0 has a Bad Block” issue. Here is a full guide on using this built-in utility to fix bad hard disk block error. Step 1. Press Win + R key to call out a Run dialog box. Then type “ cmd” in the box and press Ctrl + Shift + Enter to open up an elevated Command Prompt.


2 Answers

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.

like image 151
Peter Cordes Avatar answered Sep 23 '22 03:09

Peter Cordes


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

like image 26
David Foster Avatar answered Sep 23 '22 03:09

David Foster