If you’ve ever had to hard restart a Linux server, you know when it starts up you’ll see a message about your system being shut down uncleanly and it will do an fsck. But, how does it know you shut it down uncleanly?
The short story is, if the server finds a file at /.autofsck on boot, it knows you didn’t perform a clean shutdown. The /.autofsck file is put there by a startup script and removed when you do a clean shutdown using a commands such as halt, poweroff, shutdown, or reboot. When you perform an unclean shutdown, the shutdown scripts are never run and the /.autofsck file is never deleted, thus an fsck is initiated due to the unclean shutdown.
The script that puts it there on startup is /etc/rc.d/rc.sysinit. The scripts that remove it are /etc/rc0.d/S01halt when you power the server off or /etc/rc6.d/S01reboot when you do a reboot. Interestingly enough it is called the “crash indicator” file in all of the files.
Time or mount frequency
Sometimes you might find a server doing an unexpected fsck, even if you did a clean shutdown.
You can configure the filesystem to be checked based on a time or mount frequency. To see the settings for your filesystem, run.
tune2fs -l /dev/whatever1 | egrep '^(Mount count|Last checked|Maximum mount count|Check interval)'
Here’s the output from the command on a server. You can see the server is configured to do an fsck every 22 filesystem mounts. It has performed one mount in this example, so it has 21 left to go before the next fsck. You can also see it is configured to do an fsck every 15552000 seconds (6 months) and the last one it did was March 19, 2013 which was more than 6 months ago, so it will be doing an fsck on the next reboot
Mount count: 1 Maximum mount count: 22 Last checked: Tue Mar 19 19:05:53 2013 Check interval: 15552000 (6 months)
If you’re in a hurry and don’t want to sit around and wait for for an fsck on a 16 TB filesystem, you can create a file named /fastboot which will disable any time or mount frequency fscks.Posted in: Linux, Nexcess