# use the fixrtc cmdline option in your bootloader to
# automatically set the hardware clock to the date of
# the last mount of your root filesystem to avoid fsck
# to get confused by the superblock being in the future
BROKEN_CLOCK=""
for x in $(cat /proc/cmdline); do
case ${x} in
root=*) UUID=${x#*=} UUID="${UUID#*=}"
;;
fixrtc) BROKEN_CLOCK=1
;;
esac
done
if [ -n $BROKEN_CLOCK ];then ROOTDISK=$(readlink -f /dev/disk/by-uuid/$UUID)
TIMESTR=$(dumpe2fs -h $ROOTDISK 2>/dev/null|grep "Last mount time") TIME=${TIMESTR#*:}
ok, here a tested and properly working set of two script snippets of the initramfs suggestion above:
ogra@ubuntu:~$ cat /usr/share/ initramfs- tools/hooks/ fixclock
#!/bin/sh -e
# initramfs hook for fixclock
MINKVER="2.6.24"
PREREQ=""
# Output pre-requisites
prereqs()
{
echo "$PREREQ"
}
case "$1" in
prereqs)
prereqs
exit 0
;;
esac
. /usr/share/ initramfs- tools/hook- functions
# We use date, hwclock and dumpe2fs
copy_exec /bin/date /bin
copy_exec /sbin/hwclock /sbin
copy_exec /sbin/dumpe2fs /sbin
ogra@ubuntu:~$ cat /usr/share/ initramfs- tools/scripts/ init-premount/ fixclock
#!/bin/sh -e
# initramfs init-top script for udev
PREREQ="udev"
# Output pre-requisites
prereqs()
{
echo "$PREREQ"
}
case "$1" in
prereqs)
prereqs
exit 0
;;
esac
# use the fixrtc cmdline option in your bootloader to
# automatically set the hardware clock to the date of
# the last mount of your root filesystem to avoid fsck
# to get confused by the superblock being in the future
BROKEN_CLOCK=""
for x in $(cat /proc/cmdline); do
UUID= ${x#*=}
UUID= "${UUID# *=}"
BROKEN_ CLOCK=1
case ${x} in
root=*)
;;
fixrtc)
;;
esac
done
if [ -n $BROKEN_CLOCK ];then
ROOTDISK= $(readlink -f /dev/disk/ by-uuid/ $UUID)
if [ $DISKYEAR -gt $CLOCKYEAR ]; then
hwclock --set --date="${TIME}"
hwclock --hctosys
fi
fi