Ho to run NTP on bad hardware.

In the case when hardware has a bad bios clock and it boots up, usually it will not correct the time immediately. Running ntpd with option "-g" will override 1000s restriction, but anyway it takes time from 3 to 4 minutes before it synchronizes time with server.

If it's needed, that first synchronization will happen ASAP and only after that ntpd will be started there's one simple script:

#/bin/bash

# Due to problem of inaccurate HW-clocks and the ntpd problem in
# the case when offset is too big, this script should help.
# It should be run immediately after boot up as a last/final
# job.
#
# The requirements are:
# 1) ntpdate should be installed and PATH of ntpdate binary defined below.
# 2) ntpd should be installed and NTPD_COMMAND should be defined below.
# 3) timeserver(s) should be defined in ntp.conf.
 

NTPD_COMMAND="/etc/init.d/ntpd start"
NTP_CONF="/etc/ntp.conf"
NTP_DATE="/usr/sbin/ntpdate"
NTP_DATE_LOG="/var/log/ntpdate.log"

STATUS="0"

function checkTime(){
  for i in `cat $NTP_CONF |grep "^server" |awk '{print $2}'`
    do
    if  ping -c1 $i &> /dev/null
    then
      STATUS="1"
      $NTP_DATE -vvv $i &>> $NTP_DATE_LOG
      sleep 5;
      $NTPD_COMMAND
      break
    fi
    done
if [ $STATUS -eq 1 ]
 then
 return 0
 else
 return 1
 fi
}

until checkTime
do
sleep 1
done
 

 

Verify that no ntpd and ntp-client is not added to runlevel or bootup script. This script will do both: 1) sets the right time fter bootup and 2) starts the ntpd daemon.

NOTE:

If you still have a problem that machine is drifting too much in long term, use adjtimexconfig (http://www.ibiblio.org/linsearch/lsms/adjtimex.html).

At first run adjtimexconfig and then add it to auto startup.