How to purposely corrupt a linux filesystem
william chan
Posts: 1,326
I would like to corrupt a Centos 5 or Centos 6 filesystem in such a way that upon booting the OS would detect that the filesystem is inconsistent and then drop to a command prompt to allow user to correct the filesystem manually.
I tried
a. powering off the computer abruptly at different times
b. left a file open after writing to it and then power off the computer
both didn't work as the OS considers the problems as minor and would then auto-correct them from the journal.
Comments
Recovering from this might be a challenge though. You'd have to get familiar with grub commands. Something I still haven't been motivated enough to do myself.
This is because I am working on a system that tries to recover from such a corruption without human intervention.
I need a corrupted filesystem to let the system try recover it.
It depends on the storage medium.
What is your medium?
Theres always the option of putting it in the microwave for 1 second? lol. (dont do that)
For Centos 6 is a Sandisk 16GB USB Key
It has 2 partitions, which are /dev/sda1 mounted to /boot and
/dev/sda2 mounted to /
Normally it is the /dev/sda2 that gets corrupted because it is the one being used for writing.
Any ideas on how to corrupt /dev/sda2 ?
That said, disabling the journaling feature would do the trick I guess.
EDIT: I suppose just arbitrary block writes to the partition, bypassing the volume's filesystem, will mess it up even with journaling enabled. Be warned, it won't be recoverable doing this method.
Be warned, it won't be recoverable doing this method.
Ok lets try this method.
Do you have the specific commands to block write a small part of the partition?
Sorry as i am not very good at linux low level commands.
$ sudo dd if=/dev/zero of=/dev/sdh3 bs=1k seek=10 count=4k
Not sure if "sudo" is used in Centos. It's for raising your privilege for the duration of the command issued. You have to enter your login password once. Nothing stopping you smashing any valid volume, mounted or not, so be careful to target the right one!
"dd" is the block copy command.
"if=/dev/zero" means source data of unlimited nulls. It can be any file. Defaults to console input if not set.
"of=/dev/sdh3" means destination file, in this case my spare partition.
"bs" for virtual block size used in the copying process.
"seek" for starting virtual block number in destination.
"count" for number of virtual blocks to copy.