Debian Filesystem Repair Guide
Filesystem corruption in Debian can occur due to improper shutdowns, hardware failures, or software bugs. Below are structured steps to diagnose and repair filesystem issues, ensuring data safety throughout the process.
Before starting any repair, back up all important data to an external drive or network location. Repair operations (especially fsck) can sometimes lead to data loss if the filesystem is severely damaged. Use tools like rsync, tar, or external USB drives for backup.
journalctl or /var/log/syslog to identify filesystem errors. For example:journalctl -xe | grep -i "filesystem\|error\|fail"
Look for messages indicating corrupted inodes, bad blocks, or unmountable filesystems.df -h to see mounted filesystems. If a partition is listed as “ro” (read-only), it may have encountered errors and forced a read-only mount to prevent further damage.To safely repair a filesystem, it must be unmounted. Replace /dev/sdXY with the correct partition (e.g., /dev/sda1 for the root partition or /dev/sdb1 for a secondary drive):
sudo umount /dev/sdXY
If the partition is the root filesystem (/), you’ll need to boot into recovery mode or use a Live CD/USB to unmount it.
The fsck (Filesystem Consistency Check) tool is the primary utility for repairing Debian filesystems. Use the following commands based on your filesystem type:
sudo fsck.ext4 -p /dev/sdXY
-p: Automatically repair errors without prompting (safe for most cases).ext4 with ext2 or ext3 if your filesystem uses a different type.Use the corresponding tool (e.g., xfs_repair for XFS, btrfs check for Btrfs). For example:
sudo xfs_repair /dev/sdXY # For XFS filesystems
If fsck doesn’t find errors but issues persist, run a full check with -f:
sudo fsck.ext4 -f /dev/sdXY
This forces fsck to scan the entire filesystem, even if it appears clean.
If the root filesystem (/) is corrupted and you can’t unmount it, boot into recovery mode:
mount -o remount,rw /
fsck on the root partition (usually /dev/sda1 or /dev/nvme0n1p2):fsck -fy /
reboot
Filesystem errors can be caused by failing hardware. Use smartctl (from the smartmontools package) to check your disk’s health:
sudo apt install smartmontools
sudo smartctl -a /dev/sdX # Replace with your disk device (e.g., /dev/sda)
Look for “FAILED” attributes or reallocated sectors, which indicate physical damage. If the disk is failing, back up data immediately and replace the disk.
If the issue is caused by incorrect entries in /etc/fstab (e.g., wrong UUID, missing partition), fix the file and reboot:
mount -o remount,rw /
/etc/fstab with a text editor (e.g., nano):nano /etc/fstab
blkid to get correct UUIDs).reboot
If you can’t boot into Debian, use a Debian Live CD/USB to repair the filesystem:
fsck on the affected partition (replace /dev/sdXY with your partition):sudo fsck.ext4 -p /dev/sdXY
If none of the above steps resolve the issue, or if you suspect physical disk failure, contact a data recovery professional. Tools like TestDisk (for partition recovery) or extundelete (for deleted files) can help salvage data, but they work best on minimally-damaged filesystems.
By following these steps, you can systematically diagnose and repair most Debian filesystem issues while minimizing data loss. Always prioritize backups before attempting repairs.