Ubuntu, VirtualBox and suspend: VM clients never wakeup

Linux howto's, compile information, information on whatever we learned on working with linux, MACOs and - of course - Products of the big evil....

Ubuntu, VirtualBox and suspend: VM clients never wakeup

Postby peter_b » Sat Jan 14, 2017 4:57 pm

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

The sleep-script he suggests is a very nice solution!

To quote the posting:
"Create an pm script (in Ubuntu go to /etc/pm/sleep.d/) create a newfile named [90_virtualbox] with the following contents:"

(I added an underscore between "90" and "virtualbox" to match Ubuntu's naming convention for pm/sleep.d files)

Here's my variation of the "90_virtualbox" script (for Xubuntu 12.04 with VirtualBox v5.0.20):
Code: Select all
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
                su - $USR -c "VBoxManage controlvm $VMS pause"

                su - $USR -c "VBoxManage controlvm $VMS resume"

                echo ""
                echo "Unknown or empty sleep state: '$1'"
                echo "Valid options:"
                echo "  (hibernate|suspend) or (thaw|resume)"

Then make sure the file is correctly owned and executable:
Code: Select all
$ chown root:root /etc/pm/sleep.d/90_virtualbox
$ chmod 755 /etc/pm/sleep.d/90_virtualbox

Now you're done. Read on if you're interested in the modifications I've made:

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.

Thanks Neonatus and Yestertech! :D
  • 0

User avatar
Posts: 308
Joined: Tue Nov 12, 2013 2:05 am
Reputation: 3

Return to Knowledge Base

Who is online

Users browsing this forum: No registered users and 6 guests

Who is online over last 24 hours

Users browsed this forum in the last 24 hours: No registered users and 21 guests

Reputation System ©'