7

My hardware clock keeps going out of sync. I set it to system time a few times, but it keeps going back to a 5hrs ahead state.

Is this normal? Could it make trouble? How come my system clock is functioning properly when my hardware clock isn't?

8

The system clock gets set to either UTC or Local based on the last option used when the hwclock function was run. If you run:

hwclock -w --localtime

This should write your system clock to local time instead of UTC and should subsequently set it and read it at boot using local time. If you manually set your system clock and the hwclock was last specified with UTC then it will automatically set it back to UTC.

  • 2
    Not quite sure how I got upvoted then down voted... The other solutions specifically neglect to mention the most important point. You MUST specify --localtime or --UTC. If you don't it will REVERT to the last specified option. – Goblinlord Feb 18 '15 at 0:19
9

I do not know if it is normal, or not, because I do not know why the hardware clock should go crazy. If it's a hardware issue, you could use a software workaround until you fix it.

Thehwclock command should do what you need. You can use it in the terminal, as root, in order to set the system clock from the hardware clock, or to set the hardware clock from the system clock (depending on which one is more reliable):

hwclock --hctosys or hwclock --systohc

From the hwclock man page:

   -s, --hctosys
              Set the System Time from the Hardware Clock.

              [...] This  is  a  good  option  to  use  in one of the system startup
              scripts.

       -w, --systohc
              Set the Hardware Clock to the current System Time.
1

If it is always exactly 5 hours ahead it sounds like a timezone issue. In which case, it's likely that your hardware clock is set to local time, while the Linux system time is always set to UTC. If your timezone is 5 hours off of UTC, that would be the 5 hours.

In which case, in addition to the "--systohc" options for "hwclock" you should look into the "--localtime" and "--utc" options.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.