19

I use multiple virtual boxes for development and correct time and date is important for me when I push git commits. I do not shut down my host - it runs for months without restarting. I only hibernate it for nights and weekends. This introduces weird issue to my guest operating systems (all debians from turnkeylinux.org) - after some time, the date of guest operating systems is off by few days.

Although all guests use NTP it does not work if it detects that date is off by some large values (few hours seems to be enough). Is there any way to force NTP sync even for large time differences? Or any other solution that would restore correct date and time on guest boxes after host resumes from hibernation?

2 Answers2

17

In brief: Install (the ntp package and) the VirtualBox Guest Additions :)

  • Host: Windows 6.1 SP1, x64, 3GB
  • VirtualBox: v4.3.6
  • Guest: Debian 7.3, 32-bits, 768 KB

From VirtualBox, attach the file Oracle\VirtualBox\VBoxGuestAdditions.iso to the guest system (Settings/Storage) and as root

cd /media/cdrom0
sh ./VBoxLinuxAdditions.run

The VirtualBox Help at "9.4. Advanced configuration for Linux and Solaris guests" describes the steps but I had to install the package linux-headers-3.2.0-4-486, first.
Then, as root,

/usr/lib/VBoxGuestAdditions/vboxadd setup
/usr/lib/VBoxGuestAdditions/vboxadd-service setup
/usr/lib/VBoxGuestAdditions/vboxadd setup

Afterwards, reboot the guest.

I've checked by quitting the guest system (Alt+F4, then order VirtualBox to save the state of the guest), waiting 5 minutes, then restarting the guest system
At first, the clock was restored from its previous value, but after a few seconds all went fine (clock synced)

Andrea
  • 1,536
Pierre
  • 327
1

NTP server was not designed to run inside of a virtual machine. It requires a high resolution system clock, with response times to clock interrupts that are serviced with a high level of accuracy. NTP client is ok to run in some virtualization solutions. Run NTP on the base OS of the machine, and then have your various guest OSes take advantage of the good clock that is created on the system. Even that may not be enough, as there may be additional tools or kernel options that you need to enable so that virtual machine clients can adequately synchronize their virtual clocks to the physical system clock.

Source: Support NTP Known Issues

From that statement, and reading that your important part is git commit times, then it would be trivial to write a pre-commit hook to gather the time from your host machine, and you can get that simply by asking your host machine:

ssh hostmachine "date +%Y%m%d%H%M%s"

vgoff
  • 286