I'm having a problem with my web server: when it's been up for a long time, and then it goes down for some reason, it takes forever to boot.
My workaround to this was to create a cron to reboot the server from time to time (I've been insulted for this, be kind). The reboot was so fast that the server was able to respond to the requests before they timed out, so I was cool with it.
But now I've been told that what might be causing this is fsck being forced after X days, and also after Y mounts, so my fix won't help much.
So the question is what should I do with fsck? Force it to run more frequently, or disable it? Can it run at any time, or it must be during boot? An example of how to do it with tune2fs is also welcome.
To answer the easiest question first: Checking a filesystem "at any time" (i.e., when the system is running) is referred to as "online" checking, and in general, it isn't supported. The reason is simple: when a filesystem is mounted, the kernel is doing arbitrary things to the actual block device--which is fine, because it keeps track of what it's doing. But when you throw fsck into the mix, it too messes with the raw block device and doesn't inform the kernel about what it's doing. So they essentially step on each other's toes when making changes to the disk, and you end up with a corrupted filesystem. Even if you just "check" in read-only mode, the results fsck returns will be meaningless, again because fsck has no idea what the kernel is doing.
To change the frequency the filesystem is checked when you mount it, you will use tune2fs, as you mentioned. Suppose you'd like to fsck every 30 reboots. Do
(Substitute the block device for your filesystem.)
Or, if for some reason you'd like to disable mount-count-based checking entirely,
If you'd rather check on a calendar, you can use
-i
. For example, to check every week, doYou can use
d
for days,w
for weeks, andm
for months. Again, to disable calendar-based checking, give a value of0
for the interval. Please, please, please don't disable all checking. You will, at some point, corrupt your filesystem.In general, you can get away with slightly longer intervals if the filesystem is journaled, although it isn't a replacement. For more info, read the man pages for e2fsck and tune2fs; they're where I got most of the info for this. Hope this helps!
Change you scheduled reboot to have one of the following included
or
The existence of the
/forcefsck
will tell the OS to scan the disks (I am pretty sure this is what the second command does anyway.Use cron to schedule this for a period when the server has the least load and disable the other scheduled scans (date / number of mounts) once you are confident it is running correctly.