NTP System time different from hardware time

0

on a centos 6.5 server I've just executed ntp with:

service ntpd start

It has fixed system time, but hardware time is still wrong. Is this normal? How can i fix it?

ntpstat reports:

unsynchronized
polling server every 64s

testermaster

Posted 2015-06-03T03:40:37.270

Reputation: 313

Answers

0

It is possible that the NTP is actually correcting the time, but slowly. It normally does that to avoid programs getting worked up about having passed N seconds in a fraction of a second. Many program use the time to order their work internally.

So the clock is change to increment or decrement seconds just slightly, say 0.1 second each second (or even less). It can take a time to get both clocks synced.

Check the time difference and see if it decreases over time.

If the difference persists after an 'orderly' power-off (i.e. a shutdown, not a hardware power-off), the you should check if the system is programmed correctly. In my system, this is done in a command file run at shutdown:

/etc/rc.d/rc.0 contains:

# Save the system time to the hardware clock using hwclock --systohc.
if [ -x /sbin/hwclock ]; then
  # Check for a broken motherboard RTC clock (where ioports for rtc are
  # unknown) to prevent hwclock causing a hang:
  if ! grep -q -w rtc /proc/ioports ; then
    CLOCK_OPT="--directisa"
  fi
  if grep -q "^UTC" /etc/hardwareclock 2> /dev/null ; then
    echo "Saving system time to the hardware clock (UTC)."
    /sbin/hwclock $CLOCK_OPT --utc --systohc
  else
    echo "Saving system time to the hardware clock (localtime)."
    /sbin/hwclock  $CLOCK_OPT --localtime --systohc
  fi
fi

You can try the command manually: sudo hwclock --systohc. If that doesn't work, you might have a hardware problem.

The importance of having both clocks synced? Depends on which software you are running. The hardware clock is used to set sysclock on startup. Until NTP kicks in, your machine uses that time. Any file used during that lapse is marked with the incorrect time. This could be important for some...

jcoppens

Posted 2015-06-03T03:40:37.270

Reputation: 629

It isn't dual boot, I've only centos. My hardware time is Pacific Time+30mins at the moment. Difference isn't decreasing. https://abdussamad.com/archives/343-CentOS-Linux:-Setting-timezone-and-synchronizing-time-with-NTP-.html it says: keep in mind that ntp only affects the system time. The hardware clock on your server will not reflect that. So you want to set it as well so that the correct time is maintained after reboot: hwclock --systohc. I haven't configured the server myself.

– testermaster – 2015-06-03T05:07:19.447

That remark about the system/hardware clock seems correct. But if NTP is working (and if it gets past your firewall, and if it connects to a working server, etc, then it should update the system clock. It should run as root, but I suspect the service command takes care of that. NTP can add entries to logs, though possibly you have to enable that. But it would be enlightening to see what the logs say. – jcoppens – 2015-06-03T05:25:38.597

I think you can start the daemon manually with -n -d options to see if it works correctly. Try stopping the service, then starting the daemon with sudo ntpd -n -d, so it will show debug information on the screen (and not run in the background). You can then stop it with Ctl-C. – jcoppens – 2015-06-03T05:31:32.650

System clock is correct (it was wrong and fixed few mins after i executed ntp). I'm asking if it's normal that hardware time is still wrong and if it's important to fix it (and how). – testermaster – 2015-06-03T05:44:09.550

As was already commented, if you switch off your computer, the operating system should be programmed to do this automatically. I've added some more info to the reply. – jcoppens – 2015-06-03T12:58:41.440

I was back to check the situation and.... ntp stopped working, now it seems that system time is catching up hardware time :/ – testermaster – 2015-06-03T22:15:26.573

Ntpstat reports that it seems that ntp daemon isn't running – testermaster – 2015-06-03T23:01:01.020

0

First of all: Hardware time on a Linux system is stored in UTC, so an offset relating to your timezone is to be expected. And yes, this does make problems when dual-booting.

In Addition to that, a Linux system will not always and immediately propagate the NTP time to the RTC ("Hardware clock"), but it should do so at least on shutdown.

Eugen Rieck

Posted 2015-06-03T03:40:37.270

Reputation: 15 128

In my Slackware system you can choose if the hardware clock is UTC or local time at installation time (changeable later). So that is not a fixed rule. You can choose to set it to UTC, but on a dualboot, that does give problems. – jcoppens – 2015-06-03T05:20:29.470

@eugen rieck: I made a mistake and commented the other answer. – testermaster – 2015-06-03T05:39:39.827

@jcoppens - Ofcourse I ment "by default" – Eugen Rieck – 2015-06-03T11:01:40.967