When I suspend my Xubuntu (12.04) machine, while having VirtualBox VMs running, they never come back to life after resuming the host
Seems like I'm not the only one with this issue and it seems to be an old one.
Here's a posting by "neonatus" from 2008:
http://blog.neonatus.net/2008/11/ubuntu ... spend.html
[SOLUTION]
The sleep-script he suggests is a very nice solution!
To quote the posting:
(I added an underscore between "90" and "virtualbox" to match Ubuntu's naming convention for pm/sleep.d files)"Create an pm script (in Ubuntu go to /etc/pm/sleep.d/) create a newfile named [90_virtualbox] with the following contents:"
Here's my variation of the "90_virtualbox" script (for Xubuntu 12.04 with VirtualBox v5.0.20):
Code: Select all
#!/bin/sh
for USR in $(ps aux |grep VirtualBox |grep -v grep |cut -f1 -d' '| uniq); do
for VMS in $(su - $USR -c "VBoxManage list runningvms |cut -f2 -d'{' |cut -f1 -d'}'"); do
case "$1" in
hibernate|suspend)
su - $USR -c "VBoxManage controlvm $VMS pause"
;;
thaw|resume)
su - $USR -c "VBoxManage controlvm $VMS resume"
;;
*)
echo ""
echo "Unknown or empty sleep state: '$1'"
echo "Valid options:"
echo " (hibernate|suspend) or (thaw|resume)"
exit
;;
esac
done
done
Code: Select all
$ chown root:root /etc/pm/sleep.d/90_virtualbox
$ chmod 755 /etc/pm/sleep.d/90_virtualbox
Why my modifications?
I encountered some issues with his code and couldn't use is as-is.
User yestertech's adaptation for Mandriva already contained some fixes/improvements.
Here's a list of my minor changes to yestertech's version:
- Extracted the "foreach VM"-loop (since the listing was identical)
- Removed "egrep", since my VirtualBox version's output doesn't seem to require it?
- Changed to use UUIDs rather than VM names. There can be problematic characters in the VM name...
- Named the file "90_virtualbox" instead of "90virtualbox" to conform with default Ubuntu/Debian naming.