Sunday, September 27, 2015

How to check/repair (fsck) filesystem after crash or power-outage


At some point your system will crash and you need to perform a manual repair of your file system. A typical situation would be power loss while you are working on the system. You reboot and the system stops and indicates you must perform a manual repair of the system using fsck.

fsck (file system consistency check) is a command used to check filesystem for consistency errors and repair them on Linux filesystems. This tool is important for maintaining data integrity so should be run regularly, especially after an unforeseen reboot (crash, power-outage).

Usage: fsck [-sACVRTNP] [-t fs-optlist] [filesystem] [fs-specific-options] 

Filesystem can be either a device's name (e.g. /dev/hda) or its mount point. fsck run with no options will check all devices in /etc/fstab. It might be neccesary to run fsck from single-user mode

Note: You need to be "root" to use any of the below mentioned command

* Take system down to runlevel one: # init 1

* Unmount file system, for example if it is /home (/dev/sda2) file system then type command:
# umount /home OR  # umount /dev/sda2
* Now run fsck on the partition: # fsck /dev/sda2

* Specify the file system type using -t option:  
# fsck -t ext3 /dev/sda2 OR  # fsck.ext3 /dev/sda2
fsck will check the file system and ask which problems should be fixed or corrected. If you don't wanna type y every time then you can use pass -y option to fsck: 
# fsck -y /dev/sda2
Please note if any files are recovered then they are placed in /home/lost+found directory by fsck command.

* Once fsck finished, remount the file system: # mount /home

Read man page of fsck for more information.
Make sure you replace /dev/sda2 with your actual device name.

No comments:

Post a Comment