FreeKB - 0 Check a file system for errors in Linux
Check a file system for errors in Linux

The FSCK (file system check) command checks a file system for errors. 

Important! You need to unmount the filesystem before checking filesystem for errors. You cannot unmount the / (root) filesystem.

In this example, the /dev/sda2 partition is unmounted, then checked for errors, and then remounted. If fsck is able to locate corrupted files, the files will be placed in the /lost+found directory.

~]# umount /dev/sda2
~]# fsck -C /dev/sda2
~]# mount /dev/sda2


Full scan

By default, fsck will do a quick scan. Using the -f (full) option makes fsck run a full scan.

~]# umount /dev/sda2
~]# fsck -f /dev/sda2
~]# mount /dev/sda2


Check file systems in /etc/fstab

The -A option can be used to check every filesystem in /etc/fstab that has a 1 or 2 in the sixth field, such as: /dev/sda2  /home  ext4  defaults  0  1. The -R option skips the / (root) filesystem, just in case the / (root) filesystem has read/write.

~]# umount /dev/sda2
~]# fsck -AR
~]# mount /dev/sda2


Disable interactive prompt

By default, fsck has an interactive prompt, where you will be asked to press Y to fix an issue or N to ignore an issue. The -a or -y options can be used to disable the interactive prompt. This is useful when writing shell scripts.

~]# umount /dev/sda2
~]# fsck -y /dev/sda2
~]# mount /dev/sda2


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter 0767e in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |