LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices


Reply
  Search this Thread
Old 09-22-2014, 10:31 AM   #1
PeterSteele
Member
 
Registered: Jun 2012
Posts: 264

Rep: Reputation: Disabled
How do I synchronize VM guest time with host time


I'm running KVM under CentOS 6.4 and one issue I have is setting the clock on the VMs I create. I've tried various things but nothing gives me a reliable solution. For example, I've created some VMs this morning and although my host's clock is something like 8:00 am PDT, when my VMs start, their time is 15:00 PDT.

What's the best way to configure my VMs so that their time will be set the same as their host when they are first booted?
 
Old 09-22-2014, 01:06 PM   #2
PeterSteele
Member
 
Registered: Jun 2012
Posts: 264

Original Poster
Rep: Reputation: Disabled
It might be worth noting that I use the exact same CentOS image that is the basis of my VMs to also create OpenVZ containers. In this case, when a container is started, its time matches that of its host. I need this same result for my VMs.

Last edited by PeterSteele; 09-22-2014 at 01:08 PM.
 
Old 09-22-2014, 01:13 PM   #3
PeterSteele
Member
 
Registered: Jun 2012
Posts: 264

Original Poster
Rep: Reputation: Disabled
I've also confirmed that my VMs have kvm-clock enabled. I was under the impression that with this set, a VM will sync its time with its host on start-up, but that is definitely not the case.
 
Old 09-26-2014, 12:08 PM   #4
PeterSteele
Member
 
Registered: Jun 2012
Posts: 264

Original Poster
Rep: Reputation: Disabled
Okay, I've answered my own question. The combination of settings that I used to give me the results I need are:

1. Set the hwclock on the host and to use UTC time. This is done with the --utc option of the hwclock command. I run the following command on my host OS:

hwclock --utc --set --date="time-string"

2. Tell CentOS that the hwclock is using UTC via the file /etc/adjtime. For example, you could initialize this file using

echo -e "0.0 0 0.0\n0\n\nUTC" >/etc/adjtime

Create this file on both the host and your guest VMs. I create the file on my guests before I boot them for the first time by directly accessing the guest file system from the host.

3. Set the time zone you want for your system time. Again, do this on both your host and your guests:

ln -sf /usr/share/zoneinfo/time-zone /etc/localtime
echo "ZONE=time-zone" >/etc/sysconfig/clock
export TZ=time-zone

where time-zone is a standard CentOS time zone string, for example "US/Pacific".

4. Set the system time on your host based on the hwclock. The --utc option is needed to tell CentOS that the hwclock is in UTC time. It will take the UTC time and set your system time based on the TZ environment variable:

hwclock --utc --hctosys

5. The steps above are all done once, when you are configuring your host and guests. To keep time synced on all your servers after they are up and running you'll want to configure NTP on your host and guests.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to understand user time, sys time, wait time, idle time of CPU guixingyi Linux - Server 1 08-24-2010 10:10 AM
Synchronize time on several AIX servers ? Vilius AIX 1 12-15-2008 07:34 AM
How to synchronize time between two machine??? ajeetraina Linux - Desktop 1 11-27-2007 05:34 AM
Time Synchronize or NTP Management gurl4sh25 Linux - Software 5 06-04-2007 03:39 PM
Synchronize time kenneho Debian 11 01-21-2006 05:08 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat

All times are GMT -5. The time now is 02:51 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration