What's the best way to pause my work in Virtualbox with Ubuntu as a guest?

For Virtual Box it is not recommended to use the power saving features of the guest OS as this will all be handled by the host. Therefore first thing when having installed my guest OS I disable this (including disabling the screen saver).

The appropriate way to save a virtual machines state (and resume later) is to coose Save the machine state when closing the machine from virtual box manager (here depicted for Windows XP).

enter image description here

This will free all ressources from the virtual machine. Next time we start the machine we will resume exactly at the same state where we saved it (like in suspend/hibernate from a real machine).

From command line this can also be done by

VBoxManage controlvm <name_of_machine>  savestate

Note on security: Mind that resuming from a saved state does not ask for authentication for the guest OS. In case we work with confidential data we therefore need to log out (or switch user) from the guest OS before saving.


Create a script called 90_virtualbox in /etc/pm/sleep.d:

#!/bin/sh
#
# 90virtualbox: scan for active virtual machines and pause them on host suspend

VBoxManage list runningvms | while read line; do VBoxManage controlvm "$(expr match "$line" '"\(.*\)"')" pause; done