Troubleshooting Linux Filesystem Issues

At any moment a system admin may come across file system failures due to issues with data structures (or objects such as inode, directories, superblock etc. This can be caused by any reason:

  • Buggy device driver or utilities (especially third party utilities)
  • Mistakes by System Admin
  • Kernel bugs

Due to Filesystem Failure:

  • File system will refuse to mount
  • Entire system get hangs
  • Even if filesystem mount operation result into success, users may notice strange behavior when mounted such as system reboot, gibberish characters in directory listings etc

So how you are going to Survive in a Filesystem Failures? Most of time fsck utility can fix the problem, first simply run e2fsck to check a Linux ext2/ext3 file system

Assuming /data /dev/sda2 partition filesystem, first unmount /dev/sda2 then type following command :

# e2fsck -f /dev/sda2
Where,

  • -f : Force checking even if the file system seems clean.

Please note that If the superblock is not found, e2fsck will terminate with a fatal error. However Linux maintains multiple redundant copies of the superblock in every file system, so you can use -b {alternative-superblock} option to get rid of this problem. The location of the backup superblock is dependent on the filesystem’s blocksize:

  • For filesystems with 1k blocksizes, a backup superblock can be found at block 8193
  • For filesystems with 2k blocksizes, at block 16384
  • For 4k blocksizes, at block 32768.

You can also try any one of the following command(s) to determine alternative-superblock locations:

# mke2fs -n /dev/sda2
OR
# dumpe2fs /dev/sda2 | grep -i superblock

To repair file system by alternative-superblock use command as follows:
# e2fsck -f -b 8193 /dev/sda2

However it is highly recommended that you make backup before you run fsck command on system, use dd command to create a backup (provided that you have spare space under other partition or disk)
# dd if=/dev/sda2 of=/disk2/backup-sda2.img

Leave a Reply

Your email address will not be published. Required fields are marked *