JustGeek.in Tech, simplified.

how to run fsck on linux

FSCK (File System Consistency Check) is a system utility in Linux used to check and repair filesystem inconsistencies. It examines your filesystem for potential problems like corrupted files, broken links, or incorrect directory structures. It basically,performs a health check-up on your filesystem.

Common scenarios where you might need fsck:

After an unexpected system shutdown or power failure When your system isn’t booting properly If you notice files becoming corrupted As part of regular system maintenance

How to run fsck on Linux

Different Methods to Run fsck

Method 1: Direct Command Line Usage

Before running fsck on any partition, ensure it’s not mounted. This is crucial to prevent data corruption.

First, unmount the partition:

sudo umount /dev/sdb

It’s recommended to start with a dry run, which shows potential errors without making any changes:

sudo fsck -N /dev/sdb1

After reviewing the issues, you can proceed with the actual repair. There are two main options:

  1. Using -y to automatically answer “yes” to all prompts:
    sudo fsck -y /dev/sdb1
    
  2. Using -p for a safer automatic repair that only fixes issues that can be safely resolved:
    sudo fsck -p /dev/sdb1
    

Once repairs are complete, remount the partition:

sudo mount /dev/sdb1

Method 2: Force Check on Reboot

You can trigger fsck to run automatically during the next system boot:

  1. Create a force check file:
    sudo touch /forcefsck
    
  2. Reboot your system. fsck will run automatically during startup.
  3. After reboot, verify that the /forcefsck file has been automatically removed.

Method 3: Configure Regular Checks via /etc/fstab

You can configure automatic filesystem checks through the /etc/fstab file. Here’s an example configuration:

# [File System] [Mount Point] [File System Type] [Options] [Dump] [PASS]
/dev/sda1       /             ext4               defaults  0      1
/dev/sda2       /home         ext4               defaults  0      2

The last number (PASS) determines the fsck check order:

  • 0: Skip filesystem check
  • 1: Check first (typically used for root filesystem)
  • 2: Check after priority 1 filesystems (used for other filesystems)

Best practices:

  • Root filesystem (/) should have PASS value 1
  • Other filesystems should have PASS value 2
  • Set PASS to 0 for filesystems you don’t want to check

Important Notes

  • Always backup important data before running filesystem repairs
  • Never run fsck on mounted filesystems
  • For system partitions, it’s safer to run fsck from a live USB/CD
  • Modern journaling filesystems like ext4 typically require fsck less frequently

For more Linux tutorials and tips, check out our Linux section.