Ubuntu Time Drift
Written by:
Ilya Vasilenko
on
10 January 2023 12:30 PM
|
|
Tested config for Ubuntu 12/14/16 running under Hyper-V with no time drift
1. Kernel boot optionsEnsure that cmdline has no other time/clock related parameters, but only "clock=pit". To check/modify: - open the file - find the line with text - ensure all is correct there, - save file if changed - run "
2. Install NTPd service- run "apt-get install ntp" - stop the service by command "service ntp stop" - backup the file
- start the service "service ntp start" Set ntp to start automatically after boot update-rc.d ntp enable If it is the fresh Ubuntu install, jump to step 6. If your Ubuntu setup has the time drift fix applied earlier from our different article, do additional steps as below. 3. Remove clock adjusting script- open the file - remove the string sh - save the file 4. Remove other adjustments- uninstall - if the file - save the file 5. Remove old NTP drift file- if existing, remove 6. Restart the VM7. If still not syncing correctlySet the ntp.conf file # nano /etc/ntp.conf It should read like this (if it does not please change it to the below accordingly): tinker panic 0 CTRL-O to save Sync the time # ntpd -gq Reinstall adjtimex # apt-get install adjtimex This stops NTP, forces it to sync the clock (to “prime the pump”), sleeps for 100 seconds, forces a second clock sync, and restarts NTP. It produces output like this: # /etc/init.d/ntp stop ; ntpd -q ; sleep 100s ; ntpd -q; /etc/init.d/ntp start Stopping NTP server: ntpd. If the second time set is +2.60 then run this command (these don't have to be exact): # adjtimex -t 10260 If the second time set is -2.60 then run this command (these don't have to be exact): # adjtimex -t 9740 # /etc/init.d/ntp stop ; ntpd -q ; sleep 100s ; ntpd -q; /etc/init.d/ntp start Stopping NTP server: ntpd. Most likely this will now report for example 2.6 in the other direction. This is normal. Now return the adjtimex to the default value: # adjtimex -t 10000 Then reprime again: # /etc/init.d/ntp stop ; ntpd -q ; sleep 100s ; ntpd -q; /etc/init.d/ntp start You should now see an output like this: * Stopping NTP server ntpd [ OK ] Note that it now reports time slew (as it's only a very minor amount out). This is great. You can now type: # watch ntpq -p This should report the current status of the NTP servers and you should see the jitter falling down to below 3 on the 172.31.66.5 server. Your time is now sync'd correctly.
| |
|