How can I cause a VirtualBox VM (running Ubuntu) to run a command upon resuming its state?
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.
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.
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