Time Syncronization in the Guest

Since the everything that the virtual machine can do is dependent on the host system's actual hardware, the system clock in your virtual machine is completely dependent on what is going on in the host system.

A couple of things going on here. The Host clock is basically a tiny crystal in a tiny box on the motherboard that reacts to an electrical current, The frequency of those reactions are measured and used to estimate how much time has passed, and that estimate is passed to the CPU if it's running. Whatever operating system then uses that estimate to come up with a date and time that it thinks the user will find helpful, but that estimate will always be slightly off because all of those little crystal things are imperfect by varying amounts. To counter this most OS's have a service that checks in with a global network of computers, many of which have direct access to atomic clocks. That network uses a special language titled NTP (Network Time Protocol). These are the basic tools that get used for keeping a guest machine up to date. We have a few ways available to combine these:

  1. Using NTP to periodically syncronize the vm system clock with the NTP network pool.
  2. Manually checking the time on your phone and setting the vm clock when you feel like you should.
  3. Synchronizing the vm system clock with the host system clock.

Taking these one by one:

1. DON'T USE NTP ON A VIRTUAL MACHINE. Mostly because it's dumb, but also for reasons. Basically it boils down to the fact that since this system is 'virtual,' it only gets the processor cycles needed to run itself. Because it's not guaranteed to get all the cycles that it expects, the system clock (which depends on the processor) ends up missing some of the ticks and tocks that it depends on. The NTP client for Linux depends on that basic clock being kind of sort of close to reality, if it's not then NTP gives up and doesn't syncronize. Your clock will just snowball away from reality until it's hours or even days behind the cosmos. Little note, apparently VMWare advises the use of NTP within their guest OS's, so you got that goin for ya. If your up for a laugh, there's a nice little gem back in the NTP documentation I sited earlier.

2. Yeah, sure, you could do this. There's no real performance overhead to your vm, but apparently your time isn't worth the cost of the light used to display this sentence.

3. Now we're talking. You should have already installed the Guest Additions for the vm. Well, it's time to use some of the options.

Here's one to type into your host machine:

VBoxManage guestproperty set "VM name" "/VirtualBox/GuestAdd/VBoxService/--timesync-interval" 1000

The 1000 at the end is the number of milliseconds between syncronizations, So this setting will sync once every second, the default is 10000 (or 10 seconds). This command sets a 'guestproperty' which is a line of code in the 'VM name.vbox' file, whereever you set that up. Mine are in <home directory>/VirtualBox VMs/VM name/.

After setting that, you should run these two to make sure that the settings take effect. Since the settings are with host, you'll to restart the execution instance of your vm, not just a reboot within the instance. Run these commands from the Host:

VBoxManage controlvm "VM name" poweroff

VBoxHeadless -startvm "VM name"

You should be good now.

Channel:

Recent content

Who's new

  • sno_75
  • Jeff
  • space space
  • Sunny Molini
  • admin

Who's online

There are currently 0 users online.

Recent comments