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?
1 Answer
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
e2fsck
for ext2/ext3/ext4 file systems, the-f
option 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.The
-y
flag is described in thefsck(8)
man page as follows (emphasis mine):For some filesystem-specific checkers, the
-y
option 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.
The
e2fsck
command 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.
sudo fsck -N -y
to run it without making any changes first, if you are concerned. manpages.ubuntu.com/manpages/bionic/man8/fsck.8.html is the general fsck man page; subordinate man pages exist for filesystem-specific checkers such as manpages.ubuntu.com/manpages/bionic/man8/fsck.ext3.8.html for ext2/3/4 filesystems.