# FSCK

====================================================================================

### FSCK (File System Consistency Check)

\------------------------------------------------------------------------------------------------------------------------------------------------

#### What does FSCK do?

`fsck` (file system consistency check) is a system utility used to check and repair filesystems. FSCK is made up of various tools that are made to handle different filesystem types, these are stored within /usr/sbin:

```
lrwxrwxrwx 1 root root         8 Mar 23  2022 dosfsck -> fsck.fat
-rwxr-xr-x 1 root root    360280 Jun  1  2022 e2fsck
-rwxr-xr-x 1 root root     43440 Apr  9 15:32 fsck
-rwxr-xr-x 1 root root      1185 Feb 24  2022 fsck.btrfs
-rwxr-xr-x 1 root root     31168 Apr  9 15:32 fsck.cramfs
lrwxrwxrwx 1 root root         6 Jun  1  2022 fsck.ext2 -> e2fsck
lrwxrwxrwx 1 root root         6 Jun  1  2022 fsck.ext3 -> e2fsck
lrwxrwxrwx 1 root root         6 Jun  1  2022 fsck.ext4 -> e2fsck
-rwxr-xr-x 1 root root     84360 Mar 23  2022 fsck.fat
-rwxr-xr-x 1 root root     55712 Apr  9 15:32 fsck.minix
lrwxrwxrwx 1 root root         8 Mar 23  2022 fsck.msdos -> fsck.fat
lrwxrwxrwx 1 root root         8 Mar 23  2022 fsck.vfat -> fsck.fat
-rwxr-xr-x 1 root root      1968 Feb  9  2022 fsck.xfs
-rwxr-xr-x 1 root root     51592 Nov  1  2022 ntfsclone
-rwxr-xr-x 1 root root     35200 Nov  1  2022 ntfscp
```

#### Purpose of fsck

- Checking Filesystem Integrity: It scans the filesystem for inconsistencies and potential errors, such as corrupted metadata, lost clusters, and bad sectors.
- Repairing Errors: `fsck` can fix detected issues to prevent data loss and improve system stability.

\------------------------------------------------------------------------------------------------------------------------------------------------

<p class="callout warning">You can only run a filesystem check on an unmounted disk.</p>

Scanning a specific disk (optional repair):

```
fsck -t ext4 /dev/sda2
```

Scanning all disks (optional repair)

```
fsck -A
```

##### FSCK Options:

<table border="1" id="bkmrk--a-check-all-filesys" style="border-collapse: collapse; width: 100%;"><colgroup><col style="width: 50%;"></col><col style="width: 50%;"></col></colgroup><tbody><tr><td>-A</td><td>Check all filesystems.</td></tr><tr><td>-t \[option\]</td><td>Specify filesystem type</td></tr><tr><td>-y</td><td>Automatically attempt to fix any errors without user prompt</td></tr><tr><td>-n</td><td>Do not attempt to repair</td></tr><tr><td>-f</td><td>Forces a check, even if the filesystem appears to be fine</td></tr><tr><td>-T </td><td>Skip mounted filesystems</td></tr><tr><td>-R</td><td>Skip the root filesystem</td></tr></tbody></table>

\------------------------------------------------------------------------------------------------------------------------------------------------

#### FSCK on boot

FSCK can be configured to run for each filesystem when the server boots. [For more info see here.](https://bookstack.b4sed.xyz/link/160#bkmrk-filesystem%3A-the-bloc)

====================================================================================