Tuesday, 18 November 2008

Ubuntu, VirtualBox and suspend

Hey, I know, long time no write, well, long time no time left...

and allways running around requires me to suspend my laptop a lot, mainly when suspending it with VirtualBox running. Well after resuming the suspend VirtualBox froze most of the times. Killing the program and restarting it did not work, removing the module was impossible, so the only fix was the reboot. Well until smarter thought came ofcourse.

Create an pm script (in Ubuntu go to /etc/pm/sleep.d/) create a newfile named 90virtualbox with the following contents:


USR_RNNG=$(ps aux |grep VirtualBox |grep -v grep |cut -f1 -d' ')
if [ "x$USR_RNNG" != "x" ]; then
if [ $(id -u) -eq 0 ]; then
su $USR_RNNG -c $0
for VMS in $(VBoxManage list runningvms |egrep "^[0-9]"); do
VBoxManage controlvm $VMS savestate
exit 0

Dont forget to make the script executable (chmod +x 90virtualbox).

Well that works for me, now before doing ACPI suspend the virtualbox machines are suspended nicely and afterwards you have to start them again, but they are up in a heartbeat (well 5 seconds in my case).

You can do that either by running VirtualBox gui and starting them or running:
VBoxManage start UUID|name_of_virtual_machine

Happy virtualizing...