24

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
ish
  • 141,990
UrkoM
  • 1,375

6 Answers6

26

I know this is a really old thread, but I recently had to solve this problem so I wanted to post how to force the OS to fix problems found with fsck during bootup (for 12.04).

You do need to run the command sudo touch /forcefsck. This will cause it to perform an fsck on the next boot. You can see the results of the fsck in /var/log/boot.log.

However, you are not guaranteed that fsck will fix anything it finds. To do this, you would need to edit the file /etc/default/rcS. There is a line at the end of that file:

FSCKFIX=no

This needs to be changed to the following:

FSCKFIX=yes

This will have the same effect as running the fsck with the -y option which will force all fixes that are possible to be implemented and it will not ask for user interaction.

This will allow you to run the fsck like the OP was asking to without having to resort to booting from a live disk which isn't always possible especially if you are on a remote system.

Brian
  • 431
14
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.

10

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.

Eliah Kagan
  • 119,640
3

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.

charlie-tca
  • 1,269
1

touch /forcefsck alone didn't ensure my system ran fsck at the next boot. I also needed to run:

sudo tune2fs -c 1 /dev/<my partition>

e.g.

sudo tune2fs -c 1 /dev/sda1

More explanation I found is here: How to Force fsck to check filesystem after reboot

Zanna
  • 72,312
Clock ZHONG
  • 1,015
  • 1
  • 13
  • 17
1

You can have the revisions done automatically in the following way:

Tune2fs -c 5 -i 10 / dev / sda1

-c is the maximum number of mounts before running fsck and -i is the maximum number of days before running fsck.

In this case will be done every 5 mounts or every 10 days, whichever comes first.

I have two computers, one with Linux SuSE 13.2 and the other with Linux Mint 18.0 and in both it works perfectly.

Zanna
  • 72,312
hk3jld
  • 11