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?

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)

  • As a matter of fact, that's what I ended up doing :) Just didn't had time to post the answer, so the credit goes to you. – SiliconMind Jan 24 '14 at 10:58
  • NTP is not required for guest additions clock sync - it is performed by the guest additions daemon (VBoxService). – Pierz Jun 30 '16 at 10:28
  • 2
    Why do you suggest to repeat the first command twice? Is that really necessary? – RDP Oct 8 '16 at 14:35
  • @RDP <quote>Is it really necessary to repeat the first command twice?</quote> I don't remember, and documentation has changed see [virtualbox.org/manual/ch09.html#idm7495] – Pierre Oct 16 '16 at 13:19
  • You have to install gcc and make, too. Not having them manifests as an error starting the vboxadd service. But you don't get the helpful suggestion to install those packages unless you run vboxadd explicitly -- VBoxLinuxAdditions.run doesn't expose it. – Harry Tsai Mar 16 '17 at 12:49
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"

  • Thanks but that's not quite an answer :) I'm using VirtualBox and there are no options for time sync. So if not NTP then what? – SiliconMind Dec 17 '13 at 15:26
  • Sorry, I took the leap... but now with an edit clarified my thought. – vgoff Dec 17 '13 at 20:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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