Repairing Linux ext2 or ext3 file system

by LinuxTitli on October 16, 2005 · 20 comments

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.

Featured Articles:

Share this with other sys admins!
Facebook it - Tweet it - Print it -

We're here to help you make the most of sysadmin work. So, subscribe!

{ 20 comments… read them below or add one }

1 Anonymous October 17, 2005

simple and effective :) good pice of work

Reply

2 Anonymous October 17, 2005

can I try same commands on HP/UX?

Reply

3 LinuxTitli October 18, 2005

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.

Reply

4 Michael November 8, 2011

To repair a file system in HPUX

# fsck -F vxfs -y -o full /dev/vg##/lvol#
-or-
# fsck -F vxfs -o full -y /mount_pt

Note: The HFS file system has been obsoleted in HP-UX since version 10, except for the /stand file system which contains the kernel, and you’re not going to unmount the kernel and run a file system check. Instead, get to single user. Here is one way:

# reboot
# interact with IPL . yes
ISL>hpux -is

And as the kernel is loaded vg00 will be enabled and automatically checked for corruption.

# init 2, same thing, automatically check run level 2
# init 3, same thing, automatically check run level 3, multiprocessor mode. The system is up.

NEVER! fsck /stand – The only hfs file system for over a decade is /stand, and you never fsck /stand!

Reply

5 Anonymous October 18, 2005

thanks for HP/UX JFS repair commands :)

Reply

6 General Zod October 27, 2006

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

Reply

7 General Zod October 27, 2006

excllent work

Reply

8 Jm December 4, 2006

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

http://linux-tweaks.blogspot.com

Reply

9 Lusidvicel December 18, 2006

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

Reply

10 Owain March 3, 2007

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.

Reply

11 jack June 10, 2007

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?

Reply

12 Paolo July 14, 2008

Thanks, very good guide!

Reply

13 herson December 11, 2008

@Jack, I think that’s when you need to use a rescue disk. Most of the distros have this on their installation media.

Reply

14 Chris December 24, 2008

How do you find out what the actual device name is?

Reply

15 markthecarp January 28, 2009

This post is over two years old but still relevant today.

I just used most of the steps described here to repair an ext3 partition on my Ubuntu desktop system. Only difference being I did not do “init 1″. I logged out to the gdm screen then did Ctl-Alt-F2 to get to a virtual console. I logged into the system and ran the commands with the exception of “init 1″.

Thanks for a very helpful and concise article.

Reply

16 tuxsun1 August 3, 2009

Excellent article!!
Is there a way to do this via SSH?
What methods do you recommend for listing the mounted file systems?
Thanks!

Reply

17 bsuresh November 3, 2009

system not booting.because new root user created last time,not come guimode .so restart that p.c .not booting asked password or alt ctrl d.so i gave that password .system restarted.what will i do?lasttime i worked that pc du /dev/hdc6 .but i don’t know about this cmd.may be reason is there

Reply

18 MRPOST February 12, 2011

Hi I am getting following mesage:
Repair File system 1#
I don’t know what to do now.
Beofore this it is saying file system corrupted. Anybody please help help….

Reply

19 Jan Girke May 19, 2011

Don’t try that on Ubuntu 10.04.
It will just shut down the system.

Reply

20 Sk. Shahin Rahman December 4, 2011

Thanks a lot for this helpful article

Reply

Leave a Comment

You can use these HTML tags and attributes for your code and commands: <strong> <em> <ol> <li> <u> <ul> <blockquote> <pre> <a href="" title="">
What is 10 + 11 ?
Please leave these two fields as-is:
Are you a human being? Solve the simple math so we know that you are a human and not a bot.



Previous post:

Next post: