4

I am having problem hibernating and suspending my Dell Laptop while virtualbox is running( XP Guest). I have tried default kernel method, uswsusp and tuxonice and none of them works. But if I close virtualbox, then hibernation and suspend works fine. Following are system specs. OS : Ubuntu 10.10 64bit (completey updated) Ram : 4GB Swap : 8 GB Root : 500 GB (of which, about 79% is free)

My laptop model is Dell Inspiron N5010. It has ATI HD 5000 series graphic chipset and I am used proprietary Drivers for it, installed via jockey.

Thanks.

3
  • 1
    I've not played around with this much, but I'm not particularly surprised that it doesn't work. A vitrualbox is not quite an application; I can't imagine the semantics that would be required. Do you hibernate the VMs and then the host? How would you signal a VM to hibernate? How could you confirm that it had? What should it do upon wake?
    – msw
    Jan 23, 2011 at 5:52
  • oddly enough, there was the answer in your comment " Do you hibernate the VMs and then the host? ", After reading this I found that there is a feature in virtualbox with which once save the current state of VMs. Its pretty much like hibernating, except that I am not hibernating the Guest OS explicitly. Morever the process is very fast and after that I can hibernate the Host OS normally. So, thanks for the comment. P.S: Please excuse my bad english, I am still learning.
    – hsinxh
    Jan 23, 2011 at 8:04
  • if you have an answer, please place it in the Answer section not as comment. May 4, 2011 at 14:18

4 Answers 4

4

I had the same problem, "pause" the virtual-guest-XP (HostKey-P) did work some times but often NOT. Putting the VM-Guest-XP in "saved-state" let the system hibernate again with no problems.
I wrote a small script, put it in /etc/pm/sleep.d/05_virtualbox (don't forget chmod a+x 05_virtualbox) and power-management will do the save-machine-state and start procedure on VMs automatically...

#!/bin/sh

# File: /etc/pm/sleep.d/05_virtualbox  #(at least in ubuntu/fedora)
# 
# This hack saves-state all VirtualBox-VM's off user $VBUSER on hibernate/suspend,
#   saves the list of this VMs in $VM_LIST_FILE, and on thaw/resume it starts all
#   VMs in that list again, and removes $VM_LIST_FILE.
# BUGS: don't use the same NAME for different VMs, or rewrite the script to use UUIDs
#
# a REAL hack, tried to comment as much as possible, but the chosen syntax is obfuscated, 
#   sorry...also sorry for the bad english...
#
# Writer (guilty person): Lutz Langenbach
# Copyleft: do what you want with the Code
# Help: VBoxManage 2>&1 |less or http://www.virtualbox.org/manual/ch08.html

VM_LIST_FILE=/var/tmp/vms-in-saved-state-list
VBUSER=Put_YOUR_username_here

PATH=/sbin:/usr/sbin:/bin:/usr/bin

case "${1}" in
  suspend|hibernate)
    # print list of running VM's output: "vm-name" {vm-uuid}\n
    # extract only the name of VM's and send 
    echo -n "Send savestate to VM's:"
    sudo  -u $VBUSER  VBoxManage list runningvms \
    |perl -ne 'chomp;s/^"([^"]*)".*/\1/; print $_; system("sudo -u '"$VBUSER"' VBoxManage controlvm \"$_\" savestate && echo \"$_\">>'"$VM_LIST_FILE"'");'
    echo ..done
    ;;
  resume|thaw)
    # get each line in $VM_LIST_FILE, use it as VM-Name and send start to it 
    echo -n "Send resume to VM's"
    cat $VM_LIST_FILE | perl -ne 'chomp;s/^"([^"]*)".*/\1/; system("sudo -u '"$VBUSER"' VBoxManage startvm \"$_\"");'
    rm -f $VM_LIST_FILE
    echo .
    ;;
  *)
    echo "Don't know what to do, 1st Arg was:${1}; Must be suspend|hibernate|resume|thaw"
    ;;
esac
1
  • @TuKsn thanks for the thanks, the script down below is better, can handle multiple users. i don't see the point to do heavy disk-IO in parallel, i might slow things down. i can't add a comment to your answere so i comment here: maybe you can rewrite the script to send 'VBoxManage controlvm <uuid> <acpipowerbutton|acpisleepbutton>' instead of savestate (+configure the guest to hibernate to disk and poweroff). But then poll 'VBoxManage list runningvms' till your script insures that everything is put to sleep.
    – Lutz L.
    Sep 30, 2014 at 9:43
3

As per the comments to the original question:

I found that there is a feature in virtualbox with which once save the current state of VMs. Its pretty much like hibernating, except that I am not hibernating the Guest OS explicitly. Morever the process is very fast and after that I can hibernate the Host OS normally.

This feature is known as Save Machine State.

3
  • Can you please identify the feature by name? I don't know what the feature is called.
    – ptrcao
    Oct 17, 2011 at 12:06
  • @ptrcao it's known as pause (i think). Not near my VBox machine, otherwise I'd double check
    – jrg
    Oct 17, 2011 at 12:25
  • I have never heard of this "pause" before... I use the "save machine state" option on closing the VM guest window - I don't know if this is the same as what you are talking about?
    – ptrcao
    Oct 17, 2011 at 12:46
0

@ Lutz L. First thank you for the script. I've the same problem on Xubuntu 14.04 with VB 4.3.10 and a Xubuntu 12.04 or a Windwos XP Guest is running on hibernate.

At the first try the script seems to work perfect. But the next time the VMs do not automatically resume when main system returns from the hibernate state.

This is the message that i find in the "pm-suspend.log" file:

Running hook /etc/pm/sleep.d/05_virtualbox thaw hibernate: Send resume to VM'sVBoxManage: error: The virtual machine 'Xubuntu12' has terminated unexpectedly during startup with exit code 1 VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component Machine, interface IMachine Waiting for VM "Xubuntu12" to power on...

I can manually resume the Guests, this works without a problem, but that is not as comfortable.

P.S.: The problem has been known for a long time as you can see here: https://www.virtualbox.org/ticket/7716

EDIT: There is a similar script:

#!/bin/bash
# Script to pause/resume running VBox VMs on hibernate/thaw
operation="$1"

# This script is invoked as root, but root cannot use VBoxManage to
# control the VMs of other users. So we obtain the members of the
# 'vboxusers' group and re-execute as each user in turn
if [ $(id -u) -eq 0 ] ; then
    # running as root...
    vboxusers=$(grep ^vboxusers /etc/group | cut -d ':' -f 4- | tr ',' ' ')
    for user in $vboxusers; do
        echo "restarting as $user..."
        su - $user -c "$0 $operation" || exit $?
    done
    exit 0
fi

hibernated_vm_list=$HOME/.vbox-hibernated-vms

# get a list of all running VMs, save their state to disk and
# remember that we have done this
hibernate_vms()
{
    rm -f $hibernated_vm_list

    # each line in list is: "vmname" {vm-uuid}
    local vm_list="$(VBoxManage list runningvms)"
    if [ -z "$vm_list" ] ; then # nothing to do
        return 0
    fi

    local tempfile="/tmp/VBoxPauseResume.tmp"
    echo "$vm_list" > $tempfile
    local pids=""
    while read line ;
    do
        vm_name=$(echo "$line" | sed 's/\(".*"\).*/\1/')
        vm_uuid=$(echo "$line" | sed 's/.*\({.*}\)/\1/')
        echo "saving state of vm $vm_name for user $user"
        (VBoxManage controlvm $vm_uuid savestate && \
            echo "$vm_name $vm_uuid" >> $hibernated_vm_list && \
            echo "saved state of vm $vm_name for user $user") &
        pids="$pids $!"
    done < $tempfile
    wait $pids
    rm -f $tempfile
}

# resumes any VMs that were saved by hibernate_vms(). Uses parallel
# child processes to thaw several VMs faster
thaw_vms()
{
    if [ -e $hibernated_vm_list ] ; then
        local pids=""
        while read line ;
        do
            vm_name=$(echo "$line" | sed 's/\(".*"\).*/\1/')
            vm_uuid=$(echo "$line" | sed 's/.*\({.*}\)/\1/')
            echo "resuming vm $vm_name for user $user"
            VBoxManage startvm $vm_uuid &
            pids="$pids $!"
        done < $hibernated_vm_list
        wait $pids
        rm -f $hibernated_vm_list
    fi
}

case $operation in
    hibernate) hibernate_vms ;;
    suspend) ;;
    thaw) thaw_vms ;;
    resume) ;;
esac

(Save this script as /etc/pm/sleep.d/02-VirtualBox, and make sure that it's executable)

Source: http://angryfifer.blogspot.de/2012/02/linux-hibernation-and-virtualbox.html

Sadly the same issue with this script...

0

@TuKsn

The problem is very simple to be solved - variable DISPLAY must be set.

VirtualBox uses it while starting vms in mode gui. The same problem occurs when I log via ssh and want to start a vm in mode gui.

Thanks for your script, it works great!

However I had to add some modification in order to store the mode in which the vms work (i.e. 'gui' or 'headless' or 'sdl') needed to properly restart the vms.

Below there is the script with my correctnesses included:


#!/bin/bash
# Script to pause/resume running VBox VMs on hibernate/thaw

# Set your display here
display=":0.0"

operation="$1"

# This script is invoked as root, but root cannot use VBoxManage to
# control the VMs of other users. So we obtain the members of the
# 'vboxusers' group and re-execute as each user in turn
if [ $(id -u) -eq 0 ] ; then
    # running as root...
    vboxusers=$(grep ^vboxusers /etc/group | cut -d ':' -f 4- | tr ',' ' ')
    for user in $vboxusers; do
        echo "restarting as $user..."
        su - $user -c "$0 $operation" || exit $?
    done
    exit 0
fi

hibernated_vm_list=$HOME/.vbox-hibernated-vms

# get a list of all running VMs, save their state to disk and
# remember that we have done this
hibernate_vms()
{
    rm -f $hibernated_vm_list

    # each line in list is: "vmname" {vm-uuid}
    local vm_list="$(VBoxManage list runningvms)"
    if [ -z "$vm_list" ] ; then # nothing to do
        return 0
    fi

    local tempfile="/tmp/VBoxPauseResume.tmp"
    echo "$vm_list" > $tempfile
    local pids=""
    while read line ;
    do
        vm_name=$(echo "$line" | sed 's/\(".*"\).*/\1/')
        vm_uuid=$(echo "$line" | sed 's/.*\({.*}\)/\1/')
        vm_type=$(VBoxManage showvminfo $vm_uuid | grep "Session type:" | awk '{print $NF}')
        case $vm_type in
            "headless") ;;
            "sdl") ;;
            "GUI/Qt") vm_type="gui" ;;
            *) vm_type="gui" ;;
        esac
        echo "saving state of vm $vm_name for user $user from mode $vm_type"
        (VBoxManage controlvm $vm_uuid savestate && \
            echo "$vm_name $vm_uuid $vm_type" >> $hibernated_vm_list && \
            echo "saved state of vm $vm_name for user $user") &
        pids="$pids $!"
    done < $tempfile
    wait $pids
    rm -f $tempfile
}

# resumes any VMs that were saved by hibernate_vms(). Uses parallel
# child processes to thaw several VMs faster
thaw_vms()
{
    if [ -e $hibernated_vm_list ] ; then
        local pids=""
        while read line ;
        do
            vm_name=$(echo "$line" | sed 's/\(".*"\).*/\1/')
            vm_uuid=$(echo "$line" | sed 's/.*\({.*}\)/\1/' | awk '{print $1}')
            vm_type=$(echo "$line" | sed 's/.*\({.*}\)/\1/' | awk '{print $2}')
            echo "resuming vm $vm_name for user $user in mode $vm_type"
            DISPLAY=$display VBoxManage startvm $vm_uuid --type $vm_type &
            pids="$pids $!"
        done < $hibernated_vm_list
        wait $pids
        rm -f $hibernated_vm_list
    fi
}

case $operation in
    hibernate) hibernate_vms ;;
    suspend) ;;
    thaw) thaw_vms ;;
    resume) ;;
esac

You must log in to answer this question.

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