LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 05-26-2016, 07:59 AM   #1
LinuGeek
Member
 
Registered: Jun 2008
Posts: 126

Rep: Reputation: 0
RTC and system clock no in sync


Hello,

How to set the system clock sync with RTC (Hardware Clock / BIOS). I am writing a script that uses a system clock in order to start the system with alarm.
For this the sole requirement is to have a proper RTC clock. On my test system (SLES 10 SP4), I use NTP Server to manage the system clock. But the RTC clock is always ahead.
So for example : currently the system clock shows 14:00 26.05.2016 and the RTC shows 16:00 Hrs. I read the man pages of hwclock and it shows that following command
would sync the RTC clock to system clock. Which it did.

hwclock --systohc --localtime.

But after a reboot/shutdown, when the system comes up again , the RTC is again messed up. So there is something more which controls the RTC when the system is rebooted.
Could someone point me in the right direction. Thanx in advance.


- Admin
 
Old 05-26-2016, 08:16 AM   #2
dunne
Member
 
Registered: May 2014
Distribution: OpenBSD
Posts: 67

Rep: Reputation: 36
Set the hardware clock to the right time in GMT (Greenwich Mean Time) by going into the BIOS set-up during booting. Make sure that your Linux system knows that the hardware clock is set to GMT. Then get the exact time through NTP or whatever, and write the system time to the hwclock as you have been doing. Hardware clock and system clock should then be, and stay, in synch. UNLESS your BIOS battery is dead, but then your machine would tell you take during boot-up.

Last edited by dunne; 05-26-2016 at 08:20 AM.
 
Old 05-26-2016, 08:39 AM   #3
LinuGeek
Member
 
Registered: Jun 2008
Posts: 126

Original Poster
Rep: Reputation: 0
Thanx for reply. What you say , might work. But if possible I am looking for a way to do what you have written. In BIOS I tried to correct the time but it then again falls back to incorrect time. Is there a option in BIOS to set the GMT? I will have to take a look again.

Secondly how to tell the system that RTC is now set to GMT?
 
Old 05-26-2016, 09:58 AM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,735

Rep: Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920
So your still having the same problem from http://www.linuxquestions.org/questi...k-4175556767/?

The last line of the /etc/adjtime file will be either LOCAL or UTC. UTC is the same as GMT.

The hardware clock (RTC) does not have a time zone setting. Just set it for the correct time.

If you are using a BIOS built in alarm clock then it probably should be set to local time.
 
Old 05-27-2016, 03:50 AM   #5
LinuGeek
Member
 
Registered: Jun 2008
Posts: 126

Original Poster
Rep: Reputation: 0
Thanx again.

I set the correct time in BIOS and then booted the system. The system shows +2 Hrs time. So I guess it has something to do with timezone. How can I avoid this to have both correct time?
I tried to set the correct time at system level using date command but after reboot it again goes to the original time of +2 Hrs of BIOS clock.

The last line of /etc/adjstime is LOCAL.
I again put --local in the file /etc/sysconfig/clock which says,

# Set to "-u" if your system clock is set to UTC, and to "--localtime"
# if your clock runs that way.
#
HWCLOCK="-u" <---- This was the original value.

Atleast post reboot the RTC time is not getting changed now, even if I reboot or shutdown the system.
 
Old 05-27-2016, 04:03 AM   #6
LinuGeek
Member
 
Registered: Jun 2008
Posts: 126

Original Poster
Rep: Reputation: 0
Update :

Since my Installation Timezone is CEST . It makes sense that system clock always goes +2Hrs ahead than RTC (which i manually set to current time).

So e.g. here the current time is = 11:00 which I set in BIOS as well. And then booted the system and it shows now : 13:00

But then how do I set both these clocks show same time? I dont think I should change the timezone completely as it is correctly set to Europe.
 
Old 05-27-2016, 07:20 AM   #7
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,668
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
Ordinarily, the ntp service runs in the background, keeping the hardware clock synchronized with an atomic-time source.

The hardware clock normally tracks UTC = universal time.

When you "ask for the time," however, the value will be converted to the correct time for your selected time-zone before being displayed to you. This is done through the magic of .tz files.

Individual users can, in fact, set their own time-zone preference. Applications can ask for the time in any time-zone they please.

When you "set the clock in BIOS," the BIOS settings probably also used or assumed a time-zone. The currently-selected "tz-file" for your session specifies a time-zone that is two hours different. (The giveaway is that the difference is exactly (two) hours.)

As I said earlier, "use ntp to set the clock and to maintain it." Then, set the proper time-zone for your locale, to properly interpret the value of the system clock.

A timing application ordinarily works with absolute (UTC ...) system-clock time values internally.

"Time zones" can be a very important consideration for web-applications that are designed to be used by "anyone, anywhere." When they specify a time, they probably mean it "in terms of 'where they are.'" But, not necessarily!
 
Old 05-27-2016, 08:04 AM   #8
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,735

Rep: Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920
Actually ntp's main purpose is to keep the system clock synchronized. There is a mode where the kernel updates the RTC clock every 11 minutes if the system clock is accurate i.e ntp is running. Not sure if recent kernels still do this.

The system clock uses UTC but the BIOS clock can be anything well either local or UTC. As far as I know since I do not have any real new computers is the BIOS clock does not have any sort of time zone setting. Anyway ntp also is based upon UTC and it is the computer via the timezone setting that displays time as desired.

Have not played with SuSE is along time so there could be another setting somewhere that I don know. As stated since the difference is exactly 2 hours then it is still a local versus UTC configuration problem. A workaround might be to compensate in your script for the offset. You would need to check for CET versus CEST if necessary.
 
Old 05-27-2016, 05:59 PM   #9
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,668
Blog Entries: 4

Rep: Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945Reputation: 3945
In the "present" day, where computers are often widely (world-ly?) networked, I suggest using UTC.
 
Old 06-05-2016, 04:23 AM   #10
Arcosanti
Member
 
Registered: Apr 2004
Location: Mesa, AZ USA
Distribution: Slackware 14.1 kernel 4.1.13 gcc 4.8.2
Posts: 246

Rep: Reputation: 22
The distro you are using might have the buggy util-linux package installed. Try installing version 2.26 or later and see if the problem persists. I did that with Slackware 14.1 and the problem went away. I believe version 2.25 has a known issue with the clock not syncing correctly and the clock always ends up ahead.

Last edited by Arcosanti; 06-05-2016 at 04:46 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Wake Up Linux With an RTC Alarm Clock LXer Syndicated Linux News 1 12-01-2012 10:50 PM
Query on Real-Time-Clock (RTC) ajaygarg Linux - Hardware 5 03-08-2012 01:03 PM
Difficulty getting NTP to sync the system clock on SuSE Linux 8. sombre1 Linux - Software 2 10-10-2009 07:21 AM
Real Time Clock(RTC) problem gongcon Linux - Software 6 01-06-2005 09:36 PM
RTC time on a locally set clock pe2338 Debian 8 09-06-2003 04:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 09:51 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration