XFS Filesystem Recovery: Fixing “superblock read failed” Error on Linux


2 views

When dealing with XFS filesystem recovery, the "superblock read failed" error typically indicates corruption in the primary superblock or its backups. This is particularly common in scenarios like:

  • Unclean system shutdowns
  • Hardware failures
  • Storage device disconnections during write operations
  • NAS device failures (common in Buffalo LinkStation cases)

Before attempting repairs, confirm the disk status:

# Check disk SMART status
sudo smartctl -a /dev/sdb

# Verify partition table
sudo fdisk -l /dev/sdb

# Check filesystem errors
sudo xfs_db -c "sb 0" -c "p" /dev/sdb6

XFS stores multiple superblock backups. To find them:

# Search for backup superblocks
sudo xfs_db -r /dev/sdb6
xfs_db> sb 0
xfs_db> p
xfs_db> blocks
xfs_db> quit

# Alternatively use mkfs.xfs to show locations
sudo mkfs.xfs -n /dev/sdb6

When standard repair fails, try these methods:

Method 1: Using Alternate Superblocks

# Example using backup superblock at 32768 blocks
sudo xfs_repair -L -b 32768 /dev/sdb6

# If successful, mount with:
sudo mount -o nouuid,ro /dev/sdb6 /mnt/recovery

Method 2: Manual Superblock Reconstruction

For severe cases, we might need to reconstruct metadata:

# Zero out the log (LAST RESORT)
sudo xfs_repair -L /dev/sdb6

# If still failing, try manual superblock copy
sudo dd if=/dev/sdb6 of=/tmp/xfs_sb_backup bs=512 count=8192
sudo xfs_metadump /dev/sdb6 /tmp/xfs_metadata.img

When filesystem repair isn't possible:

# Use xfs_copy for raw data extraction
sudo xfs_copy /dev/sdb6 /mnt/destination/image.img

# Or use professional tools like:
# - xfsdump
# - testdisk
# - photorec (as mentioned in the original case)
  • Regularly check filesystem health: sudo xfs_admin -l /dev/sdb6
  • Implement proper backup strategies for NAS devices
  • Consider using XFS-specific monitoring tools

For deeper investigation:

# Enable XFS debug logging
sudo echo 1 > /sys/fs/xfs/sdb6/error/metadata/0/log_failures

# Check kernel messages
dmesg | grep XFS

# Inspect hardware-level errors
sudo hdparm -I /dev/sdb

When dealing with XFS filesystem corruption, the "superblock read failed" error typically indicates one of these scenarios:

  • Primary superblock corruption
  • Physical disk damage in the superblock region
  • Metadata log requiring replay
  • Filesystem inconsistency after improper shutdown

First, let's verify the disk's physical health:

sudo smartctl -a /dev/sdb
sudo badblocks -v /dev/sdb6

Method 1: Mount with forced recovery

sudo mount -t xfs -o norecovery /dev/sdb6 /mnt/temp

Method 2: Alternative superblock locations

XFS maintains multiple superblock copies. Try these commands to locate backups:

sudo xfs_db -c "sb 0" -c "p" -r /dev/sdb6
sudo xfs_db -c "sb 1" -c "p" -r /dev/sdb6

If standard methods fail, try this comprehensive approach:

sudo xfs_repair -v -L -m 512 /dev/sdb6
sudo xfs_repair -v -o force_geometry /dev/sdb6

When repair isn't possible, consider these data recovery tools:

sudo apt-get install xfsdump
sudo xfsdump -l 0 -f recovery.xfsdump /dev/sdb6

For raw data extraction:

sudo dd if=/dev/sdb6 of=recovered_data.img bs=4M conv=noerror,sync

To avoid future issues:

  • Regularly run xfs_admin -l to check filesystem labels
  • Implement proper backup strategies with xfsdump
  • Schedule periodic filesystem checks