7

I am running a few Ubuntu VMs on a MacBook Pro host.

Whenever I pause a VM or save its state to disk, the next time I restart it, the system clock goes out of sync.

Is there a way for the VM to know it has just been resumed, and run a command? (for example, running ntpdate -u time.nist.gov as root would do the trick)

I tried modifying the scripts in /etc/pm/sleep.d, but these don't appear to be called on VM suspend/resume.

4
  • For this particular case, shouldn't the Guest Additions do this automatically? Sep 9, 2011 at 21:54
  • @Mechanical snail, actually you might be right. I don't remember if I installed the guest additions on these VMs. (never thought to do that because they don't run a GUI) You should make this an answer.
    – mpontillo
    Sep 9, 2011 at 23:03
  • @Mechanical snail, good sign: I did mkdir /media/cdrom ; mount /dev/cdrom /media/cdrom ; cd /media/cdrom ; ./VBoxLinuxAdditions.run and it updated the guest additions from 4.0.10 to 4.0.12 and synchronized the clock. Good so far, but I guess I did have them installed before. (maybe there's a bug...) Now I'll test a save/resume cycle.
    – mpontillo
    Sep 9, 2011 at 23:08
  • @Mechanical snail, clock sync now works. Thanks! If you make this an answer I'll accept it.
    – mpontillo
    Sep 9, 2011 at 23:10

3 Answers 3

6

For this particular use, the Guest Additions is supposed to synchronize the VM's clock automatically. (See "Time synchronization" at http://www.virtualbox.org/manual/ch04.html, or if you want to customize it, http://www.virtualbox.org/manual/ch09.html#changetimesync.) It's possible that this updating might have stopped working when using an older version of the guest additions than the VirtualBox version on the host.

To install or update the Guest Additions, mount the Guest Additions CD image using the relevant menu command on the host, and run the script from the CD on the guest. For details see the directions at http://www.virtualbox.org/manual/ch04.html#idp11850096.

2

The easiest solution is to install DKMS on the server, which syncs time and does a lot of other useful things. This works on my OSX system, running VirtualBox with an Ubuntu VM Guest.

All I needed to do was run this on my VM:

sudo apt-get install virtualbox-guest-dkms
sudo reboot

People may need different packages specific to their linux flavor.

Ubuntu DKMS Reference: https://help.ubuntu.com/community/DKMS

0

You can use the crontab within linux if you want, it's not a full proof fix but you can set it so it runs every 5 minutes if you want which will execute the command you need, so updating the time with the server.

This blog post shows how to use the crontab. Also you can look at the CronHowTo @ Ubuntu Documentation

It might be useful for you.

8
  • Yeah, I actually thought about using crontab. I think that might be the workaround I'll have to use. But I don't want it to run constantly. Only when it wakes up from sleep. The laptop doesn't have consistent network access, and I don't want it constantly probing for the time server.
    – mpontillo
    Sep 1, 2011 at 0:10
  • It shouldn't matter so much, it wouldn't really be slowing down using the machine, as it is a service right Sep 1, 2011 at 0:18
  • Well, there's the problem that it will try and fail to get a connection sometimes. But there's also the problem that I would have to wait the 5 minutes (or whatever) after I started up the VM to continue working. The reason I care is that I am running programs that are sensitive to timestamps, so I'd rather it be event-driven than be the guy who annoys NIST by pounding their server with an NTP request every 5 seconds. ;-)
    – mpontillo
    Sep 1, 2011 at 1:23
  • I get what you mean, You could try what's listed in this article, rickguyer.com/… but with setting that value as 0 instead of 1? Sep 1, 2011 at 1:29
  • Thanks, I tried it and it didn't work. (maybe it doesn't work on OS X hosts?)
    – mpontillo
    Sep 1, 2011 at 2:00

You must log in to answer this question.

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