3

Here is my scenario: I run multiple VMs on my workstation to simulate the production environment. At the end of the day I sleep my workstation (with my VMs running in the background) at 6PM. When I return to the office the next morning at 8AM and wake the workstation, all of my VMs are at 6PM.

Tiring of resetting NTP or simply remembering to force an update, I put the following in a 5 minute cron

service ntp stop && ntpd -gq && service ntp start

Here is my /etc/ntp.conf

tinker panic 0

driftfile /var/lib/ntp/ntp.drift

logfile /var/log/ntpd.log

# Enable this if you want statistics to be logged.
#statsdir /var/log/ntpstats/

statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable
filegen clockstats file clockstats type day enable

# Specify one or more NTP servers.

# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for
# more information.
server 0.ubuntu.pool.ntp.org
server 1.ubuntu.pool.ntp.org
server 2.ubuntu.pool.ntp.org
server 3.ubuntu.pool.ntp.org

# Use Ubuntu's ntp server as a fallback.
server ntp.ubuntu.com

# Access control configuration; see /usr/share/doc/ntp-doc/html/accopt.html for
# details.  The web page <http://support.ntp.org/bin/view/Support/AccessRestrictions>
# might also be helpful.
# 
# Note that "restrict" applies to both servers and clients, so a configuration
# that might be intended to block requests from certain clients could also end
# up blocking replies from your own upstream servers.

# By default, exchange time with everybody, but don't allow configuration.
restrict -4 default kod notrap nomodify nopeer noquery
restrict -6 default kod notrap nomodify nopeer noquery

# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1

# Clients from this (example!) subnet have unlimited access, but only if
# cryptographically authenticated.
#restrict 192.168.123.0 mask 255.255.255.0 notrust


# If you want to provide time to your local subnet, change the next line.
# (Again, the address is an example only.)
#broadcast 192.168.123.255

# If you want to listen to time broadcasts on your local subnet, de-comment the
# next lines.  Please do this only if you trust everybody on the network!
#disable auth
#broadcastclient

Is there a better way to accomplish this?

ewwhite
  • 197,159
  • 92
  • 443
  • 809
chrisan
  • 957
  • 1
  • 8
  • 12

3 Answers3

3

If you are using VMware Workstation (or VMware vSphere), there are specific ways to handle timekeeping on your (Linux) virtual machines. However, that is not enough for your sleeping situation. NTP inside of the guest-only doesn't help here.

You absolutely need to install the VMware guest tools on the guest virtual machines and ensure that NTP running on the host. This will fix the sleeping problem and the drift that occurs when the guest is suspended.

Edit:

Oh, it's Ubuntu... I find that a lot of Ubuntu users don't install the native VMware tools suite. Here are the steps (and a video) to accomplish this.

ewwhite
  • 197,159
  • 92
  • 443
  • 809
  • I have VMware guest tools installed and they are running, didn't realize my host (Win7) needs to have ntp installed. I'll give that a try and report back, thanks – chrisan Oct 07 '13 at 19:15
  • Well no luck, I used their exact config mentioned. I did not have the `server ...` and `fudge ...` lines they said to comment out. I also didnt see where they said NTP has to run on the host (win7) and they list `vmware.pool.ntp.org` as remote NTP servers to use. Or were you saying to _not_ disable VMware's timesync and use their tool instead of NTP? Currently it is install and timesync is disabled per that doc – chrisan Oct 09 '13 at 12:11
  • Use timesync, then. I don't really understand what you're doing. Are you shutting your computer down? Putting it hibernate mode? Why not just suspend your VMs? – ewwhite Oct 09 '13 at 12:26
  • Picture a laptop, close it's lid it goes to sleep, open it's lid it wakes up. I'm not suspending all my VMs for the same reason I'm not closing all my programs. Basically I'm asking if theres a way to have NTP update in large steps automatically instead of my cron that does `service ntp stop && ntpd -gq && service ntp start` If no, then I'll keep what I have or try VMWare's timesync – chrisan Oct 09 '13 at 17:00
1

Your ntp.conf should work! I've found that sometimes ntpd will take quite a while to correct a substantial time difference. (I've seen it take upwards of 12 hours to actually make the correction).

You should find that if you leave it overnight (without your cron job) then it will eventually correct itself.

blacklight
  • 1,389
  • 1
  • 10
  • 19
  • Thanks, but that defeats the whole purpose of sleeping the computer. If I leave it on all the time ntp works well enough on it's own. Think of this like my laptop I close and only open again the next day when I want to work again :) – chrisan Oct 07 '13 at 12:28
  • Yes I know what you mean, I have the exact same problem with my Hyper-V server. I don't like running it overnight, so when I turn it on the next day, all my VM's are back by ~12 hours. Unfortuantely I don't think ntpd is really designed to fix frequent substantial time lapses. – blacklight Oct 07 '13 at 21:55
1

Using iburst would also help set the clock more quickly, but this is only effective on service start.

Most applications will probably want to specify the iburst option with the server command. With this option a volley of messages is exchanged to groom the data and set the clock in about ten seconds.

You would need to figure out a way to restart the service on APCI resume. (You could try this.)

Aaron Copley
  • 12,525
  • 5
  • 47
  • 68