In many cases it can be quite difficult to accuracy keep time on a virtualized operating system due to the complex interactions between the hardware, host operating system, virtualization layer and the guest operating system. In my case I found that running Red Hat Linux 5 (CentOS 5) on VMWare Server 1.0.8 resulted in an unstoppable and rapid slowing of the guest clock.
The obvious steps to take include running NTP to control the local clock. This, however, only works when the clock skews very slowly. In my case, as in many, the clock drifts too rapidly for NTP to handle. So we need another solution. VMWare recommends installing VMWare Tools on the guest operating system and subsequently adding the following to your VMX configuration file:
tools.syncTime = true
This does not always work either. You should also try changing you guest system clock type. Most suggestions include adding clock=pit to the kernel options. None of this worked for me. I had to resort to a heavyhanded NTP trick – putting manual ntpdate updates into cron. In my case, I set it to update every two minutes. The clock still drifts heavily within the two minute interval but for me it is an acceptable amount. You should adjust the update interval for your own needs. Every five minutes may easily be enough but more frequently might be necessary.
Using crontab -e under the root user, add the following to your crontab:
*/2 * * * * /usr/sbin/ntpdate 0.centos.pool.ntp.org
For those unfamiliar with the use of */2 in the first column of this cron entry, that designates to run every two minutes. For every five minutes you would use */5. Remember that it takes a few minutes before cron changes take effect. So don’t look for the time to begin syncing for a few minutes.
For me, this worked perfectly. Ntpdate is not subject to the skew and offset issues that ntpd is. So we don’t have to worry about the skew becoming too great and the sync process stopping.
If anyone has additional information on syncing Linux in this situation, please comment. Keep in mind that this is for Red Hat Linux and the kernel with RHEL5 is 2.6.18 which does not include the latest kernel time updates that may be found in some distributions like Ubuntu. Recent releases of Ubuntu likely do not suffer this issue as I expect OpenSuse 11.1 or the latest Fedora would not either.