Wednesday, September 27, 2023
 Popular · Latest · Hot · Upcoming
rated 0 times [  4] [ 0]  / answers: 1 / hits: 4994  / 2 Years ago, fri, august 6, 2021, 1:56:43

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.

More From » 12.04


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

# tune2fs -c 30 /dev/sdaX

(Substitute the block device for your filesystem.)

Or, if for some reason you'd like to disable mount-count-based checking entirely,

# tune2fs -c 0 /dev/sdaX

If you'd rather check on a calendar, you can use -i. For example, to check every week, do

# tune2fs -i 1w /dev/sdaX

You can use d for days, w for weeks, and m for months. Again, to disable calendar-based checking, give a value of 0 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!

[#34185] Friday, August 6, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.

Total Points: 291
Total Questions: 135
Total Answers: 117

Location: New Caledonia
Member since Thu, Mar 23, 2023
7 Months ago