I want to check the consistency of a file system and fix the errors. What are the safety considerations in running
fsck -f -y on a file system?
Neither flag is defined in the top-level
fsck documentation, so the most general answer is that it depends on the filesystem-specific fsck command you are using.
For many fs-specific commands, in particular
e2fsckfor ext2/ext3/ext4 file systems, the
-foption is used to "Force checking even if the file system seems clean." This can make the command slower but is not expected to cause any harmful side effects in itself.
-yflag is described in the
fsck(8)man page as follows (emphasis mine):
For some filesystem-specific checkers, the
-yoption will cause the fs-specific fsck to always attempt to fix any detected filesystem corruption automatically. Sometimes an expert may be able to do better driving the fsck manually.
This implies that there is some risk involved: in some cases, the command may perform actions that would not be advised by an expert administrator.
e2fsckcommand has an alternative,
-p, which can be used to "automatically fix any filesystem problems that can be safely fixed without human intervention." The command will exit with an error if any issues are detected that require further intervention.