Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

...and how do I find out?

Say I am about to reboot a server. I would like to minimize downtime, so thinking about wrapping reboot in an alias that says "hang on buddy, you're going to hit a fsck on boot".

Next question.. what's the best way to say "lets do it next time?" set the last check date?

I know tune2fs can set a bunch of parameters, but how would I get em?

share|improve this question
    
Which OS are you running, and which filesystem? –  Alan H Jun 18 '09 at 20:43
    
Good point - versions of Linux (mainly deb & derivatives) and ext2 or ext3 –  Tom Newton Jun 19 '09 at 7:24
add comment

8 Answers

up vote 17 down vote accepted

If all you want to do is avoid an fsck, adding the -f option to shutdown should help with that. shutdown -F to force fsck.

tune2fs -l /dev/foo will tell you the interesting bits of information.

Here's a start at extracting just what you need:

mount -l -t ext3,ext2 | cut -d' ' -f1 | xargs -n1 tune2fs -l | egrep -i 'state|mount|check'

If the "Next check after" date is in the past, there will be an fsck.

If the filesystem state is not clean, there will be an fsck. (this could also happen if there's a problem with the system during reboot/shutdown that prevents a clean unmount)

If the mount count has reached the maximum mount count, there will be an fsck.

share|improve this answer
    
Thanks - if I ussue shutdown -f, will the next reboot get the fsck instead? –  Tom Newton Jun 19 '09 at 7:27
    
Assuming your system currently meets one of the criteria for getting an fsck, yes, the next reboot would get the fsck instead. "shutdown -f" creates a file that tells the system startup to skip fsck, but the system startup also removes that file. –  freiheit Jun 19 '09 at 15:08
add comment

Here is a script that checks your filesystems for fsck:

https://gist.github.com/Avyd/7008315

share|improve this answer
1  
Please dont just post links to external sites - copy over useful information and provide the link for reference. –  Frederik Nielsen Oct 16 '13 at 15:16
add comment

I use the following perl script to check when the next fsck will occur:

#!/usr/bin/perl -w

use strict;

my $mountcount = 0;
my $maxmount = 0;
my $dev;
my $mountpoint;
my $fstype;
my $debug = 0;

my $cmd = "mount";

open MOUNT, sprintf ( "%s |", $cmd ) or die sprintf ( "ERROR: Cannot execute %s - %s\n", $cmd, $! );
while ( <MOUNT> ) {
    chomp;
    ( $dev, undef, $mountpoint, undef, $fstype, undef ) = split;
    printf "Found device %s\n", $dev if ( $debug > 0 );

    if ( $fstype =~ /^ext/i ) {
        $cmd = sprintf "dumpe2fs -h %s 2>&1", $dev;
        open DUMPE2FS, sprintf ( "%s |", $cmd ) or die sprintf ( "ERROR: Unable to execute %s - %s\n", $cmd, $! );
        while ( <DUMPE2FS> ) {
            chomp;
            if ( /^Mount count:/ ) {
                ( undef, $mountcount ) = split /:/;
                $mountcount =~ s/\s*//g;
                printf "Mount count = %s\n", $mountcount if ( $debug > 0 );
            }
            if ( /^Maximum mount count:/ ) {
                ( undef, $maxmount ) = split /:/;
                $maxmount =~ s/\s*//g;
                printf "Maximum mount count = %s\n", $maxmount if ( $debug > 0 );
            }
        }
        close DUMPE2FS;

        printf "Filesystem %s, mounted on %s will be checked in %s mounts\n", $dev, $mountpoint, $maxmount - $mountcount;
    }
}
close MOUNT;

I have it run in my ~/.bashrc so I always know when my filesystems will be checked, though I use ext4 now which doesn't suffer from extended fsck times, it's still nice to know.

Typical output is something like:

Filesystem /dev/sda1, mounted on / will be checked in 5 mounts
user@localhost ~ $
share|improve this answer
    
Apparently, your script does not evaluate "Next check after:" attributes! –  xebeche Oct 5 '11 at 6:00
add comment

If you don't want to guess - do this:

touch /fastboot

and you'll be certain to avoid slow checks (or worse - a total failue if a check fails and the reboot halts)

share|improve this answer
add comment

I thought about how to get a list of filesystems more comfortably:

for D in $(mount -l -t ext3,ext2 | cut -d' ' -f1 ) ; do \
echo --- $D; tune2fs -l $D | egrep -i 'mount (count|time)|check' ; done \
| awk '
  /^--- / { mydev=$2; checked=0 }
  /^Mount count:/ { mycnt=$3 }
  /^Maximum mount count:/ { if (mycnt >= $3) checked=1 }
  /^Next check after:/ {
    cmd=("date +%s -d\"" $4 FS $5 FS $6 FS $7 FS $8"\"");
    cmd | getline mydate; close(cmd);
    if ((mydate <= (systime()+120)) || (checked == 1)) print mydev;
  }
'

I guess it could be done more elegantly but anyway here it is. If one pipes this into xargs -r df -h one could also quickly see how large the filesystems are.

Note that in the code above the time of "Next check" is compared to (NOW + 120 seconds) assuming that it takes some time until your system gets up again.

HTH

share|improve this answer
add comment

I regularly use tunefs to reset boot counts and time before doing a mid-day reboot, to prevent fsck. The difference in boot time is stunning. Afterwords I reset them to allow the next boot to fsck.

share|improve this answer
add comment

the other option is you can manually make it skip fsck checks at boot by updating the 6th field in your /etc/fstab:

/dev/sda2  /  ext3  defaults,errors=remount-ro 0       1

This is the similar to what most fstabs will have 1 means that it should be checked and is a root file system, 2 means it should be checked but will be done in parallel with other file systems and 0 means skip checking

this is also true no matter the file system

share|improve this answer
add comment

Using tune2fs -l /path/to/device:

  • If "Mount count" will be greater than "Maximum mount counts" then use -c to change the max or -C to change the count
  • If "Last Checked" is not recent enough for the "Check interval" use -i to change the interval or -T to change the last checked
share|improve this answer
    
This does assume ext2 or ext3, but is a fairly good assuption. –  David Pashley Jun 18 '09 at 21:09
    
David: the question does mention tune2fs... –  freiheit Jun 18 '09 at 21:21
add comment

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.