About nixCraft

Topics

Repairing Linux ext2 or ext3 file system

Posted by Vivek Gite [Last updated: October 27, 2006]

1) 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

2)Unmount file system, for example if it is /home (/dev/sda3) file system then type command:
# umount /home
OR
# umount /dev/sda3

3) Now run fsck on the partition:
# fsck /dev/sda3

However be sure to specify the file system type using -t option. Recenly 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
OR
# fsck.ext3 /dev/sda3

Tip if you don't know your file system type then typing mount command will display file system type.

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/sda3

Please not if any files are recovered then they are placed in /home/lost+found directory by fsck command.

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

5) Go to multiuser mode
# init 3

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

Tell us how we're doing: Please answer a few questions about your experience to help us improve nixCraft.

You may also be interested in other helpful articles:

Discussion on This Article:

  1. Anonymous Says:

    simple and effective :) good pice of work

  2. Anonymous Says:

    can I try same commands on HP/UX?

  3. LinuxTitli Says:

    Commands are same but syntax changes.

    To repair HFS file system (/home)

    umount /home
    fsck –F hfs /dev/vg00/lvo1
    mount /home

    To repair JFS file system (/home)
    umount /home
    fsck –F vxfs /dev/vg00/lvo14
    mount /home

    Replace /dev/XXX/YYY with actual device file.

  4. Anonymous Says:

    thanks for HP/UX JFS repair commands :)

  5. General Zod Says:

    Concise, very effecive and to the point. Just what was required.

  6. General Zod Says:

    excllent work

  7. Jm Says:

    What about to recover data that are deleted?
    Thanks anyway… :)

    http://linux-tweaks.blogspot.com

  8. Lusidvicel Says:

    Hello, i love http://www.cyberciti.biz! Let me in, please :)

  9. Owain Says:

    Thankyou - this page saved my life! (well, not literally). After checking loads of links that just told me what it said in the man page, here was a quick, easy and practical way to use the command.

  10. jack Says:

    How do you check the / partition - which cannot be unmounted since it still shows as “in use” after going to run level 1? Is there a way without rebooting?

  11. Paolo Says:

    Thanks, very good guide!

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.