Thursday, January 24, 2013

Detailed Procedure to Run 'fsck' for Fixing Linux File Systems

The Linux operating system may comprise several file systems, one for each partition on your hard drive. These file systems become vulnerable to corruption after a disgraceful shutdown of your Linux computer. Power surges, hardware failures, and human errors are a few typical causes of file system damage in Linux. A useful file system check utility called ‘fsck’ is bundled with all Linux distributions. It enables you to correct errors and fix corruption in Linux file systems. However, you can use this command only in single user mode that allows only the root user to log in to the Linux system. Moreover, the command supports only journaling file systems that maintain a record of changes made to the file system. You should unmount the partition to be checked before using this command. For performing a check on the root file system, you should use a Linux Live CD for unmounting the entire drive.

Using ‘fsck’ command to fix Linux file system corruption:
  • Navigate to the terminal window. To do this, go to ‘Applications’ or ‘Programs’ menu, and then the ‘Accessories’, ‘Utilities’ or ‘Xterm’ section. You will find the terminal window.
  • Type the command ‘su’ to run as a root user and specify the root password when asked for.
  • Run the ‘mount’ command. This will display a list of all file systems on your hard drive. Determine the name and type of the file system to be fixed. The name can be anything like ‘dev/sda2’ or ‘/home’.
  • Run the command ‘init 1’ to switch to single user mode or run level one. Now, only the root user can access the system. You will not have access to the network or any daemons running in this mode.
  • Run the following command at the file system to unmount the file system to be fixed:
    Umount /dev/sda2

    (Assuming ‘/dev/sda’ to be the file system you need to fix)
  • Run the following command to scan and repair the file system:
    fsck -t ext2 /dev/sda2

    (Assuming the type of file system to be ‘ext2’)
  • The time taken by this command would depend on the size of your file system.
  • Repeat the two preceding steps until all the errors have disappeared.
  • Remount the file system by running ‘mount /dev/sda2’.
  • Run the command ‘init 3’ to switch to multi-user mode.

In case you have issues with your file system even after the aforementioned fix, take help of professional Linux data recovery software. With these advanced tools, you can fix Linux file system corruption and easily recover all your seemingly lost data stored on the Linux hard drive.