Check file systems
Bugs, power failures, and mechanical problems can all cause data structures on a file system to become corrupted and cause severe data loss. To check and repair Linux file systems, you can use the fsck (stands for file system check ) command. This command performs a sequential investigation of the file system. If it finds a misplaced directory or a file with no inode number, it places them in the /lost+found directory.
Linux runs fsck automatically at startup on partitions that are marked for it in /etc/fstab. You can also run the fsck utility manually. To do this, run the fsck command along with the name of the file system you would like to check:
fsck is not usually used on a mounted file system because it could corrupt the file system. It is recommended to unmount the file system before running this command.
The fsck utility supports a couple of options:
- -A option – check all the file systems marked to be checked in /etc/fstab. Normally used in system startup scripts.
- -t option – normally, fsck determines the file system type automatically. You can force the type with the -t FSTYPE option.
- -N option – display what would be checked but don’t actually perform the check. This option is useful to see what would happen if you performed the check.
- -R option – checks all file systems except the root directory
- -V option – displays verbose output.
fsck is actually a front end to other tools, such as e2fsck (aka fsck.ext2 , fsck.ext3, and fsck.ext4) or XFS’s xfs_check and xfs_repair.