Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

One of my Ubuntu 10.04 servers is giving me trouble. When I run fsck.ext4 -n /dev/sda5 it tells me there are errors in the free inode count, free block count, and more.

I have tried:

touch /forcefsck

Also tried:

shutdown -rF now

and still, after reboot, I see errors.

I also just checked on my eeePC netbook, Ubuntu 10.10, and have the same issue!

How can I force a really "forced" "forceful" "seriously fix my filesystem" fsck of the "/" filesystem on reboot?

Clarification: I run fsck.ext4 -n because it's a mounted filesystem, to check if there are errors. This tells me that there are. I thought that the automatic fsck every 30 mounts during the boot-up process is precisely to take care of errors in the root filesystem. But it doesn't do it in my case. I could reboot with a LiveCD and fix the errors, and then reboot again, but that's some serious downtime for a live server. A reboot, auto fsck, then continue booting is much more sustainable on a live server, and I believe should be the right behaviour.

Additional info: Here is the output. It looks like something that the autofsck would fix, doesn't it?

root@server:~# fsck.ext4 -n /dev/sda5
e2fsck 1.41.11 (14-Mar-2010)
Warning!  /dev/sda5 is mounted.
Warning: skipping journal recovery because doing a read-only filesystem check.
/dev/sda5 contains a file system with errors, check forced.
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
Free blocks count wrong (1849368, counted=1948909).
Fix? no

Free inodes count wrong (545504, counted=552134).
Fix? no


/dev/sda5: ********** WARNING: Filesystem still has errors **********

/dev/sda5: 116752/662256 files (0.2% non-contiguous), 795324/2644692 blocks
share|improve this question
    
what is the Ubuntu server version you are using? –  crncosta Nov 24 '10 at 15:03
    
10.04. I'll edit my question. –  UrkoM Nov 24 '10 at 15:32
    
I don't think you can actually do that, in fact you might be better off doing the check manually. –  RolandiXor Nov 24 '10 at 15:46
1  
Sorry but I still need more info. Are you doing fsck on mounted filesystems? can you boot from a LiveCD and check again (with your /dev/sda5 unmounted)? –  crncosta Nov 24 '10 at 15:51
    
Isn't it possible that not the file system but the hard drive is broken? In which case it would be expected that ext4 isn't fixing errors as well as it would were there just a few bad sectors. –  Stefano Palazzo Nov 24 '10 at 18:45

3 Answers 3

up vote 8 down vote accepted

From the e2fsck man page :

"Note that in general it is not safe to run e2fsck on mounted filesystems. The only exception is if the -n option is specified, and -c, -l, or -L options are not specified. However, even if it is safe to do so, the results printed by e2fsck are not valid if the filesystem is mounted. If e2fsck asks whether or not you should check a filesystem which is mounted, the only correct answer is ''no''. Only experts who really know what they are doing should consider answering this question in any other way."

So if you check a mounted FS with fsck even using the -n option the result may be not valid at all. Don't check mounted filesystems. Use a Live-CD/Live-USB.

If you don't check the filesystem while it is mounted, I don't understand why you need to use touch /forcefsck you can just unmount it and fix it. But if it is the case and after a fix your FS still have errors then you can consider using :

e2fsck -cy /dev/sda5

That will fix an hard drive related issue called bad blocks you may have (this will take a long time).

If you want to check a mounted filesystem, I don't know how to proceed but I think you should create another question.

share|improve this answer
    
You are correct, the filesystem is mounted. And of course I need to do fsck when unmounted. But I run fsck -n to check while mounted, without making changes, and it tells me there are errors. And shouldn't the fsck on reboot fix them??? –  UrkoM Nov 25 '10 at 3:01
    
I just noticed what you say in the first sentence: why would fsck -n not be valid on a mounted filesystem? How can I check if a mounted filesystem has errors in a reliable way? –  UrkoM Nov 25 '10 at 13:12
    
You can check the e2fsck man page that say: "Note that in general it is not safe to run e2fsck on mounted filesystems. The only exception is if the -n option is specified, and -c, -l, or -L options are not specified. However, even if it is safe to do so, the results printed by e2fsck are not valid if the filesystem is mounted. If e2fsck asks whether or not you should check a filesystem which is mounted, the only correct answer is ''no''. Only experts who really know what they are doing should consider answering this question in any other way." –  Nyamiou The Galeanthrope Nov 25 '10 at 22:03
    
I don't know how to check a mounted file system maybe you should create another question. –  Nyamiou The Galeanthrope Nov 25 '10 at 22:04
    
Can you add those two last comments to your answer? Then I'll accept it. I didn't know that, so that's why... I think it's because fsck -n doesn't process the journal, so the filesystem state is inconsistent without looking at the latest changes kept there. –  UrkoM Nov 26 '10 at 0:35
sudo touch /forcefsck
sudo reboot

You've got a typo- you're touching /forcefcsk. The "c" and the "s" are swapped. fsck is short for FileSystemChecK.

share|improve this answer
    
This wouldn't work for me because the root filesystem is mounted read-only due to errors I to fix with fsck! Chicken and the egg problem that can only be solved via liveCD or pulling the drive into another machine. –  HDave Aug 10 '12 at 18:09

You can not force a fsck on / that will repair because the partition is in use. Try running the check from a different partition or live cd.

share|improve this answer
1  
Very true, but the automatic fsck on boot should happen before the partition is in use, precisely to be able to fix errors on "/". Otherwise, what's the point? –  UrkoM Nov 25 '10 at 3:10
3  
I believe the check happens before use, however, it is more of an advisory check. It is up to you to decide how to fix the errors. An easy check is when looking at /etc/fstab. The "/" gets a different check then the other partitions. –  charlie-tca Nov 26 '10 at 16:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.