Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[solved] wrong system time
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
Lokesh
Apprentice
Apprentice


Joined: 01 Apr 2012
Posts: 161

PostPosted: Mon Jul 31, 2017 9:56 am    Post subject: [solved] wrong system time Reply with quote

Hello,
my systemdate is wrong (compare to the time of this post):
Code:
date
Mo 31. Jul 13:55:45 CEST 2017

which is surprising since
Code:
cat /etc/timezone
Europe/Paris
followed by emerge --config sys-libs/timezone-data as per handbook.

I also tried one of the tools:
Code:
tzselect
...
...
...
Therefore TZ='Europe/Paris' will be used.
Selected time is now:   Mon Jul 31 13:32:25 CEST 2017.
Universal Time is now:  Mon Jul 31 11:32:25 UTC 2017.
Is the above information OK?
1) Yes
2) No
#? 1

You can make this change permanent for yourself by appending the line
        TZ='Europe/Paris'; export TZ
to the file '.profile' in your home directory; then log out and log in again.

Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
Europe/Paris


I know that it is possible to use ntp at boot, but that's a workaround. There were quite a number of posts over the years in the internet, but solutions were either not applicable (different Linux), or ntp, etc. Surprisingly nothing on Gentoo, although I am having this problem in all my installs/reinstalls over the past months.

Cheers
Lokesh
_________________
Sometimes frustrated Linux User


Last edited by Lokesh on Tue Aug 01, 2017 1:59 pm; edited 1 time in total
Back to top
View user's profile Send private message
charles17
Advocate
Advocate


Joined: 02 Mar 2008
Posts: 3664

PostPosted: Mon Jul 31, 2017 11:06 am    Post subject: Reply with quote

Have you worked through the System time wiki article?
Back to top
View user's profile Send private message
Lokesh
Apprentice
Apprentice


Joined: 01 Apr 2012
Posts: 161

PostPosted: Mon Jul 31, 2017 11:46 am    Post subject: Reply with quote

charles17 wrote:
Have you worked through the System time wiki article?
I mentioned above that I configured the timezone-data according to the handbook, it should imply that I did the whole procedure following it.
_________________
Sometimes frustrated Linux User
Back to top
View user's profile Send private message
Fitzcarraldo
Advocate
Advocate


Joined: 30 Aug 2008
Posts: 2037
Location: United Kingdom

PostPosted: Mon Jul 31, 2017 11:53 am    Post subject: Re: wrong system time Reply with quote

Lokesh wrote:
Surprisingly nothing on Gentoo, although I am having this problem in all my installs/reinstalls over the past months.

In addition to the aforementioned Gentoo Wiki article System time, see also Configuring the Linux clock (the first part covers installations that use OpenRC, the second part covers installations that use systemd).
_________________
Clevo W230SS: amd64, VIDEO_CARDS="intel modesetting nvidia".
Compal NBLB2: ~amd64, xf86-video-ati. Dual boot Win 7 Pro 64-bit.
OpenRC systemd-utils[udev] elogind KDE on both.

My blog
Back to top
View user's profile Send private message
Tony0945
Watchman
Watchman


Joined: 25 Jul 2006
Posts: 5127
Location: Illinois, USA

PostPosted: Mon Jul 31, 2017 12:54 pm    Post subject: Reply with quote

NTP may be a workaround, but it's a useful workaround. My clock loses two seconds per day, so (instead of the daemon running constantly), I use ntp to check at boot and have a cron job to sync twice a day so it's never more than one second off.

The time can jump by hours if you dual boot with Windows, but have no idea what could throw you off by days. Consider ntp at boot and once daily. See how it goes.
Back to top
View user's profile Send private message
Lokesh
Apprentice
Apprentice


Joined: 01 Apr 2012
Posts: 161

PostPosted: Mon Jul 31, 2017 1:12 pm    Post subject: Re: wrong system time Reply with quote

Fitzcarraldo wrote:
In addition to the aforementioned Gentoo Wiki article System time, see also Configuring the Linux clock (the first part covers installations that use OpenRC, the second part covers installations that use systemd).

I have seen your blog earlier when searching for a solution n the internet. However, I am getting somewhat weird results:
Code:
hwclock --utc --> time 2 hours ahead of mine
hwclock --localtime --> correct time

Next, I did the edits as per your blog (/etc/adjtime does not exits)
Code:
nano /etc/conf.d/hwclock
clock="local"
clock_hctosys="YES"
clock_systohc="YES

Rebootet and:
Code:
hwclock --utc --> time 4 hours ahead of mine
hwclock --localtime --> 2 hours ahead of mine

In other words: I am getting the same wrong time after setting hwclock from "utc" to "local".

Before going back to ntp sync at boot I would prefer to find out what is wrong here.
_________________
Sometimes frustrated Linux User
Back to top
View user's profile Send private message
Fitzcarraldo
Advocate
Advocate


Joined: 30 Aug 2008
Posts: 2037
Location: United Kingdom

PostPosted: Mon Jul 31, 2017 1:24 pm    Post subject: Re: wrong system time Reply with quote

Lokesh wrote:
Next, I did the edits as per your blog (/etc/adjtime does not exits)
Code:
nano /etc/conf.d/hwclock
clock="local"
clock_hctosys="YES"
clock_systohc="YES

Actually my blog post has a caveat regarding setting clock_systohc="YES and clock_hctosys="YES": what do you have in your kernel configuration for CONFIG_RTC_SYSTOHC and CONFIG_RTC_HCTOSYS? Also, are you dual-booting with either another Linux distribution or with Windows? If not, why don't you make clock="UTC"? The system clock can still show local time. That's how mine is configured.
_________________
Clevo W230SS: amd64, VIDEO_CARDS="intel modesetting nvidia".
Compal NBLB2: ~amd64, xf86-video-ati. Dual boot Win 7 Pro 64-bit.
OpenRC systemd-utils[udev] elogind KDE on both.

My blog
Back to top
View user's profile Send private message
Lokesh
Apprentice
Apprentice


Joined: 01 Apr 2012
Posts: 161

PostPosted: Mon Jul 31, 2017 2:01 pm    Post subject: Re: wrong system time Reply with quote

Fitzcarraldo wrote:
what do you have in your kernel configuration for CONFIG_RTC_SYSTOHC and CONFIG_RTC_HCTOSYS
Code:
# CONFIG_RTC_HCTOSYS is not set
CONFIG_RTC_SYSTOHC=y

I did not touch this, these are default settings.
Fitzcarraldo wrote:
Also, are you dual-booting with either another Linux distribution or with Windows? If not, why don't you make clock="UTC"? The system clock can still show local time. That's how mine is configured.
Yes, I am dualbooting with another Linux. But the other one is called few times only a week, I don't think it changed the hwclock (haven't tested it though).

My preference would be UTC! From your blog though I understood that if hwclock --localtime gives the correct time it is the one to chose. So reverting the changes I did to /etc/conf.d/hwclock?

Lokesh
_________________
Sometimes frustrated Linux User
Back to top
View user's profile Send private message
Fitzcarraldo
Advocate
Advocate


Joined: 30 Aug 2008
Posts: 2037
Location: United Kingdom

PostPosted: Mon Jul 31, 2017 2:13 pm    Post subject: Reply with quote

You're misunderstanding what I wrote. Set the following:

Code:
clevow230ss fitzcarraldo # grep -v "^#\|^$" /etc/conf.d/hwclock
clock="UTC"
clock_args=""


This is my kernel configuration:

Code:
# CONFIG_RTC_HCTOSYS is not set
CONFIG_RTC_SYSTOHC=y


Code:
clevow230ss fitzcarraldo # hwclock --utc
2017-07-31 15:18:42.020226+0:00
clevow230ss fitzcarraldo # date
Mon 31 Jul 15:18:41 BST 2017
clevow230ss fitzcarraldo # hwclock
2017-07-31 15:18:57.687103+0:00

The command 'hwclock --utc' tells your installation that the hardware clock contains UTC.

Notice what I wrote in my blog post:

Quote:
The hwclock command always shows local time, even if you keep your hardware clock in UTC.

_________________
Clevo W230SS: amd64, VIDEO_CARDS="intel modesetting nvidia".
Compal NBLB2: ~amd64, xf86-video-ati. Dual boot Win 7 Pro 64-bit.
OpenRC systemd-utils[udev] elogind KDE on both.

My blog


Last edited by Fitzcarraldo on Mon Jul 31, 2017 2:23 pm; edited 1 time in total
Back to top
View user's profile Send private message
josephg
l33t
l33t


Joined: 10 Jan 2016
Posts: 783
Location: usually offline

PostPosted: Mon Jul 31, 2017 2:21 pm    Post subject: Re: wrong system time Reply with quote

Lokesh wrote:
I am dualbooting with another Linux. But the other one is called few times only a week, I don't think it changed the hwclock (haven't tested it though).

check that your time settings across all your (dualbooting) systems are the same.
_________________
"Growth for the sake of growth is the ideology of the cancer cell." Edward Abbey
Back to top
View user's profile Send private message
Lokesh
Apprentice
Apprentice


Joined: 01 Apr 2012
Posts: 161

PostPosted: Mon Jul 31, 2017 2:34 pm    Post subject: Reply with quote

Fitzcarraldo wrote:
Code:
clevow230ss fitzcarraldo # hwclock --utc
2017-07-31 15:18:42.020226+0:00
clevow230ss fitzcarraldo # date
Mon 31 Jul 15:18:41 BST 2017
clevow230ss fitzcarraldo # hwclock
2017-07-31 15:18:57.687103+0:00

So I used the very same settings as you did, and the outcome is:
Code:
date
Mo 31. Jul 18:27:29 CEST 2017
lokesh@Gentoo ~ $ sudo hwclock
2017-07-31 20:27:35.812221+1:0
This is were I started, the clock is 2 hours ahead of my time. Hardware clock is even 4 hours in the future ...

Since I am not rebooting in between these settings, the other Linux installation should not be able to interfere (btw: there the time is correct without ntp syncing).

Seems I am back to square one. :cry:
_________________
Sometimes frustrated Linux User
Back to top
View user's profile Send private message
Fitzcarraldo
Advocate
Advocate


Joined: 30 Aug 2008
Posts: 2037
Location: United Kingdom

PostPosted: Mon Jul 31, 2017 3:23 pm    Post subject: Reply with quote

Make sure you have configured the timezone:

Code:
# cp /usr/share/zoneinfo/Europe/Paris /etc/localtime
# cat /etc/timezone
Europe/Paris


Use the 'date' command to set your system clock to the local time now (I'll assume it is 31 July 2017 17:25 CEST in the example below):

Code:
# date 073117252017.00


Then tell your installation that your hardware clock is using UTC:

Code:
# hwclock --utc


Set the hardware clock's time (specify local time in the hwclock command, not UTC):

Code:
# rm /etc/adjtime
# hwclock --set --date="2017-07-31 17:25:00"


Make sure /etc/conf.d/hwclock contains only the following:

Code:
clock="UTC"
clock_args=""


Reboot into your installation.

EDIT: Moved timezone configuration to start, as per my blog post, as hwclock command needs to know the timezone.
_________________
Clevo W230SS: amd64, VIDEO_CARDS="intel modesetting nvidia".
Compal NBLB2: ~amd64, xf86-video-ati. Dual boot Win 7 Pro 64-bit.
OpenRC systemd-utils[udev] elogind KDE on both.

My blog


Last edited by Fitzcarraldo on Tue Aug 01, 2017 9:59 am; edited 1 time in total
Back to top
View user's profile Send private message
Lokesh
Apprentice
Apprentice


Joined: 01 Apr 2012
Posts: 161

PostPosted: Mon Jul 31, 2017 4:04 pm    Post subject: Reply with quote

Hello Fitzcarraldo

I did everything according to your guidance.

Fitzcarraldo wrote:
Reboot into your installation.
I shall do that tomorrow, my system is compiling a lot of packages at the moment. I report back whether it worked or not. Thanks so far for looking into this.

Lokesh
_________________
Sometimes frustrated Linux User
Back to top
View user's profile Send private message
sebB
l33t
l33t


Joined: 02 Mar 2011
Posts: 806
Location: S.O. France

PostPosted: Mon Jul 31, 2017 4:49 pm    Post subject: Reply with quote

I've the same timezone as yours.

The only thing I did was to manually change the date in the bios and set it to UTC (actually less 2 hours)
Then set the correct timezone
Back to top
View user's profile Send private message
Lokesh
Apprentice
Apprentice


Joined: 01 Apr 2012
Posts: 161

PostPosted: Tue Aug 01, 2017 1:58 pm    Post subject: Reply with quote

sebB and fitzcarraldo: thank you very much! Now I do understand the wiki:
Code:
Typically the system clock time is set up by the hardware clock on boot. Alternatively it is possible to manually set the system clock or use a network time server

I assumed that the hardware clock should always be correct. I was also not aware that this refers to the clock controlled by the BIOS. Ok, foolish me.
So either way or both will lead to success. Grand, I like to improve my knowledge.

Thread marked as solved.

EDIT: DO NOT USE BOTH SOLUTIONS TOGETHER. I did it and was not able to acces any https site. If SebB's advice is followed, the hwclock should NOT be set to "UTC" (because it is local). Or else leave the hwclock in the BIOS as is (at least in my case it was 2 hours ahead = UTC) and follow fitzcarraldo's approach. Nerve-wracking ...
_________________
Sometimes frustrated Linux User
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Installing Gentoo All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum