How should I run fsck on a Linux file system

Scenario / Question:

I need to check file system for errors using fsck. Can I run fsck on a mounted file system ?

Solution / Answer:

Running fsck on a mounted file system can result in data corruption. The two options are:

1) Change the running state of the system to single user mode and unmount the file system

What if you need to run fsck on the root / file system ?

2) Boot the computer into Rescue Mode using the installation CD

1) Single User Mode and umount the file system

Issue command to change run level and umount the /home file system that is mounted on /dev/sda2

# init 1
# umount /home

Run fsck:

# fsck /dev/sda2

2) Rescue Mode using installation CD ( to run fsck on root /)

Insert the Installation CD into the drive and reboot your system:

# shutdown -r now

After booting from the Installation CD and presented with the installation command prompt type:

linux rescue nomount

Once you are at the system command prompt you need to run mknod. Because we started Rescue Mode with the “nomount” option, no file systems were initialized and no device files were created. If we try to run fsck on a file system it will fail. We need to use mknod to create the block or character special file.

To use mknod we need to know the Minor and Major numbers of the device.

# ls -l /dev/sda
8 0
# ls -l /dev/sda2
8 2
# mknod /dev/sda b 8 0
# mknod /dev/sda2 b 8 2

Run fsck and force the check and attempt to automatically repair:

-y — cause the fs-specific fsck to always attempt to fix any detected filesystem corruption automatically.

-f — force a check even if reported in a clean state

-v — Produce verbose output, including all file system-specific commands that are executed.

# fsck -yvf /dev/sda2

LVM Partitions

In order to be able to run fsck on lvm partitions we need to find the pv’s, vg’s, lv’s and activate them.

# lvm pvscan
# lvm vgscan
# lvm lvchange -ay /dev/VolGroup00/LogVol_home
# lvm lvscan

# fsck -yfv /dev/VolGroup00/LogVol_home

LUKS Partition

In order to be able to access an encrypted LUKS partition user cryptsetup.

cryptsetup luksOpen <device> <name>

<device> – is the device path

<name> – is the name of the unencrypted mount that can be accessed by /dev/mapper/<name>

# cryptsetup luksOpen /dev/VolGroup00/LogVol_home home
# Ener LUKS passphrase for /dev/VolGroup00/LogVol_home
# fsck -yvf /dev/mapper/home
Fabio Milano has written 80 articles for us. Fabio Milano is a certified RHCE, MCP, and CFOI. He runs an IT consulting and services company called RDS Support inc. Website:http://www.rdssupport.com
The information provided is for educational purposes only. All content including links and comments is provided "as is" with no warranty, expressed or implied. Use is at your own risk and you are solely responsible for what you do with it.

11 Comments so far

  1. [...] boot ok guys, thx, I did it and everything goes fine! For those like me, some useful links: How to run fsck on a Linux file system | %/category_title%/ | Linux Tutorial Repairing Linux ext2 or ext3 file system fsck(8): check/repair file system – Linux man [...]

  2. Piotr on November 16th, 2009

    Totally no good for a CentOS box. Imagine having it 500 km away – you just can’t go down to SUM.

  3. FSCK HDD Error  | Vladimir Yosifov on November 1st, 2010
  4. Alexandre Martini on November 4th, 2010

    This site save my life! Congratulation!

  5. Gustavo on November 29th, 2010

    Thank you very much!! Now I can breath again! :D

  6. Anup Nair on February 28th, 2011

    Thank a ton!

    I had a hard time with rescue mode. I was wondering why it couldn’t umount / (LVM) partition when in rescue mode. And that’s when I came across this site, suggesting ‘nomount’

  7. mahmood on August 25th, 2011

    hi,
    you article was wonderfull. i saved my linux from corruption

  8. jonathan on May 8th, 2012

    u are my saviour :)

  9. Paul Stone on May 22nd, 2012

    Thanks for this very informative article. I don’t know why fsck’ing a logical volume has to be so arcane, but your instructions worked like a charm.

  10. amit on June 21st, 2012

    Hi, I am unable to run mknod as suggested above in rescue mode.
    Its ended with message
    OSError: [error 17] File exists.
    Please suggest

Leave a reply