How can I avoid "Run fsck manually" messages while allowing experimenting with system time changes?

13,583

Solution 1

I was going to suggest hacking e2fsck to disable the specific checks for a last mount time or last write times in the future. These are defined in problem.c / problem.h, and used in super.c. But in looking, I discovered that E2fsprogs 1.41.10 adds a new option to /etc/e2fsck.conf called broken_system_clock. This seems to be exactly what you need, and since you're using Red Hat Enterprise Linux 6, you should have 1.41.12, which includes this option. From the man page:

   broken_system_clock
          The e2fsck(8) program has some hueristics that assume  that  the
          system clock is correct.  In addition, many system programs make
          similar assumptions.  For example, the UUID library  depends  on
          time  not going backwards in order for it to be able to make its
          guarantees about issuing universally unique ID’s.  Systems  with
          broken  system clocks, are well, broken.  However, broken system
          clocks, particularly in embedded systems, do exist.  E2fsck will
          attempt  to  use  hueristics to determine if the time can no tbe
          trusted; and to skip time-based checks if this is true.  If this
          boolean  is set to true, then e2fsck will always assume that the
          system clock can not be trusted.

Yes, the man page can't spell "heuristics". Oops. But presumably the code works anyway. :)

Solution 2

I doubt there's a way to remove this check specifically, short of modifying the source code. Ignoring all errors from fsck sounds dangerous, what if there was some other problem?

Therefore I'll suggest the following workaround: change the boot scripts to set the system date to some time in the future (say 2038-01-18 on a 32-bit machine) just before running fsck, and read it back from the hardware clock afterwards (hwclock --hctosys, with more options as needed depending on your hardware and use of GMT in the hardware clock.)

Share:
13,583
me_and
Author by

me_and

L3 support engineer for Metaswitch Networks (stuff posted here isn't on behalf of my company &c. &c.). I hack around in Python, spend more time than I'd like with shell, and am proficient if somewhat rusty with C. I'm also the Git maintainer for Cygwin and a contributor to Dreamwidth. You can also find me in a wide variety of larp fields, or on Twitter, Facebook, Google+, Wikipedia (which has by far the most complete profile), and other places by request.

Updated on September 17, 2022

Comments

  • me_and
    me_and about 1 year

    I'm working with a system where we want to allow users to play around with the date and time if they want, and where reboots may happen arbitrarily. This is fine, except for one thing: if there's a large time jump backwards, the following error appears on reboot:

    Checking filesystems
    IMAGE2: Superblock last mount time (Tue Mar  1 17:32:48 2011,
            now = Thu Feb 24 17:34:29 2011) is in the future.
    
    IMAGE2: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.
            (i.e., without -a or -p options)
    
    *** An error occurred during the file system check.
    *** Dropping you to a shell; the system will reboot
    *** when you leave the shell.
    

    …and then the boot hangs waiting for user console input, and even once console access is gained, requires a root password to continue.

    This is decidedly less than ideal. Is there any way to either skip the check or force the check to happen automatically on reboot?

    Google has only provided help that requires running fsck manually if/when this is hit, which is not what I'm after. Running fsck manually after setting the time doesn't work as the filesystem is still mounted at that point, and just disabling fsck entirely is less than ideal.

    I'm using RedHat 6.

    Update: The solution I'm currently going with is to hack fstab to disable fsck checking on reboot. I'd tried editing the last mount time on the disks using debugfs, which works fine for ext3 drives, but appears to fail inconsistently on ext4.

  • me_and
    me_and over 12 years
    Running in a VM is really not an option for us, and in any case just reverting to a snapshot means we remove all the other state the user may have set up.
  • me_and
    me_and over 12 years
    Would this not mean the next time around that there'd be a window in which we could hit the same bug again? i.e. the last mount time is 2038-01-18, so if the current time is set to that too, there's a race condition in which we're (as far as the system's concerned) trying to mount before the last mount again.
  • Gilles 'SO- stop being evil'
    Gilles 'SO- stop being evil' over 12 years
    @me_and: Yes, I'm afraid my kludge won't help against malicious users. If that's what you're up against, patching fsck looks to be the best option.
  • me_and
    me_and over 12 years
    That looks fantastic, save that the man page implies it only affects ext2 and ext3, and I'm using a combination of ext3 and ext4. Still, I'll go try it now, as if it works, it's exactly what I'm looking for.
  • me_and
    me_and over 12 years
    It works! Including on ext4. Thank you!