화. 8월 5th, 2025

File system corruption can strike any Linux system unexpectedly – from sudden power loss to faulty hardware. Don’t panic! This guide walks you through detection and repair with practical steps.

🚨 Symptoms of Corruption

  • “Input/output error” messages
  • Unmountable drives or refusal to mount
  • Missing files/folders
  • System freezing during disk access
  • dmesg logs showing “EXT4-fs error” or similar
  • Applications crashing when accessing files

🔒 Critical First Steps

  1. STOP WRITING DATA: Avoid further writes to prevent permanent loss.
  2. Unmount the partition:
    sudo umount /dev/sdXY  # Replace sdXY with your partition (e.g., sda1)  
  3. Use a Live USB: If the OS won’t boot, use Ubuntu Live USB to work offline.

🔧 Repair Tools by File System Type

File System Repair Tool Command Example
EXT2/3/4 fsck sudo fsck -y /dev/sdXY
XFS xfs_repair sudo xfs_repair /dev/sdXY
Btrfs btrfs check sudo btrfs check --repair /dev/sdXY
FAT/NTFS ntfsfix sudo ntfsfix /dev/sdXY

⚙️ Step-by-Step Repair (EXT4 Example)

  1. Force a filesystem check on reboot:
    sudo touch /forcefsck  # For systems that can still boot  
    sudo reboot  
  2. Manual repair with fsck:
    sudo fsck -C -y -f /dev/sdXY  # -C: Progress bar, -y: Auto-fix, -f: Force check  
  3. Analyze logs:
    sudo dmesg | grep -i "error\|fsck\|sdXY"  

⚠️ Handling Severe Corruption

  • If fsck asks to repair primary superblock, use backup superblocks:
    sudo mkfs.ext4 -n /dev/sdXY  # Find backup superblock addresses (DO NOT use -n and -y together!)  
    sudo fsck -b 32768 /dev/sdXY  # Replace 32768 with your backup block  
  • For unrecoverable inodes: sudo debugfs /dev/sdXYdump ~/recovered_file

🛡️ Prevention Best Practices

  • Regular backups: Use rsync or BorgBackup.
  • UPS: Protect against power surges.
  • Schedule checks:
    sudo tune2fs -c 30 /dev/sdXY  # Check every 30 mounts  
  • Enable journaling: Always use journaled filesystems (ext4/XFS) for critical data.

💡 When All Else Fails

  • PhotoRec/TestDisk: Recover raw files from damaged partitions.
  • Professional help: For mission-critical data, consult recovery services.

Final Tip: Never run fsck on a mounted drive! Always unmount first. Stay calm, work methodically, and let the tools do their job. Your data has a fighting chance! 🛠️💾

> ℹ️ Remember: File system repair isn’t data recovery. If valuable data is at risk, image the drive with ddrescue first:
> sudo ddrescue /dev/sdXY ~/disk.img ~/logfile

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다