Andrew Mercer
on this page

Run fsck on an unmounted filesystem (or a read-only one). Checking a mounted filesystem can corrupt it. Use a live/rescue environment for the root filesystem.

Identify the filesystem type first

lsblk -f /dev/sdc
sudo blkid /dev/sdc1
sudo parted /dev/sdc print

Check

sudo fsck /dev/sdc1                # picks the right checker via blkid
sudo fsck.ext4 -f /dev/sdc1        # -f forces a check even if marked clean
sudo fsck -n /dev/sdc1             # read-only: report problems, change nothing
sudo fsck -y /dev/sdc1             # answer yes to all repair prompts (after you have a backup)
sudo fsck.msdos -a -w /dev/sdd1    # FAT: auto-repair, write changes
sudo xfs_repair -n /dev/sdc1       # XFS uses xfs_repair, not fsck

Practise on a scratch disk

To rehearse recovery, corrupt the start of a throwaway partition and repair it:

sudo dd if=/dev/zero of=/dev/sdX1 bs=1k count=1024     # DESTRUCTIVE: wipes the first MB of that partition
sudo fsck -y /dev/sdX1

Troubleshooting: "The superblock could not be read or does not describe a valid ext2/ext3/ext4 filesystem"

ext2fs_open2: Bad magic number in super-block
fsck.ext2: Superblock invalid, trying backup blocks...
  • Confirm you pointed at the partition (/dev/sdc1), not the whole disk (/dev/sdc), and that it really is ext-family.
  • ext filesystems keep backup superblocks. List where they are without changing anything:
sudo mke2fs -n /dev/sdc1
Superblock backups stored on blocks:
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 4096000

(-n is essential: it means "do nothing, just show what you would do". Without it, mke2fs creates a new filesystem and erases the old.) The block numbers depend on the filesystem's block size, so use the list your own filesystem prints.

  • Then check using a backup superblock:
sudo e2fsck -b 32768 /dev/sdc1
  • If the partition itself is the problem, try mounting after repair to a scratch dir (sudo mount /dev/sdc1 /mnt/sdc) and copy data off, or image the disk with ddrescue before attempting more repairs.

Related: mount, smartmontools, wipefs.