How to corrupt an ext3 partition so that it will undergo fsck to fix automatically at boot? [closed]

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.


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.