Recent Posts

Tags

News

  • Now relocated, living and working at Tokyo, Japan.

    Rex Tang, MVP ASP.NET 2006

    This blog is depreciated and not update anymore. Please refer to Rexiology@MSDN Blogs for continuous updates.

    This is a mirror of his technology blog Rexiology::Work

Community

Email Notifications

Microsoft Sites

Other Sites

Blog pools

Bloggers

My other places

Archives

Rexiology...

asp.net, .net framework, etc...

Clock in a Linux Guest Runs More Slowly or Quickly Than Real Time...

crosspost from http://rextang.net/blogs/work/

The title came from VMWare KB and just said exactly the problems I've faced those 2 days!

As I've  written in the Windows X Server Client post, I used VMWare 5.5 to setup a Fedora Core 6 Linux VM to be the linux test server. the linux kernel version is 2.6.18 and after I finished that post soon I found that my server's system time is little bit strange. it's not sync with the host time.

Since correct time is very important for a server, I think it should be more important in a linux server since there were lots of logs and crontabs that's based by time. The very first thoughts to fix this problem is to use NTP protocol to sync with world time servers. in linux kernel 2.6 there is ntpd for ntp server, in 2.4 it should be xntpd. so I quickly modified "/etc/ntp.conf" file and started the ntpd.

the time is still not sync with real time after I started ntpd. also I found that the ntpd installed is not able to sync to outside server, it will only sync to LOCAL server, even if I turned on udp port 123 in iptables (both in and out), just like what it was written in this maillist I found. also, the system time is slow, it takes more than one second to pass a second (inside this linux guest system). there seems also having problems related to VM hardware's clock settings.

This tooks me one day and didn't find any solution on the internet. finally I decided that maybe it's only happened on linux kernel 2.6.18 and decide to build up another distribution with different kernel version to test again.

I choosed CentOS 4.4 with linux kernel 2.6.9 to build up another linux vm. and after the installation, the system time is still slow like the one inside Fedora vm. this concluded that it will almost happened with 2.6 kernel in VMWare and won't happened in 2.4 kernel (since my colleague had a RedHat 7.2 with kernel 2.4.18 running without the time slow problem). some posts I read indicated that this should have something related to system clock. so I started dig into that direction.

A search to Google finally found the answer. From VMWare KB. It's exactly the answer of this problem if you are running kernel 2.6 inside VMWare. the reason that caused the slowing time inside guest system is because of that the guest clock frequency is setting too high than the host OS can offer. in 2.4 kernel the clock rate is set to 100HZ and after 2.6 kernel the clock is set to 1000HZ on compiling time, thus cause the timer in guest OS slower than host OS. refer to this KB for more detail explaination.

Just follow what the KB said to tune bootup kernel options for both slow time and quick time problem, like the following (GRUB case):

image=/boot/vmlinuz label="linux"
root=/dev/hda1 initrd=/boot/initrd.img
append="resume=/dev/hda6 splash=silent clock=pit nosmp noapic nolapic"
read-only

"clock=pit" is to fix quick clock problem, "nosmp noapic nolapic" is to fix slow clock problem.

after a reboot of guest linux (both my Fedora one and CentOS one) , the clock is back to normal and strangely that the ntpd also back to normal work and can query outside time server without problems. cool!

As also provided in another VMWare KB talking about Timekeeping in VMWare Virtual Machine, it is also able to use VMWare Tools to sync guest OS time with host one. by installing VMWare Tools in Linux server, there will be a vmware-guestd running and by setting parameter "tools.syncTime = TRUE" inside VMWare .vmx setting file, time will be sync.ed with host OS using VMWare Tools and will be not necessary to run ntpd or ntpdate in crontab to sync your time inside guest system, it will auto sync with host OS and it will now be only the host OS that needs to sync with world time server thus save the bandwith also the loading of outside time servers.

finally solved the time problem, and got to learn one more linux distribution install, also get deeper understanding of ntpd during this problem solving, nice (tough) learning.

actually Fedora Core distribution is pretty different from CentOS installation, CentOS is pretty much like RedHat distribution and many daemon names are different from Fedora and CentOS (RedHat). another tough learning to remember those difference! (should be more differences if touching FreeBSD systems!)

anyway, now I can also setup my xdmcp and vnc server env on my CentOS guest system and now have 2 guest linux systems to start my learning of those network services installation. keep walking...

Technorati Tags: linux , redhatfedoraCentOSntpclockkernelvmware

 

Comments

Elias said:

Interesting...

# April 7, 2007 10:40 AM

Loukianos said:

interesting

# April 21, 2007 10:27 AM

Dion said:

Cool}Cool!

# April 21, 2007 9:26 PM

Michalis said:

interesting

# April 23, 2007 4:02 AM

Miltos said:

Cool}Cool!

# April 24, 2007 7:38 AM

abc said:

It does work, thanks!

# June 12, 2007 3:41 PM

  Virtualized LoadRunner? (Part 3 of 3) by LoadRunner TnT said:

Pingback from    Virtualized LoadRunner? (Part 3 of 3) by LoadRunner TnT

# December 25, 2007 11:41 PM

john said:

This solution doesn't work for me. I run 3 VMs on top of Fedora 8 (x86_64) and all 3 clocks run slow. The guests I run are Fedora 7 (i386), Opensuse 10.3 (i386) and Ubuntu 7.10 (x85_64). Anyone have other ideas to try?

# January 5, 2008 9:21 PM

tom said:

try clocksource=acpi_pm on newer distros

# January 11, 2008 4:01 PM

tom said:

ok, on Centos 5.0 i ended up turning on with kernel params:

clocksource=acpi_pm nosmp noapic nolapic

and in my vmx file:

"tools.syncTime = TRUE"

it seems to not lose time now.

# January 11, 2008 4:28 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 

If you can't read this number refresh your screen
Enter the numbers above: