@ 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...