Linux comes with the system utility fsck ("file system check") for checking the consistency of a file system. This quick post explains how to use fsck to fix error.
The syntax is as follows to check and optionally repair one or more Linux file systems:
fsck Fs-Name-Here fsck /dev/xyz fsck /home fsck.ext3 /dev/hdc1 fsck.ext2 /dev/flash/device/name
Fs-Name-Here can be one of the following
- A device name (e.g. /dev/hda1, /dev/sda2, /dev/md0, /dev/vg1/volume_1)
- A mount point (e.g. /var, /home)
- An ext2 label (e.g. LABEL=home )
- UUID specifier (e.g. UUID=8868abf6-88c5-4a83-98b8-bfc24057f7bd)
First, a file system must be unmounted. You cannot repair it while it is running. Take system down to runlevel one (make sure you run all command as root user):
# init 1
Next, unmount file system, for example if it is /home (/dev/sda3) file system then type command:
# umount /home
# umount /dev/sda3
Finally, run fsck on the partition, enter:
# fsck /dev/sda3
However be sure to specify the file system type using -t option. Recently, one of our sys admin run the command on ext3 file system w/o specifying file system. Result was more corruption as fsck by default assumes ext2 file system:
# fsck -t ext3 /dev/sda3
# fsck.ext3 /dev/sda3
# fsck.ext4 /dev/sda5
If you do not know your file system type then typing mount command will display file system type.
/dev/root on / type ext4 (rw,relatime,barrier=0,journal_checksum,data=ordered) /tmp on /tmp type tmpfs (0) none on /dev/pts type devpts (gid=4,mode=620) /sys on /sys type sysfs (0) /proc/bus/usb on /proc/bus/usb type usbfs (0) /dev/vg1/volume_1 on /volume1 type ext4 (usrjquota=aquota.user,grpjquota=aquota.group,jqfmt=vfsv0,synoacl) /volume1/@optware on /opt type bind (bind) none on /proc/fs/nfsd type nfsd (0)
fsck will check the file system and ask which problems should be fixed or corrected. If you don't want to type 'y' every time then you can pass -y option to fsck:
# fsck -y /dev/sda3
Please not if any files are recovered then they are placed in /home/lost+found directory by fsck command.
Don't execute, just show what would be done:
# fsck -N /dev/sda3
Once fsck finished, remount the file system:
# mount /home
Go to multiuser mode, enter:
# init 3
Read man page of fsck for more information. Make sure you replace /dev/sda3 with your actual device name:
$ man fsck
Page last updated at 9:58 PM, April 10, 2012.Tweet itFacebook itGoogle+ itPDF itFound an error/typo on this page?