21

My Virtual Machine's clock drifts pretty significantly. There's documentation out there about dealing with this, but nothing seems to be working very well.

Anyone have any suggestions, things that worked well for them, ...

Supposedly updating regularly via ntp is not a good solution.

3
  • 1
    Interested to know why ntp isn't supposed to be a good idea?
    – cagcowboy
    Sep 22, 2008 at 20:36
  • What operating system is your Virtual Machine running?
    – Mark Biek
    Sep 22, 2008 at 20:38
  • about ntp solution: i have to admit that i cannot remember at the moment the reason why ntp was discouraged. i think perhaps it had to do with the idea of using different methods simultaneously and how this would be bad.
    – carrier
    Sep 22, 2008 at 22:23

11 Answers 11

17
  1. Read you vmware documentation carefully before you listen to anyone. We are running ESX5.

Timekeeping best practices for Linux guests among other things says: Ref: http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1006427

NTP Recommendations Note: VMware recommends you to use NTP instead of VMware Tools periodic time synchronization. NTP is an industry standard and ensures accurate time keeping in your guest. You may have to open the firewall (UDP 123) to allow NTP traffic.

This is a sample /etc/ntp.conf:

tinker panic 0
restrict 127.0.0.1
restrict default kod nomodify notrap
server 0.vmware.pool.ntp.org
server 1.vmware.pool.ntp.org
server 2.vmware.pool.ntp.org
driftfile /var/lib/ntp/drift

This is a sample (RedHat specific) /etc/ntp/step-tickers:

0.vmware.pool.ntp.org
1.vmware.pool.ntp.org

The configuration directive tinker panic 0 instructs NTP not to give up if it sees a large jump in time. This is important for coping with large time drifts and also resuming virtual machines from their suspended state.

Note: The directive tinker panic 0 must be at the top of the ntp.conf file.

It is also important not to use the local clock as a time source, often referred to as the Undisciplined Local Clock. NTP has a tendency to fall back to this in preference to the remote servers when there is a large amount of time drift.

An example of such a configuration is:

server 127.127.1.0
fudge 127.127.1.0 stratum 10

Comment out both lines.

After making changes to NTP configuration, the NTP daemon must be restarted. Refer to your operating system vendor’s documentation.

11

vmware have a really good PDF doc on this problem.

Basically, the host will slew the ticks delivered to your guests as it can. Don't run NTP or timed or junk like that. Just install vmware-guestd and let the host slew your ticks. If you still lose ticks, then any other solution will have major drift too.

If you can, use a guest OS that has a low frequency tick rate. Newer versions of Linux come with 1000Hz ticks, but it used only to be 100Hz. That seems easier for the host to deliver. A kernel rebuild is usually needed to change the HZ value.

2
8

Just to add some data about why NTPD is not a good solution. NTPD is a daemon that tries to compensate for the local clock drift; if the "internal clock" drifts away by X number of seconds in a day, then instead of jumping ahead/back like a forced command as in "ntpdate " NTPD tries to add/remove some cycles to the clock so that in time, normally within 15 minutes, the clock runs accurately enough and the compensation overcomes this X numbers of seconds that the servers gains/losses in a day. This has the advantage that you won't see any time in the day repeated, which is a MUST for for transactional systems.

But to be able to do this, NTPD requires that the local clock does a reasonably good job, which normally means that the local clock won't drift apart more than 42 seconds a day (more or less; I am not sure of the exact number). This normally is a problem in Virtual Machines, since the the clock is software controlled, so if the HOST has too much overload, you could see that the CLIENT's clock will run more slowly, and if it doesn't then the clock could run too fast. The problem here for NTPD is that the local clock is not reliable and doesn't have a constant drift in time; it may be more or less depending on the overload of the HOST system.

So in this case it's better to install the client tools as has been suggested, and synchronize the CLIENT clock with the HOST's clock (normally referred as the "wall clock")

1
1

There is no definitive answer because several methods exist, each having its pros and cons. What one to chose depends on your tasks, server load, operating system, etc.

Read vmware_timekeeping.pdf for thorough understanding of the issue.

Quick recipes for Linux could be found in a separate KB article

1

The best solution to this problem is (if locally connected) Install Local NTP server and put "service ntp restart" in an infinite loop with sleep time 30 seconds approx. by writing a code in "/etc/init.d/rc.local" file. Reboot system and time will be synchronized with the server computer.

0

Doesn't installing the virtual machine additions (tools) synchronize the clock between the guest and host OS?

0

Supposedly updating regularly via ntp is not a good solution

That's the solution I would recommend, though. Why is it not considered good at your location?

0

Install NTP if you don't already have it.

ntpdate will set the clock correctly, then ntpd can keep the clock accurate.

The NTP pool project provides a large pool of NTP servers to pick from.

Edit just noticed you said you think NTP is not a good solution - why? If you're worried about the effect of the clock changing, NTP is the ideal, as ntpd does not jump the clock forwards or backwards, instead it "slews" the clock by speeding it up/down slightly until it's back in line with the correct time.

1
  • if i run ntpdate -u it'll update the clock... however, after 1 minute i'll already be off by 5 seconds, so i would have to run the update pretty often. i was unaware, however, of the slewing feature. all i've used is ntpdate -u which jumps.
    – carrier
    Sep 22, 2008 at 22:24
0

I had the same problem and solved it by

  1. installing vmware-guestd
  2. sending the kernel an option clocksource=acpi_pm
  3. running hwclock -s hourly as root.
0

This is an old issue but one that was affecting us recently. What I found was that any of our vm's that were running vmware tools were affected by the issue.

More recently we had started using open-vm-tools and on those vm's the option was not set. Since open-vm-tools is fully supported and recommended by Vmware I would suggest using it over vmware tools: http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=2073803

If open-vm-tools is in a repository that you use it is also simple to install via yum install or apt-get install etc.

-2

You can use the cmd and

net time \\computer_name /set

to set the clock remotly (or in a script for example)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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