Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a script where fsck is called in case filesystem is in "error" state only. I'd like to tests it. Unfortunatelly I don't know how to force "error" state on ext3 partition.

The only one idea I have is run fsck on mounted partition first. AS soon as there is warning that filesystem can be damaged, I expect it can help. Need to try. Meanwhile, may be anyone knows answer already?

share|improve this question

migrated from stackoverflow.com Jun 30 '11 at 12:25

This question came from our site for professional and enthusiast programmers.

2 Answers 2

Well, here it is: debugfs -w -R "ssv state 2" /dev/sda1

debugfs is part of e2fsprogs package intended for low level access to ext2/3 filesystems.

-w - work in r/w;
-R - run one command and exit;
ssv - set superblock value, self-describing;
state - just a name of the field containing state of filesystem.

Codes are:

0 - not clean
1 - clean
2 - not clean with errors
share|improve this answer

I fiddled with this briefly in a VM. My initial thought was to nuke the partition's primary superblock. Doing so does not cause dumpe2fs to report a "filesystem state" of "error" but it does (obviously) break your partition ("Bad magic number in super-block") ... so maybe that's all you need for your testing. Running fsck against a partition in this state and inspecting the value of $? will report a status of 8 (operational error).

Anyway, this is dangerous and I would not advise doing it on any system where you have data you care about. Try it in a VM like I did.

You can get some information about the file system like this:

dumpe2fs /dev/sda1 | egrep "state|superblock|Block size"

You will see that the filesystem has a primary superblock, and some number of backup superblocks. If you are prepared to break things, take note of a few things in that output:

  • "Block size: X": take note of X
  • "Primary superblock at Y": take note Y
  • "Backup superblock at Z": take note of at least one Z

Now destroy your primary superblock:

dd if=/dev/zero of=/dev/sda1 bs=X count=1 seek=Y

Congratulations! Your filesystem is now broken.

Unmount it if it is mounted:

umount /dev/sda1

Then run fsck specifying the location of one of the backup superblocks noted earlier:

fsck -b Z /dev/sda1

Now mount /dev/sda1 somewhere, and you should be back in business.

share|improve this answer
    
Thank You for investigation. Actually I need "error" state because my script use dumpe2fs. Presence of real damage to filesystem doesn't matter, only state matters. –  user822834 Jul 1 '11 at 5:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.