CentOS – Automatically run fsck on boot into recovery

centos5fsck

I'm automating a process to upgrade my ext3 filesystem to ext4. Following the instructions from here I'm able to successfully migrate my filesystem. I've scripted the vast majority of the work, and it's working pretty nicely.

However, the final step in the migration is running fsck on the unmounted partition. The issue is that I'm trying to migrate the root partition, which can't be unmounted during normal operations. So to run fsck, I need to boot into recovery mode, enter the root password, and run fsck that way.

Is it possible to configure CentOS to automatically run fsck on boot into recovery?

Best Answer

Why running an automatic fsck on system start won't work? fsck -pvfDC0 isn't doing anything special, just optimising the directories (the -D option) -- that's only part of ext4 file system. Extents is what makes it ext4. Just make it do fsck and reboot:

touch /forcefsck
shutdown -r now

Ext4 driver can read ext2, ext3 and ext4 file system, it's all the same for it. So yes, making sure your system is can boot from ext4 is important, having pure ext4 fs isn't.

That being said, I'd still go for creating a new partition as ext4 and copying data over -- it will be faster (access to partition, not the migration) and safer.