1. Home
  2. Linux
  3. [Solved]: How to Prevent Virtual Machine’s clock Synchronizing with Host machine and Set Independent clock time?

[Solved]: How to Prevent Virtual Machine’s clock Synchronizing with Host machine and Set Independent clock time?

Question: In my CentOS 5 VM (running on Xen server), the date command displays wrong output (as 16 Jun 2015 07:05:11 instead of 16 Feb 2016 13:07:00). I tried to  sync date via ntpdate command without success and setting the date manually via the date command didn’t work as well. Below is the message obtained from /var/log/message.

Log message shows:

Jun 16 07:05:11 pub81 ntpd[14744]: time correction of 21111567 seconds exceeds sanity limit (1000); set clock manually to the correct UTC time.

Please help.

Date change on CentOS 5 VM

Answer: By default, the VM’s clock is synchronized to the host machine’s clock. It means, you cannot change the VM’s clock independently. However, the below trick will allow you to override this setting:

Add the following line to your file: /etc/sysctl.conf

# Allow the VM to update it's own clock, and do not use the DOM host clock.
xen.independent_wallclock=1

On Redhat/CentOS/Fedora

Run the below command to read the new setting.

sysctl -p /etc/sysctl.conf

(or)

Alternatively, you may restart the network service.

/etc/init.d/network restart

On Debian/Ubuntu

sysctl -p /etc/sysctl.conf

(or)

Alternatively, you may restart the network service.

/etc/init.d/networking restart

Now try to set the date as shown below:

[root@pub81 ~]# date --set="16 Feb 2016 13:07:00"

Voila! the date is changed! Now you can use ntpdate to sync date with any NTP server.

Updated on September 2, 2017

Was this article helpful?

Related Articles

Leave a Comment