2

I have several Ubuntu virtual machine running within a Hyper-V server. The server is a Windows 2012r2 machine. The Ubuntu VMs are either Ubuntu 14.04 or Ubuntu 16.04 (the current LTS releases).

It seems that when the virtual machines first power on they often have a timestamp of several days in the future. This can be seen in the syslog. The system time is corrected once the network connection comes up and NTP starts.

Why are virtual-machines running under Hyper-V starting with a date several days in the future?

The Hyper-V host server is connected to a UPS so has a very long uptime. It has the correct date and time at present. It is set to use a 0.uk.pool.ntp.org server as a time source. The ADDC and DC on my network also act as time servers to most of the client machines. Both of these have the correct time & date at present. Both of these are also setup to use several .pool.ntp.org servers as a reference. w32tm /query /peers confirms the settings on all three machines.

This time error on start up causes problems with my DNS entries for the VMs as well. When the Ubuntu system comes up it acquires an IPv4 address with a DHCP reservation. My network currently hands out 8 day reservations. Sometimes the power on date error is so great that the reservations look as if the were requested in the future, after the current date. When I look at the /var/lib/dhcp/dhclient.eth0.leases file modification date it is several days in the future. This then seems to make the Ubuntu DHCP client think it has a reservation which runs until a date several days in the future. The client then does not to reserve (or renew) a new IP Address over DHCP and its DNS entries expire on the server side.

TafT
  • 233
  • 2
  • 12
  • 2
    Is the time on the host correct? – mzhaase Oct 17 '16 at 10:39
  • Sorry about that @mzhaase what a detail for me to have forgotten. Yes, my Hyper-V host server has the correct time set. It is also configured to use a 0.uk.pool.ntp.org as a time server so it should remain correctly set. I have also checked the ADDCs "which most clients ultimately use as time sources) have the correct date and time. I shall update my question to clarify these points. – TafT Oct 17 '16 at 12:07
  • and this is a fresh installation of ubuntu? or if it is cloned, is it cloned with a snapshot or booted cleanly? – mzhaase Oct 18 '16 at 10:14
  • I believe that all the VMs were created in a manner as outlined by http://www.oxfordsbsguy.com/2014/06/02/how-to-create-a-hyper-v-vm-template-without-vmm/ but without the sysprep stage as Ubuntu 14.04 was installed on the first Vm. So a new VM is created each time but the VHDx is manually copied. All VHDs are on the NTFS local disk of the server. These are all Generation 1 virtual machines. The few 16.04 machines that show the problem were 14.04 machines that had a do-release-upgrade recently. – TafT Oct 18 '16 at 14:28
  • @TafT Have you ever found a solution. I am experiencing that as well, syslog after boot shows time in future and then it fixes itself to correct time. – atapaka Nov 02 '17 at 11:55
  • @leosenko I have never found the root cause of this problem. If you do it would be great if you could post something back here. – TafT Nov 03 '17 at 12:13

2 Answers2

0

Based on my experience: (Every) OS on physical machine fistly gets time from hardware clock on motherboard. After bootup ntp client kicks in and can correct time based on information from ntp server. So: Linux VMs should firstly retrieve time from HyperVM Host, and later ntp can change time. Check the Settings in specific VM called "Integration Services". There is "Time synchronization" service. It controls whether Hardware Host shares the time to VM. Helps to keep time in sync.

  • I currently have the "Time synchronization" service disabled so that the Linux machine only uses NTP (once the network is up). What I need to know is why the VMs (virtual)hardware clock is set to such a strange datetime on boot. – TafT Oct 18 '16 at 13:29
  • The reason why time is in future is unknown for me. But as I remember I had issues in the past with time syncing in VM, and I resolved that by Enabling the Time Synchronization Option. – user381219 Oct 18 '16 at 13:39
  • I have not used Hyper-V much. I know that in the VMWare tools there were separate low level controls for whether the hardware clock was set at power on, resume or periodically. There was also the option to set the time using some integrated client process. My reading so far suggested that Hyper-V always set the hardware clock on power on and that the "Time Synchronization Option" only controls the sync of the clock after boot with the tools installed. If I do not have the tools installed on a client, it should still boot with the correct(ish) time shouldn't it? – TafT Oct 18 '16 at 14:07
  • 1
    Well, I have to swallow my own tounge. I have checked, and it seems that You are right. The "Time Synchronization Option" just helps to keep time in sync and is not required for VM for obtaining time from HyperV [link](https://blogs.msdn.microsoft.com/virtual_pc_guy/2010/11/19/time-synchronization-in-hyper-v) . The link also describes some interesting scenarios when VM time gets out of sync. – user381219 Oct 18 '16 at 17:53
  • 1
    Additionally: You say that there is no integration tools installed on VM. But modern linux distros have LIS (Linux Integration Services) already built-in and enabled [link](https://blogs.technet.microsoft.com/virtualization/2016/07/12/which-linux-integration-services-should-i-use-in-my-linux-vms/) – user381219 Oct 18 '16 at 17:57
  • Thank you for the links. I said "If I do not have the tools installed on a client" but it sounds like some tools would be there all the same. There is a plausible explanation of the situation I am seeing in your first link. The idea that the OS does not read the RTC because it thinks a reboot is not a big enough shift is a bit odd. Maybe I should see if the RTC on the host server is set correctly, I would hope it would match the time in Windows. – TafT Oct 19 '16 at 09:04
0

Make sure you use the right timezone in Ubuntu. You can also install the HyperV integration for Linux. In Hyper-V manager under the settings of a VM, under Management > Integration Services you can validate “Time synchronization”;

Good luck!!

BennyBoy
  • 121
  • 5
  • Both the output of `date` and `cat /etc/timezone` suggest that I am in the correct timezone. Even if I was not, I do not think that could account for several days of error. Is the basic problem that “Time synchronization” _must_ be used on all Ubuntu VMs that use DHCP to acquire IP addresses? – TafT Oct 19 '16 at 09:10