4

I have Ubuntu Server running as a guest on a Windows host using VirtualBox 3. The Ubuntu Server has guest additions installed.

To save a bit of time when I use this image, I suspend rather than shutting down. This works fine except for the date of the clock on the guest machine.

Is there a command I can run on the guest once it has been restored to force it to set the clock from the underlying host?

3 Answers 3

2

If you route Internet connection to the guest OS, you may use ntpdate to sync it's clock with special time servers, e.g.

sudo ntpdate ntp.ubuntu.com
1
  • 1
    I'm afraid that won't work for me because of the nature of my setup (ntpdate isn't installed on the machine and no regular internet access). That's why I took the trouble to install Guest Additions, so that the guest could get at the host's clock. Sadly it seems to only access it on a full initialisation of the client VM - rebooting the client OS isn't good enough.
    – Rich
    Jan 19, 2011 at 15:31
6

Since you have a Windows host, you can make sure you have an ntp server running locally: Link

You can verify if the server is turned on by running the following command:

w32tm /query /configuration

Keep in mind that you will need to be elevated to run this command. When you execute this, you will get back a laundry list of configuration settings. We are specifically interested in the NtpServer section:

NtpServer (Local)
DllName: C:\Windows\system32\w32time.dll (Local)
Enabled: 1 (Local)
InputProvider: 0 (Local)
AllowNonstandardModeCombinations: 1 (Local)

The third line will specify whether or not the NtpServer (aka the ‘server piece’) is turned on. If Enabled is 1, then it’s on. If you see that Enabled is 0, then it is off. If you aren’t running Vista or Server 2008, you can query the registry directly:

 reg query HKLM\system\CurrentControlSet\Services\W32Time\TimeProviders\NtpServer

You should see an entry that looks something like the following:

Enabled    REG_DWORD    0x1

As before, 1 is on, 0 is off. You can turn on the NtpServer at any time by running the following commands:

reg add HKLM\system\CurrentControlSet\Services\W32Time\TimeProviders\NtpServer /v Enabled /t REG_DWORD /d 0x1 /f

w32tm /config /update

The first command will change the Enabled flag in the registry to 1 (turning on the NtpServer), then the second command will tell the w32time service that the configuration in the registry need to be re-read, to make the changes active. You can confirm that the NtpServer is in fact running by calling w32time again:

w32tm /query /configuration

Then use that as your ntp server from within your Linux client

ntpdate 10.0.2.2

(Remember that when running NAT, 10.0.2.2 is the host address).

I was looking for the answer myself and found this useful as our firewall blocks the default ntp port.

0

You should install VirtualBox Guest Additions: https://www.virtualbox.org/manual/ch04.html#idm1933 and remove any ntp/ntpd installed. Please note that you have a package in Ubuntu/Debian named virtualbox-guest-dkms which will recompile when you upgrade the kernel, that's the best way to install Guest Additions.

VirtualBox will keep the date adjusted, even if you freeze the VM for a long time, and restart it from its frozen state. NTP can't do that, as it's meant to run without «pause».

Update: it seems that's a bug: https://www.virtualbox.org/ticket/16181

Update: I've read the following thread: https://forums.virtualbox.org/viewtopic.php?f=8&t=27279

And it seems that using the following in the guest will help (that the exact opposite of the OP's question):

VBoxService --enable-timesync

Strange thing is that even when I set --timesync-set-on-restore 1 the log shows Guest Property: /VirtualBox/GuestAdd/VBoxService/--timesync-set-on-restore not found.

But it seems to work a little bit better (if your host clock is right).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .