tags 555296 + patch thanks Dear Maintainer,
After upgrading to Debian Squeeze, I lost my copy of "virtualbox-vm-control," so I wrote a new one. The new one is attached. This script will try very hard to stop VirtualBox VMs so the hibernation process can finish safely. Unfortunately, this script does not attempt to detect affected hardware configurations because I don't know how to do that correctly. Technical details: The script will check each user for any running VMs. For each VM it finds, it will do the following: 1. It will try to suspend the VM, as the running user. 2. If the VM failed to suspend, it will try to power off the VM, as the running user. 3. If any running VM failed to power off, it'll attempt to suspend the user's remaining VMs and then kill all the user's VirtualBox processes, as the running user. 4. If any VirtualBox process failed to die, it'll attempt to suspend every other user's VMs before killing all the VirtualBox processes. 5. By this point, no VMs should be running. If VMs failed to suspend, they were powered off. If the VMs didn't power off, that user's VirtualBox process was killed. If VirtualBox processes failed to die, all users' VirtualBox processes are killed. If even the root user couldn't guarantee all VMs were stopped, it'll quit with an error (1). 6. If no VMs appear to be running, quit normally (with 0). Please consider including this patch in future versions of Debian's VirtualBox so other users can safely combine Virtual Machines and hibernation. Thanks for your time, Nick -- System Information: Debian Release: 7.2 APT prefers stable-updates APT policy: (500, 'stable-updates'), (500, 'stable') Architecture: amd64 (x86_64) Foreign Architectures: i386 Kernel: Linux 3.2.0-4-amd64 (SMP w/2 CPU cores) Locale: LANG=en_US.utf8, LC_CTYPE=en_US.utf8 (charmap=UTF-8) Shell: /bin/sh linked to /bin/dash Versions of packages virtualbox depends on: ii adduser 3.113+nmu3 ii dpkg 1.16.12 ii libc6 2.13-38 ii libcurl3 7.26.0-1+wheezy4 ii libgcc1 1:4.7.2-5 ii libgsoap2 2.8.7-2 ii libpng12-0 1.2.49-1 ii libpython2.7 2.7.3-6 ii libsdl1.2debian 1.2.15-5 ii libssl1.0.0 1.0.1e-2 ii libstdc++6 4.7.2-5 ii libvncserver0 0.9.9+dfsg-1 ii libx11-6 2:1.5.0-1+deb7u1 ii libxcursor1 1:1.1.13-1+deb7u1 ii libxext6 2:1.3.1-2+deb7u1 ii libxml2 2.8.0+dfsg1-7+nmu2 ii libxmu6 2:1.1.1-1 ii libxt6 1:1.1.3-1+deb7u1 ii python 2.7.3-4+deb7u1 ii python2.7 2.7.3-6 ii zlib1g 1:1.2.7.dfsg-13 Versions of packages virtualbox recommends: ii libgl1-mesa-glx [libgl1] 8.0.5-4+deb7u2 ii libqt4-opengl 4:4.8.2+dfsg-11 ii libqtcore4 4:4.8.2+dfsg-11 ii libqtgui4 4:4.8.2+dfsg-11 ii virtualbox-dkms 4.1.18-dfsg-2+deb7u1 ii virtualbox-qt 4.1.18-dfsg-2+deb7u1 Versions of packages virtualbox suggests: ii vde2 2.3.2-4 pn virtualbox-guest-additions-iso <none> -- no debconf information
#! /bin/sh # Pause VirtualBox VMs during hibernation. # Some systems (x64 systems with AMD-V (and VT-x?) enabled, cannot hibernate # while Virtual Machines are running (if you try, the system will become # unresponsive). This script will try very hard to stop VirtualBox VMs so the # hibernation process can finish safely. # # Technical details: # # The script will check each user for any running VMs. For each VM it finds, it # will do the following: # # 1. It will try to suspend the VM, as the running user. # # 2. If the VM failed to suspend, it will try to power off the VM, as the # running user. # # 3. If any running VM failed to power off, it'll attempt to suspend the user's # remaining VMs and then kill all the user's VirtualBox processes, as the # running user. # # 4. If any VirtualBox process failed to die, it'll attempt to suspend every # other user's VMs before killing all the VirtualBox processess. # # 5. By this point, no VMs should be running. If VMs failed to suspend, they # were powered off. If the VMs didn't power off, that user's VirtualBox process # was killed. If VirtualBox processes failed to die, all users' VirtualBox # processes are killed. If even the root user couldn't guarantee all VMs were # stopped, it'll quit with an error. # # 6. If no VMs appear to be running, quit with 0. # Copyright (C) 2013 Nick Daly <nick.m.d...@gmail.com> # # This program is free software: you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software # Foundation, either version 3 of the License, or (at your option) any later # version. # # This program is distributed in the hope that it will be useful, but WITHOUT # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more # details. # # You should have received a copy of the GNU General Public License along with # this program. If not, see <http://www.gnu.org/licenses/>. set -e if [ "$1" != "hibernate" ] then # do nothing if we aren't hibernating. exit 0 fi userNoKill=0 for user in `who | cut -d ' ' -f 1 | sort | uniq` do userNoOff=0 echo "Suspending ${user}'s VMs..." for vm in `su $user -c "vboxmanage list runningvms | cut -d '\"' -f 2"` do echo "Suspending ${user}'s $vm VM..." # 1. try to save the VM's state su $user -c "vboxmanage controlvm $vm savestate" if [ $? = 0 ] then echo "${user}'s $vm VM suspended." else echo "${user}'s $vm VM didn't suspend, turning off." # 2. if suspend failed, turn off the VM su $user -c "vboxmanage controlvm $vm poweroff" if [ $? = 0 ] then echo "${user}'s $vm VM powered off." else userNoOff=1 echo "${user}'s $vm VM didn't turn off, killing VirtualBox later." fi fi done if [ "$userNoOff" = "1" ] then # 3. if turning off failed, kill VirtualBox. su $user -c "killall VirtualBox" if [ $? = 0 ] then echo "${user}'s VirtualBox killed." else userNoKill=1 echo "${user}'s VirtualBox didn't die, killing all VirtualBoxes later." fi fi done if [ "$userNoKill" = "1" ] then # 4. if couldn't kill virtualbox as user, kill as root. killall VirtualBox # 5. if we didn't kill VirtualBox processes, then quit with error. if [ $? != 0 ] then echo "All VirtualBoxes didn't die, can't suspend." exit 1 fi fi # no VMs are currently running. echo "No VMs are running, continuing to suspend." exit 0