I have a script that mounts /dev/sdc1 to /home. I do not know the state of /dev/sdc1 in advance, it could possibly be "dirty". Do I need to run fsck.ext4 before mounting the filesystem, or has mount some checks that will prevent a "dirty" filesystem to be mounted an possibly corrupting data?

Or even better, is there some way to tell mount to check the filesystem when mounting ?


There used to be an option to check ext2 filesystems at mount time, but that is no longer supported. Nowadays boot scripts check filesystems before mounting them, and your scripts should do so too. Mounting a filesystem does still check things to make sure it's safe to mount the filesystem; but it won't fix anything (beyond replaying the journal on ext3 or ext4 filesystems).

You should use fsck -p to perform these checks; the -p option tells e2fsck to fix anything that can be fixed safely without human intervention. If an error occurs requiring human intervention, e2fsck will exit with an appropriate exit code, and your script needs to take those into account as well.

See the mount(8), fsck(8) and fsck.ext4(8) manpages for more details. You might find the source code of ext4_fill_super() interesting; that's the code which mounts an ext4 filesystem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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