Repairing Linux ext2 or ext3 file system

by LinuxTitli · 16 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:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 16 comments… read them below or add one }

1 Anonymous 10.17.05 at 2:20 am

simple and effective :) good pice of work

2 Anonymous 10.17.05 at 7:50 pm

can I try same commands on HP/UX?

3 LinuxTitli 10.18.05 at 12:32 am

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 10.18.05 at 11:25 pm

thanks for HP/UX JFS repair commands :)

5 General Zod 10.27.06 at 5:16 pm

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

6 General Zod 10.27.06 at 5:17 pm

excllent work

7 Jm 12.04.06 at 3:05 am

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

http://linux-tweaks.blogspot.com

8 Lusidvicel 12.18.06 at 5:50 pm

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

9 Owain 03.03.07 at 10:03 pm

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 06.10.07 at 4:50 pm

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 07.14.08 at 12:38 pm

Thanks, very good guide!

12 herson 12.11.08 at 4:32 am

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

13 Chris 12.24.08 at 9:10 am

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

14 markthecarp 01.28.09 at 2:00 pm

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.

15 tuxsun1 08.03.09 at 10:13 pm

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

16 bsuresh 11.03.09 at 7:07 am

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

Leave a Comment

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

Previous post:

Next post: