Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm running Linux (Centos) under Virtual PC in Windows 7.

Guest is set to a different time zone then host OS and none of them are UTC.

The issue is that when guest boots its time is always set to the host OS time but time zone is still whatever guest uses eg
host is 14/5/2011 09:00 NZST,
guest after booting becomes 14/5/2011 09:00 CDT (same relative time as host but different TZ)
where it should really be 13/5/2011 16:00 CDT (same absolute time).

Basically on each boot time jumps forward and correcting it later causes all sort of issues like crashed imap server and so on.

As far as i understand it happens because /etc/sysconfig/clock allows only two options for a clock setting: use hardware clock (host OS clock) as is (ie local time) or as UTC time, so i cant see a way to fix on the guest side.

Is there any way so specify time zone for a guest on virtual machine level? Maybe Virtualbox or VMWare does allow something like it?

share|improve this question
    
Please make your title clearer, as I think it asks the opposite of what you meant judging by the question body itself. Also, I may be wrong but your examples don't seem to make sense. –  Eduardo Ivanec May 15 '11 at 21:17
    
Thanks for the comment, tried to make it better –  alexeit May 15 '11 at 21:33
    
OK, it's much clearer now. I deleted my answer as it's no longer relevant. As far as I can see the only viable workaround would be to set the host to UTC, as I'm guessing changing the timezone of the guest would prove more problematic. –  Eduardo Ivanec May 15 '11 at 21:34
    
Host is my laptop so it is problematic as well :). Guest has different TZ to keep it consistent with live server because of huge amount of legacy code, settings and data. But i'm afraid you are right - i need to suck it up and change one of them to UTC –  alexeit May 15 '11 at 21:41
add comment

2 Answers 2

Not convinced the other softwares would change anything as it sounds like the regional settings of your (host) computer are being inherited.

A common solution would be NTP (Network time protocol)

Try installing NTP on CentOS and configuring it to pull the correct time and date from a time server/ntpd.

Tutorial here: http://www.cyberciti.biz/faq/howto-install-ntp-to-synchronize-server-clock/


Comment included: "@alexeit I only describe this as a solution as I hit the same problem with a virtual host company once based in the US hosted my system. I needed a GMT/UTC0 timezone and as such had to configure NTP to solve my issue as I could not control the timezone/time of the VM host.

Additional to my last comment: Sorry this was a while back - I do actually recall having to create a start up script to 'soft' set the timezone correctly then sync with NTP."

share|improve this answer
    
Perhaps I misunderstood the question, but @alexeit seems to be having problems with timezones and not with the clock itself - as far as I know NTP wouldn't be of help in this case, as it only gets you a reliable clock and doesn't have anything to do with timezones. –  Eduardo Ivanec May 15 '11 at 21:23
    
ntpd will not fix time after reboot. It also wont update time when it is too much far off the time it supposed to be (which is the case here) –  alexeit May 15 '11 at 21:27
    
@alexeit I only describe this as a solution as I hit the same problem with a virtual host company once based in the US hosted my system. I needed a GMT/UTC0 timezone and as such had to configure NTP to solve my issue as I could not control the timezone/time of the VM host. –  Lexo May 15 '11 at 21:31
    
Additional to my last comment: Sorry this was a while back - I do actually recall having to create a start up script to 'soft' set the timezone correctly then sync with NTP. –  Lexo May 15 '11 at 21:38
    
Thanks for the hint, i'll research it. Can you perhaps include this comment in your answer. –  alexeit May 15 '11 at 21:44
add comment

Fresh answer. I have just tested this on Ubuntu not CentOS but the same principal applies.

As you mentioned there are two clocks - The hardware clock and the UTC (I generally think of this as OS level) clock.

The virtual machine host controls the hardware clock and in live environments it may not always be possible to change this (for example a VPS). So instead, I recommend using NTP to keep the time synchronized based on the timezone of your VM.

Step 1. [May not always be required] Set the timezone on your OS using /etc/localtime (It's possible to use CentOS' redhat-config-date or just setup). Further details please see: http://www.cyberciti.biz/faq/howto-linux-unix-change-setup-timezone-tz-variable/

Step 2. To test this then synchronizes, use ntpdate utility along with your chosen time server. You should find when you type date the expected output with correct time and zone is received.

ntpdate [server]

Step 3. Either set a daily crontab to run the same ntpdate command or install and configure ntp daemon to keep the time in sync on a more regular basis.


In testing, my host was BST (British Standard Time) and was showing as Mon May 16 00:00:00 BST 2011 on the hardware clock which initially inherited to the virtual system.

I then changed /etc/localtime to a symbolic link of Japan JST and rebooted. Time now shows as Mon May 16 08:01:00 JST 2011.

I purposely put the time out of sync by several hours (date -s "15 May 2011 16:00:00") Time now shows as Sun May 15 16:00:00 JST 2011.

I then ran ntpdate ntp.ubuntu.com Time now shows as Mon May 16 08:04:00 JST 2011

share|improve this answer
    
Just to clarify, so host time is 00:00, you boot guest and it's time is 08:00 - did you run ntpdate during/straight-after boot or not? –  alexeit May 15 '11 at 23:55
    
I ran ntpdate manually straight after boot, I believe it was ran during boot though. At the time of testing, my host (laptop) was set to BST 00:00 and my VM was JST 00:00. NTPDate, when ran corrected the time to 08:00 which would've been correct as JST is +8 hours in comparison to my local time. –  Lexo May 16 '11 at 0:28
    
NTPDate was ran automatically when I rebooted - CentOS can be configured to do so, not sure if it does by default. –  Lexo May 16 '11 at 0:35
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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