10 Practical fsck Commands to Diagnose and Repair Linux Filesystems
This article presents ten hands‑on examples of using the Linux fsck utility—including checking specific partitions, employing options like -A, -t, -M, -y, -n, and -a—to detect, report, and automatically fix filesystem errors while explaining exit codes and best‑practice recommendations.
Linux fsck is a utility for checking and repairing Linux file systems (ext2, ext3, ext4, etc.). It runs automatically at boot if a file system has not been checked recently, and administrators can invoke it manually on unmounted file systems to avoid data loss.
1. Checking a file system on a disk partition
First, list all available partitions with # parted /dev/sda print:
# parted /dev/sda print
Number Start End Size Type File system Flags
1 1049kB 106MB 105MB primary fat16 diag
2 106MB 15.8GB 15.7GB primary ntfs boot
3 15.8GB 266GB 251GB primary ntfs
4 266GB 500GB 234GB extended
5 266GB 466GB 200GB logical ext4
6 467GB 486GB 18.3GB logical ext2
7 487GB 499GB 12.0GB logical fat32 lbaThen run # fsck /dev/sda6 to check a specific file system:
# fsck /dev/sda6
fsck from util-linux 2.20.1
e2fsck 1.42 (29-Nov-2011)
/dev/sda6: clean, 95/2240224 files, 3793506/4476416 blocks2. File‑system‑specific fsck commands
fsckcalls the appropriate checker (e.g., fsck.ext2, fsck.ext3, fsck.ext4) located in /sbin:
# cd /sbin
# ls fsck*
fsck fsck.cramfs fsck.ext2 fsck.ext3 fsck.ext4 fsck.ext4dev fsck.minix fsck.msdos fsck.nfs fsck.vfatIf the checker for a file system is missing (e.g., fsck.ntfs), fsck reports an error.
# fsck /dev/sda2
fsck from util-linux 2.20.1
fsck: fsck.ntfs: not found
fsck: error 2 while executing fsck.ntfs for /dev/sda23. Using -A to check all file systems in one run
The -A option checks every file system listed in /etc/fstab in the order of their fs_passno values. Filesystems with a pass number of 0 are skipped.
# cat /etc/fstab
##
proc /proc proc nodev,noexec,nosuid 0 0
/dev/sda5 / ext4 errors=remount-ro 0 1
/dev/sda6 /mydata ext2 defaults 0 2
/dev/sda7 /backup vfat defaults 0 3Run the global check: # fsck -A It is recommended to add -R to skip the root file system:
# fsck -AR -y4. Using -t to check only specific file‑system types
The -t option limits the check to the listed types. For example, to check only ext2 file systems: # fsck -AR -t ext2 -y To exclude a type, prefix it with no (e.g., noext2).
5. Avoid running fsck on mounted file systems with -M
Use -M as the default to prevent accidental checks on mounted partitions:
# mount | grep "/dev/sd*"
/dev/sda5 on / type ext4 (rw,errors=remount-ro)
/dev/sda6 on /mydata type ext2 (rw)
/dev/sda7 on /backup type vfat (rw)
# fsck -M /dev/sda7
# echo $?
06. Skipping the title line with -T
The -T option suppresses the introductory line printed by fsck:
# fsck -TAR
...7. Forcing a check with -f even on a clean file system
By default, fsck skips clean file systems. Use -f to force a full check:
# fsck /dev/sda6 -f
...8. Automatically fixing detected problems with -y
The -y option answers “yes” to all prompts, repairing errors without user interaction:
# fsck -y /dev/sda6
...9. Reporting problems without fixing them using -n
The -n option prints detected issues to standard output but makes no changes:
# fsck -n /dev/sda6
...10. Automatic repair of corrupt parts with -a
The -a option behaves like e2fsck -p, automatically fixing safe problems. If a serious issue is found, fsck exits with code 4.
# fsck -a -AR
...For more severe inconsistencies, use -y to force full automatic repair.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
