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'm looking for a way to corrupt an ext3 partition safely, so that it can be recovered by fsck on next boot, for testing purposes. Thanks!

share|improve this question

closed as too broad by Falcon Momot, Scott Pack, Ward, RolandoMySQLDBA, larsks Jul 26 '13 at 17:36

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

6  
Are you just trying to force a fsck on reboot? There are safer, easier and better ways to do that. –  MadHatter Jul 26 '13 at 7:12
    
No, I'm not looking for force fsck using "touch /forcefsck" or something. I just want to see how it behaves when the file system is actually corrupt. And I don't worry about data loss in test environment. Thanks! –  shad Jul 26 '13 at 7:23
    
I'd like to emphasize the "seek=10000" that @MadHatter just wrote, please don't omit it from your testing or you're screwed without a full disk backup. You should probably add this as an answer? –  pauska Jul 26 '13 at 8:09
    
OK, I've added it as an answer and deleted it as a comment. –  MadHatter Jul 26 '13 at 9:42
add comment

2 Answers 2

up vote 3 down vote accepted

Use dd to write data from /dev/zero on top of the raw device. Start with a few bytes, e2fsck -p, repeat, increasing the count until you trash something expensive.

dd if=/dev/zero bs=1 count=10 of=/dev/sda1 seek=10000

You increase count= to write more. The seek= is designed to pass over the first 10k of /dev/sda1 so you don't trash the superblock or any of the vital structures at the top of the filesystem. There's nothing wrong with trashing the superblock (given that this is test data), but fsck won't be able to autorecover from loss of the superblock so you'll have to manually point it to a backup superblock. You specifically ask about what the reboot fsck can recover from, so you should know that the -p flag puts fsck into the boot-time "fix what you can safely fix" mode.

If you do this on a data partition, you can avoid the reboot cost, and just keep the trash-fsck cycle going.

share|improve this answer
    
Thanks @MadHatter, that did the trick:) –  shad Jul 26 '13 at 11:38
add comment

You could overwrite the first superblock, for ext3 it would be

dd if=/dev/zero count=1 bs=4096 seek=0 of=/dev/<filesystem to corrupt>

That's a fun thing to recover from. You also don't need to reboot just use fsck interactively.

share|improve this answer
add comment

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