Linux - GeneralThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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?
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.
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!
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.