Switching hwclock from localtime to UTC

Hello everyone, I have the following problem: I installed 11.2 on a laptop with the hardware clock said to run on local time (CE(S)T), expecting to do a dual-boot Windows setup later. That plan got scrapped, and the to-DST switchover lately failed, so I’d like to switch the hwclock to UTC.

By now, I have (coming to work at 08:53 CEST = 06:53 UTC today):

grep ‘^^#]’ /etc/sysconfig/clock

HWCLOCK="-u"
SYSTOHC=“yes”
TIMEZONE=“Europe/Berlin”
DEFAULT_TIMEZONE=“US/Eastern”

grep -i clock /var/log/boot.msg

<7> 0.000307] hpet clockevent registered
<6> 8.107595] rtc_cmos 00:03: setting system clock to 2010-04-29 06:54:58 UTC (1272524098)

YaST2 shows checkmark for “Hardware Clock set to UTC”

  • but nonetheless, when I logged in, the OS time shown was 06:something “local” (digital panel clock) / “CEST” (‘date’ command), and ‘last’ says:

reboot system boot 2.6.31.12-0.2-de Thu Apr 29 06:54 (02:49)

(For the moment, I run ntpd to fix the issue, but I’m lucky to currently have network every day.)

What am I missing to have the OS clock be initialized correctly on bootup?

What does hwclock -u give you?

Once you have the system time correct, a manual

hwclock -u --systohc

should fix it. Also you may want to delete any /etc/adjtime to prevent it from having any effect.

> What does hwclock -u give you?

date

Thu Apr 29 10:33:30 CEST 2010

(Correct.)

hwclock -u

Thu Apr 29 10:33:17 2010 -0.286464 seconds

hwclock -u --systohc

hwclock -u

Thu Apr 29 10:33:33 2010 -0.907206 seconds

hwclock --systohc

hwclock -u

Thu Apr 29 10:33:55 2010 -0.204082 seconds

(I should probably mention that I also had to add /etc/rc.d/rc*.d/K01boot.clock symlinks - which will do a --systohc on shutdown - to stop the time from drifting further and further into the past …)

> Also you may want to delete any /etc/adjtime to prevent it from having any effect.

Thanks, I’ll try that. Though it looks correct to me, as far as I know adjtime syntax:

cat /etc/adjtime

0.000000 1272530033 0.000000
1272530033
UTC

Why don’t you set all this through Yast- System - Date and Time ?

> Why don’t you set all this through Yast- System - Date and Time ?

Umh. Because YaST2 says it is set (including the time, once the laptop got an NTP sync after boot), yet the time is off everytime I boot?

Have you set your time zone correctly? Both in Yast and the desktop clock.

Desktop clock, YaST2, /etc/sysconfig/clock and date all agree that my local time is that of Germany (and, where applicable, that the RTC is set to UTC).

Quick experiment before I call it a day … :

/etc # /etc/init.d/ntp stop
Shutting down network time protocol daemon (NTPD) done
/etc # date;hwclock -u;ls -l adj*;init.d/boot.clock stop;date;hwclock -u;ls -l adj*;sleep 60;init.d/boot.clock start;date;hwclock -u;ls -l adj*
Thu Apr 29 20:04:20 CEST 2010
Thu Apr 29 20:04:21 2010 -0.532195 seconds
-rw-r–r-- 1 root root 44 Apr 29 10:33 adjtime.bak
The System Time is in sync with Hardware Clock good
Thu Apr 29 20:04:21 CEST 2010
Thu Apr 29 20:04:22 2010 -0.953602 seconds
-rw-r–r-- 1 root root 44 Apr 29 10:33 adjtime.bak
The System Time is in sync with Hardware Clock good
Thu Apr 29 20:05:22 CEST 2010
Thu Apr 29 20:05:23 2010 -0.938045 seconds
-rw-r–r-- 1 root root 44 Apr 29 10:33 adjtime.bak

Hm. If it does the exact same thing tomorrow morning, I’d be fine …

> If it does the exact same thing tomorrow morning, I’d be fine …

No dice. :-/

/etc/init.d/ntp stop

Shutting down network time protocol daemon (NTPD) done

date

Fri Apr 30 07:07:28 CEST 2010

(Correct time is 7:07 UTC / 9:07 CEST.)

ls -l /etc/adj*

-rw-r–r-- 1 root root 16 Apr 30 07:06 /etc/adjtime
-rw-r–r-- 1 root root 44 Apr 29 10:33 /etc/adjtime.bak

cat /etc/adjtime

0.0 0 0.0
0
UTC

hwclock

Fri Apr 30 09:08:46 2010 -0.469791 seconds

hwclock -u

Fri Apr 30 09:08:49 2010 -0.422803 seconds

dmesg | egrep -i ‘(clock|time^A-Za-z])’

0.000307] hpet clockevent registered
0.121242] Time:  7:05:40  Date: 04/30/10
2.316424] rtc_cmos 00:03: setting system clock to 2010-04-30 07:05:42 UTC (1272611142)
3.000033] Clocksource tsc unstable (delta = -148904953 ns)

Old CMOS battery?

I’d hope not (refurbished laptop bought only months ago), though I wouldn’t know offhand how to check that. But … if the CMOS batt were failing, the RTC should get reset to a fixed value, rather than lagging 2h behind the correct time on every boot, right?

Alright everyone, at least I located the problem now …

# egrep '^       ]*(-_|A-Za-z]*\)|(if|elif|else) |fi$)' /etc/init.d/boot.clock.orig
    if test -e /dev/rtc ; then
    fi
    if test -z "$(/sbin/modprobe -l rtc_cmos)" ; then
    fi
    if /sbin/modprobe -q rtc_cmos ; then
        if test $start -lt $end ; then
        fi
    fi
    start|restart|reload|force-reload)
        if test -n "$SYSTEM_TIME_INCORRECT" ; then
        fi
        if test "$USE_HWCLOCK" != yes ; then
            if test -n "$TIMEZONE" -a -x /usr/sbin/zic ; then
            fi
        fi
        if test "$ELEVENMIN_MODE" = yes ; then
        fi
        if test "$USE_ADJFILE" = yes ; then
            if test ! -s /etc/adjtime ; then
        fi
    stop)
        if test "$ELEVENMIN_MODE" = yes ; then
        fi
        if test "$USE_HWCLOCK" = yes -a "$SYSTOHC" = yes ; then
            if test "$USE_ADJFILE" = yes ; then
            fi
        fi
    timezone)
        if test "$USE_HWCLOCK" = yes ; then
        fi
    status)

Note that within the code for the “start” case, there is NO branch for the “$USE_HWCLOCK” = “yes” situation.

The debug code I added to the start script starts its log as follows:

# head -7 /var/tmp/clockstart.log

### START called, TZ:
### Runlevel: unknown
### Called as: /etc/init.d/boot.clock start
### Hardware Clock: Tue May  4 12:10:10 2010  -0.234620 seconds
### System Time: Tue May  4 10:10:10 CEST 2010

So something sets the system time to the wrong value I observe even before the usual boot scripts get run, and /etc/init.d/boot.clock does nothing when run. The culprit most likely is the initrd:

/boot # lsinitrd initrd 2>/dev/null | grep clock
etc/sysconfig/clock
bin/warpclock
boot/05-clock.sh

Soooo … I need to create updated initrd’s to properly change the RTC settings. :sarcastic:

(Or quite possibly I’ll bail out and add the “missing” branch to boot.clock, doing a “hwclock -u --hctosys”.)

Update: After reading up on “mkinitrd”, I took the leap of faith and ran it (without params). Problem gone, and everything still seems to work.<:)

P.S.: New question: How do I add “[solved]” to the thread title … ?

Glad you got it fixed but not sure why you had to do it. It certainly is not “normal”.

Currently can not mark threads “solved”.