How to correctly sync time in linux running as virtual guest after host resumes from hibernation?

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)


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"