openSuse 13.2 gets time wrong from hwclock

Hello,
after setting my parallel installation of Windows 7 to use UTC instead of local time, because I wanted to get rid of the time error, now Linux gets the time wrong from the hwclock.
The RTC has ever been in UTC.
As I write this it is 22:17 UTC or 00:17 in my time zone (+2).
Everytime I reboot Linux (without starting Windows in between) 2 hours will be substracted. To show this I set the time with “ntpd -qg” and wrote it to the RTC with “hwclock --systohc”. My timezone is set with:

/etc/localtime -> ../usr/share/zoneinfo/Europe/Budapest

After rebooting I get the following output from “timedatectl” and “hwclock --debug”

      Local time: Tue 2015-06-23 22:17:14 CEST
  Universal time: Tue 2015-06-23 20:17:14 UTC
        RTC time: Tue 2015-06-23 22:17:14
        Timezone: Europe/Budapest (CEST, +0200)
     NTP enabled: no
NTP synchronized: no
 RTC in local TZ: no
      DST active: yes
 Last DST change: DST began at
                  Sun 2015-03-29 01:59:59 CET
                  Sun 2015-03-29 03:00:00 CEST
 Next DST change: DST ends (the clock jumps one hour backwards) at
                  Sun 2015-10-25 02:59:59 CEST
                  Sun 2015-10-25 02:00:00 CET

hwclock from util-linux 2.25.1
Using the /dev interface to the clock.
Last drift adjustment done at 1435096061 seconds after 1969
Last calibration done at 1435096061 seconds after 1969
Hardware clock is on UTC time
Assuming hardware clock is kept in UTC time.
Waiting for clock tick...
...got clock tick
Time read from Hardware Clock: 2015/06/23 22:15:54
Hw clock time : 2015/06/23 22:15:54 = 1435097754 seconds since 1969
Wed Jun 24 00:15:54 2015  -0.922492 seconds

As you can see, the hwclock is right, but the system time is not.
Do you know how this can happen?

Hi
You need to go into the BIOS and ensure it’s time is set to UTC, in Windows I’m assuming you added RealTimeIsUniversal? Then ensure via YaST date and time the box is checked for UTC and adjust the timezone and time manually if incorrect…

In my BIOS there is no option to set the time to UTC, but the time is already 2 hours late.
You are right, in Windows I added RealTimeIsUniversal and in YaST the timezone is correct and UTC is selected.
I changed and rechanged the settings and rebooted, but the problem is still there.

On 2015-06-24 00:36, kupferstadt wrote:
>
> Hello,
> after setting my parallel installation of Windows 7 to use UTC instead
> of local time, because I wanted to get rid of the time error, now Linux
> gets the time wrong from the hwclock.
> The RTC has ever been in UTC.
> As I write this it is 22:17 UTC or 00:17 in my time zone (+2).
> Everytime I reboot Linux (without starting Windows in between) 2 hours
> will be substracted.


su -
rm /etc/adjtime
date

Check that the time as shown by “date” is correct. That file remembers
your previous setting…


Cheers / Saludos,

Carlos E. R.
(from 13.1 x86_64 “Bottle” at Telcontar)

I removed “/etc/adjtime” and after setting the time with ntpd the output with date is correct, after rebooting 2 hours late.

On 2015-06-24 01:16, kupferstadt wrote:
>
> In my BIOS there is no option to set the time to UTC, but the time is
> already 2 hours late.
> You are right, in Windows I added RealTimeIsUniversal

Wait. You don’t have to change Windows to UTC; you can have local time.
You have to do a change in the registry that tells Windows to calculate
the UTC and store that in the CMOS or BIOS clock.

https://en.opensuse.org/SDB%3AConfiguring_the_clock#Other_OS

It is different.

The concept is the same as openSUSE does, with the setting in YaST.

Run this and paste it here:


su -
date --utc
date --rfc-3339=seconds
hwclock --debug
cat /etc/adjtime
cat /etc/sysconfig/clock | egrep -v "^:space:]]*$|^#"

Make sure Windows shows the correct time. Reboot to Linux. If time is
incorrect (if you are running the ntp daemon, stop it), correct it
using command line in a terminal as root (man date). Check that
time, date, and time zone are correct. Then, issue:


rm /etc/adjtime
hwclock --systohc --utc
hwclock --debug
date

The last two commands should show the correct time and date.


Cheers / Saludos,

Carlos E. R.

(from 13.1 x86_64 “Bottle” (Minas Tirith))

As Carlos describes, you can’t simply check the UTC checkbox in Windows to set to UTC, you need to manually make the Registry fix.

Probably the original and most complete information on doing this is at ArchLinux Wiki
https://wiki.archlinux.org/index.php/Time#UTC_in_Windows

It should be noted that modern distros that use systemd default to UTC so it shouldn’t be an issue for openSUSE 13.2 in any scenario.

TSU

He did not. Please google for RealTimeIsUniversal in Windows. Also he said in the very first post:

This really needs stepping through the boot process starting with early in initrd to find out at which point time is changing. As it is 13.2, I would start with booting with “rd.break”; this will stop just before switching to real root in dracut. Is time still correct here? If not, it is possible to break really early using rd.break=cmdline, before virtually anything runs.

… somehow all this rings the bell … do you have NTPD_FORCE_SYNC_HWCLOCK_ON_STARTUP set?

On 2015-06-27 08:46, arvidjaar wrote:
>
> robin_listas;2716668 Wrote:
>>
>> Wait. You don’t have to change Windows to UTC
>
> He did not. Please google for RealTimeIsUniversal in Windows.

Can you point to a good article on this, so that we (I, probably) can
add the information on the openSUSE wiki article?

I just googled it, but I can’t find what it is about. Just reports on
bugs and problems.

> Also he
> said in the very first post:kupferstadt Wrote:
>> Everytime I reboot Linux (without starting Windows in between) 2 hours
>> will be substracted
>
> This really needs stepping through the boot process starting with early
> in initrd to find out at which point time is changing. Unfortunately I
> miss openSUSE version so I cannot give any recommendations here.

In the past, this was always solved via removing /etc/adjtime and
resetting the clock, as I posted.

He is using 13.2, as stated in the thread subject tittle.

Maybe running mkinitrd would help.


Cheers / Saludos,

Carlos E. R.

(from 13.1 x86_64 “Bottle” (Minas Tirith))

Something like this? Time - ArchWiki

He is using 13.2, as stated in the thread subject tittle.

Yes, I realized that when I pressed submit button. You probably do not get article updates. I believe I remember this problem and I think it was caused by ntp startup scripts that incorrectly assumed local time always. So disabling ntp to test if it changes anything makes sense.

On 2015-06-27 13:16, arvidjaar wrote:
>
> robin_listas;2717067 Wrote:

> Something like this?
> https://wiki.archlinux.org/index.php/Time#UTC_in_Windows

Ah! Ok, it is the regedit change, that it has that name. Then I know
about it :slight_smile:

Meanwhile I found this interesting background article:

http://www.cl.cam.ac.uk/~mgk25/mswish/ut-rtc.html
IBM PC Real Time Clock should run in UT

>> He is using 13.2, as stated in the thread subject tittle.
>>
>
> Yes, I realized that when I pressed submit button. You probably do not
> get article updates.

only if the update happens before the minute ends in …6. At that point
it is sent and I don’t see any more changes…

> I believe I remember this problem and I think it
> was caused by ntp startup scripts that incorrectly assumed local time
> always. So disabling ntp to test if it changes anything makes sense.

Ah…

:-?


Cheers / Saludos,

Carlos E. R.

(from 13.1 x86_64 “Bottle” (Minas Tirith))

As you already figured out, I used the RealTimeIsUniversal registry fix for Windows to set it to use UTC (of course it shows the real time).

As you proposed I tried to fix my issues with your code:

I got this output with the time already 4 hours late as I rebooted twice since the last adjustment. The HW-Clock is just 2 hours late, probably it gets set, when I shut Linux down. ntpd is already disabled.

linux-knd0:~ # date --utc
Tue Jun 30 06:15:11 UTC 2015
linux-knd0:~ # date --rfc-3339=seconds
2015-06-30 08:15:11+02:00
linux-knd0:~ # hwclock --debug
hwclock from util-linux 2.25.1
Using the /dev interface to the clock.
Last drift adjustment done at 1435131275 seconds after 1969
Last calibration done at 1435131275 seconds after 1969
Hardware clock is on UTC time
Assuming hardware clock is kept in UTC time.
Waiting for clock tick...
...got clock tick
Time read from Hardware Clock: 2015/06/30 08:15:12
Hw clock time : 2015/06/30 08:15:12 = 1435652112 seconds since 1969
Tue Jun 30 10:15:12 2015  -0.797687 seconds
linux-knd0:~ # cat /etc/adjtime
0.000000 1435131275 0.000000
1435131275
UTC
linux-knd0:~ # cat /etc/sysconfig/clock | egrep -v "^:space:]]*$|^#"
TIMEZONE="Europe/Berlin"
DEFAULT_TIMEZONE="Europe/Berlin"

I rebooted to Windows, set the correct time, rebootet again to linux and set the time with

 date --set "Tue Jun 30 10:35:01 UTC 2015"

Now my laptop shows the correct time, I issued:

linux-knd0:~ # rm /etc/adjtime
linux-knd0:~ # hwclock --systohc --utc
linux-knd0:~ # hwclock --debug
hwclock from util-linux 2.25.1
Using the /dev interface to the clock.
Last drift adjustment done at 1435660577 seconds after 1969
Last calibration done at 1435660577 seconds after 1969
Hardware clock is on UTC time
Assuming hardware clock is kept in UTC time.
Waiting for clock tick...
...got clock tick
Time read from Hardware Clock: 2015/06/30 10:36:19
Hw clock time : 2015/06/30 10:36:19 = 1435660579 seconds since 1969
Tue Jun 30 12:36:19 2015  -0.500713 seconds
linux-knd0:~ # date
Tue Jun 30 12:36:25 CEST 2015

I will reboot and we will see if it did the trick.

EDIT: It didn’t

NTPD_FORCE_SYNC_HWCLOCK_ON_STARTUP is set, but as I stopped ntpd, this shouldn’t do anything, should it?
I will try to step trough the boot process with rd.break, if the fix above does not work.

On 2015-06-30 13:06, kupferstadt wrote:
>
> As you already figured out, I used the RealTimeIsUniversal registry fix
> for Windows to set it to use UTC (of course it shows the real time).

Ok. That part clarified :slight_smile:

> I got this output with the time already 4 hours late as I rebooted twice
> since the last adjustment. The HW-Clock is just 2 hours late, probably
> it gets set, when I shut Linux down. ntpd is already disabled.
>
>
> Code:
> --------------------
> linux-knd0:~ # date --utc
> Tue Jun 30 06:15:11 UTC 2015
> linux-knd0:~ # date --rfc-3339=seconds
> 2015-06-30 08:15:11+02:00
> linux-knd0:~ # hwclock --debug
> hwclock from util-linux 2.25.1
> Using the /dev interface to the clock.
> Last drift adjustment done at 1435131275 seconds after 1969
> Last calibration done at 1435131275 seconds after 1969
> Hardware clock is on UTC time
> Assuming hardware clock is kept in UTC time.
> Waiting for clock tick…
> …got clock tick
> Time read from Hardware Clock: 2015/06/30 08:15:12
> Hw clock time : 2015/06/30 08:15:12 = 1435652112 seconds since 1969
> Tue Jun 30 10:15:12 2015 -0.797687 seconds
> linux-knd0:~ # cat /etc/adjtime
> 0.000000 1435131275 0.000000
> 1435131275
> UTC
> linux-knd0:~ # cat /etc/sysconfig/clock | egrep -v “^:space:]]*$|^#”
> TIMEZONE=“Europe/Berlin”
> DEFAULT_TIMEZONE=“Europe/Berlin”
> --------------------

Well, the issue is that the CMOS clock should have 06:15:11, UTC, but it
has 10:15:12 2015, and it says that is UTC. That’s the problem, that the
UTC time is not stored on the CMOS.

>
>
> I rebooted to Windows, set the correct time, rebootet again to linux and
> set the time with
>
> Code:
> --------------------
> date --set “Tue Jun 30 10:35:01 UTC 2015”
> --------------------
>
> Now my laptop shows the correct time, I issued:
>
> Code:
> --------------------
> linux-knd0:~ # rm /etc/adjtime
> linux-knd0:~ # hwclock --systohc --utc
> linux-knd0:~ # hwclock --debug
> hwclock from util-linux 2.25.1
> Using the /dev interface to the clock.
> Last drift adjustment done at 1435660577 seconds after 1969
> Last calibration done at 1435660577 seconds after 1969
> Hardware clock is on UTC time
> Assuming hardware clock is kept in UTC time.
> Waiting for clock tick…
> …got clock tick
> Time read from Hardware Clock: 2015/06/30 10:36:19
> Hw clock time : 2015/06/30 10:36:19 = 1435660579 seconds since 1969
> Tue Jun 30 12:36:19 2015 -0.500713 seconds
> linux-knd0:~ # date
> Tue Jun 30 12:36:25 CEST 2015
>
> --------------------

But you see, the CMOS clock is still 10:36:19, it was not set to 06:36.

IMO, there is a bug in Linux hwclock or in your BIOS: your CMOS clock
can not be set correctly.

>
> I will reboot and we will see if it did the trick.
>
> EDIT: It didn’t

No surprise…

> NTPD_FORCE_SYNC_HWCLOCK_ON_STARTUP is set, but as I stopped ntpd, this
> shouldn’t do anything, should it?
> I will try to step trough the boot process with rd.break, if the fix
> above does not work.

I don’t think it will help.

You can use ntp (rcntp ntptimeset) early at boot to force the clock to
be corrected. As a hack.


Cheers / Saludos,

Carlos E. R.

(from 13.1 x86_64 “Bottle” (Minas Tirith))

Why should the CMOS clock be set to 06:36? I set it to 10:35 UTC which is 12:35 CEST.

I think the first question is whether time gets reset on startup or shutdown. So the first test would be to verify that RTC matches current system time and then shutdown and go to BIOS to check. If time is wrong, it is reset on shutdown.

On 2015-06-30 20:46, arvidjaar wrote:
>
> I think the first question is whether time gets reset on startup or
> shutdown. So the first test would be to verify that RTC matches current
> system time and then shutdown and go to BIOS to check. If time is wrong,
> it is reset on shutdown.
>
>
Look at this sequence:


linux-knd0:~ # date --utc
Tue Jun 30 06:15:11 UTC 2015

linux-knd0:~ # hwclock --debug
....
Hardware clock is on UTC time
Assuming hardware clock is kept in UTC time.
....
Hw clock time : 2015/06/30 08:15:12 = 1435652112 seconds since 1969


linux-knd0:~ # rm /etc/adjtime
linux-knd0:~ # hwclock --systohc --utc
linux-knd0:~ # hwclock --debug
....
Hardware clock is on UTC time
Assuming hardware clock is kept in UTC time.
....
Time read from Hardware Clock: 2015/06/30 10:36:19
Hw clock time : 2015/06/30 10:36:19 = 1435660579 seconds since 1969
Tue Jun 30 12:36:19 2015  -0.500713 seconds
linux-knd0:~ # date
Tue Jun 30 12:36:25 CEST 2015

UTC is 06:15 at the start of the sequence. After he issues hwclock to
copy the system clock to the cmos, the cmos clock still shows 10:36:19 !!!

So the CMOS clock IS NOT SET! How can that be?

Unless what he printed is not the full sequence…


Cheers / Saludos,

Carlos E. R.

(from 13.1 x86_64 “Bottle” (Minas Tirith))

And local clock at the same time shows 12:36. Where is the problem?

On 2015-07-01 05:16, arvidjaar wrote:
>
> robin_listas;2717549 Wrote:
>> After he issues hwclock to
>> copy the system clock to the cmos, the cmos clock still shows 10:36:19
>> !!!
>
> And local clock at the same time shows 12:36. Where is the problem?

I think that the two separate runs of commands confused me.


Cheers / Saludos,

Carlos E. R.

(from 13.1 x86_64 “Bottle” (Minas Tirith))

I think I am seeing the same problem (in Tumbleweed).

I know why. I accidentally forgot to check the “HW clock uses UTC” box during install. There ought to be a way of fixing that short of a reinstall. I’ve changed everything that I know about (including “/etc/adjtime”).

Right now, I have “ntpd” service disabled. That way, the harware clock stays correct but system time is 5 hours off. If I run “ntpd”, then system time is correct, but hardware clock time is reset to 5 hours off.

Is systemd setting the clock offset somewhere that I don’t know about?

If timedatectl shows the correct values, the saved settings should be ok, I’d say.

But AFAIK the system time is already set by the initrd. If there are wrong settings in there, it might cause a time offset.
I would suggest to recreate the initrd.

You did change the “HW clock uses UTC” in YaST meanwhile? Actually I thought that would recreate the initrd automatically anyway…

PS: Maybe try to run this to switch to “HW clock uses UTC”:

timedatectl set-local-rtc 0

Or maybe try to switch the RTC to local time (“timedatectl set-local-rtc 1”) and back.