Wednesday, January 9, 2013

Examining 'Nuts and Bolts' of a Linux File System and Related Data Corruption

A Linux file system comprises a set of files and directories stored together on a separate partition on your hard disk. Digging a little deeper, it contains user data and metadata. User data is the actual information stored in files, whereas metadata represents the objects that keep your file system's structural information (such as inodes, directories, and superblock). Overall, the file system is divided into blocks. Each block either contains user data or metadata. One block that is the most critical to your file system is superblock.

A Linux superblock has every information about your file system, i.e. file system type, size, status, and information about other objects. This information is required for the proper functioning of various file system operations. If something corrupts the superblock, you will be at the risk of losing all data on the hard disk. This is the reason why a file system contains multiple copies of its superblock. In the event that the block damages or corrupt itself, you can take help of these backup copies to rebuild or restore the primary superblock. You can use the following command to find out the location of the primary and backup superblock on a partition ('/dev/sda3' in this case):

# dumpe2fs /dev/hda3 | grep -i superblock

Linux is no exception to file system failures. They can occur because of plethora of reasons, such as power failures, faulty device drivers, kernel bugs, and human errors. A common sign is that the file system will fail to mount. In case you are able to mount the corrupt file system, you will have intermittent problems of system hangs, hard reboots, and more. Further, you may see some gibberish characters in your directory listings.

You can force a file system check on a particular partition using 'e2fsck' utility with the '-f' option as follows:

# e2fsck -f /dev/sda3

If the utility fails to find the primary superblock, it may return a fatal error. You can also use this command to get the backup superblock location:

# mke2fs -n /dev/sda3

Run the below given command to fix file system corruption using the backup or alternate superblock:

# e2fsck -f -b 8193 /dev/sda3

If the above resolution fails to repair the file system, you should take help of professional Linux data recovery software. Using these utilities, you can easily repair all types of Linux file systems. Further, you can quickly regain access to all lost files, photos, videos, and other personal information in your system.