fsck Command

Check and repair filesystem inconsistencies to ensure data integrity and fix errors that may occur due to improper shutdowns or hardware issues.

Syntax

fsck [options] [device] fsck -t type [options] [device] fsck [options] -A fsck [options] -R

The fsck command checks and repairs filesystem inconsistencies, ensuring data integrity and fixing errors that may occur due to improper shutdowns or hardware issues.

Basic Usage

Check a specific filesystem

# Check a specific device fsck /dev/sda1 fsck /dev/nvme0n1p1 # Check with specific filesystem type fsck -t ext4 /dev/sda1 fsck -t xfs /dev/sdb1

Check a specific device or partition for filesystem errors

Check all filesystems

# Check all filesystems in /etc/fstab fsck -A # Check all filesystems except root fsck -AR # Check all filesystems with specific type fsck -t ext4 -A

Check all filesystems defined in the system configuration

Interactive and automatic modes

# Interactive mode (default) fsck /dev/sda1 # Automatic mode (non-interactive) fsck -y /dev/sda1 # Automatic mode with no questions fsck -a /dev/sda1

Choose between interactive repair or automatic error correction

Common Options

Filesystem type options

# Specify filesystem type fsck -t ext4 /dev/sda1 fsck -t xfs /dev/sdb1 fsck -t ntfs /dev/sdc1 # Auto-detect filesystem type fsck /dev/sda1

Specify or auto-detect the filesystem type for checking

Repair options

# Automatic repair (yes to all) fsck -y /dev/sda1 # No repair, just check fsck -n /dev/sda1 # Force check even if clean fsck -f /dev/sda1 # Skip mounted filesystems fsck -M

Control how fsck handles repairs and checks

Output and logging

# Verbose output fsck -v /dev/sda1 # Show progress bar fsck -C /dev/sda1 # Print version and exit fsck -V

Control the amount of information displayed during checking

Practical Examples

System administration tasks

# Check root filesystem (from recovery mode) fsck -f / # Check all ext4 filesystems fsck -t ext4 -A # Check specific partition with verbose output fsck -v -t ext4 /dev/sda2 # Force check of clean filesystem fsck -f /dev/sda1

Common administrative tasks using fsck

Recovery scenarios

# Check after improper shutdown fsck -y /dev/sda1 # Check with automatic repair fsck -a /dev/sda1 # Check multiple partitions for partition in /dev/sda1 /dev/sda2 /dev/sda3; do echo "Checking $partition..." fsck -y $partition done

Recovery procedures for damaged filesystems

Maintenance and monitoring

# Check filesystem health fsck -n /dev/sda1 # Check with progress display fsck -C -t ext4 /dev/sda1 # Check all filesystems except root fsck -AR

Routine maintenance and health checking

Best Practices

fsck Best Practices
  • Always unmount filesystems before running fsck
  • Use recovery mode or live CD for root filesystem
  • Backup important data before major repairs
  • Use appropriate filesystem type detection
  • Monitor fsck output for critical errors
  • Run fsck after improper shutdowns
Common Pitfalls
  • Mounted filesystems - Never run fsck on mounted filesystems
  • Data loss - Automatic repair may result in data loss
  • Wrong device - Double-check device names before running
  • Interruption - Don't interrupt fsck during operation
  • Multiple instances - Don't run multiple fsck instances simultaneously

See also