Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I simulate ext3 filesystem corruption?

I would like to simulate filesystem corruption for the purpose of testing how our embedded systems react to it and ultimately have them fail as gracefully as possible. We use different kinds of block device emulated flash storage for data which is modified often and unsuitable for storage in NAND/NOR.

Since I have a pretty good idea of how often data is modified in different parts of the file tree and where sensitive data is stored. I would like to inject errors in specific areas and not just randomly.

In cases of emergency we use fsck -y as a sort of last resort in order to attempt to bring the system up and report that is in a very bad state. I would very much like to cause errors which would trigger fsck to attempt repairs in order to study the effect on the systems capability to come back up.

dd if=/dev/random is not precise enough for my purpose since it can't easily be used to inject controlled errors. Are there any other tools or methods which fit my needs better or do I have to invent my own?

like image 876
David Holm Avatar asked Sep 26 '08 15:09

David Holm


People also ask

What causes file system corruption?

The most common causes of file system corruption are improper shutdown, startup procedures, hardware failures, virus attack, or other errors. The hardware failures could be a bad sector, a bad disk controller, or a power outage.

What causes filesystem corruption Linux?

generally speaking file system corruption is caused by power loss during a write operation, or in a case where there are cached writes that haven't yet been written to disk.


2 Answers

If you already know what to modify, dd can read a file containing the bytes you want to write, and you tell it where to write them.

To figure out where to write, debugfs from the e2fsprogs package could help you.

like image 64
Nicolas Avatar answered Oct 14 '22 07:10

Nicolas


It should be possible to use a Linux filesystem image fuzzer to cause corruption:

  • e2fuzz from e2fsprogs
  • http://people.redhat.com/sgrubb/files/fsfuzzer-0.7.tar.gz
  • http://projects.info-pull.com/mokb/fsfuzzer-0.6.tgz
  • http://www.cccmz.de/~snakebyte/fsfuzzer-0.6-lmh2.tar.bz2
  • http://thread.gmane.org/gmane.comp.file-systems.ext4/32167 (uses zzuf)

or one of the Linux disk fault injection techniques (e.g. dm-flakey in corruption mode) described in https://unix.stackexchange.com/a/144200 .

like image 26
Anon Avatar answered Oct 14 '22 08:10

Anon