Wed 11 Feb 2009
Suspending your VM
Posted by jjaimon under Technical
No Comments
I noticed that I must always suspend or shutdown my VMs before I suspend the laptop. If not, vmware causes heavy swapping when I resume from suspend. I can normally take care of this when I intentionally suspend my laptop. The problem is with my ACPI configurations. My preferences on battery power is to suspend after 30minutes of inactivity or when the lid is closed. Sometimes, when an accidental closing or power failure or pulling out the cable while the lid is closed causes the laptop to suspend automatically.
I was looking for an option to avoid this. Then, I came across the sleep.d scripts. You can place a script in
/usr/lib/pm-utils/sleep.d
directory. This has the format of pam scripts and will be executed based on the prefixed number on the filename. I have the following file in my sleep.d to suspend my running VM before the laptop is suspended.
/usr/lib/pm-utils/sleep.d/11pm-suspend-vm
#!/bin/bash
. /usr/lib/pm-utils/functions
suspend_vm()
{
vm=`vmrun list | grep winxp`
if [ -n "$vm" ]; then
logger "pm-suspend-vm: suspending the running $vm"
vmrun suspend "$vm"
stopservice vmware
else
logger "pm-suspend-vm: no running vms found"
fi
return 0
}
resume_vm()
{
return 0
}
case "$1" in
hibernate|suspend)
suspend_vm
;;
thaw|resume)
resume_vm
;;
*)
;;
esac
exit $?
