Throughout this guide USER indicates the user on your system that is part of the virtual box management group and is able to run the 'VBoxManage' commands. The guide assumes that you already have a working virtual machine and so doesn't cover setup or configuration. The following can be applied to any guest, not just a Windows system.
The first thing to do was to create a script for starting your virtual machine.
This example is called server03start.sh:
#Script to start Server03 VBox machine in vrdp mode
su USER -c "VBoxManage startvm Server03 -type vrdp"
Once you have the script you need to make it executable:
chmod +x SCRIPTNAME
The next step is to copy your script to /etc/init.d/ and edit /etc/rc.local to run the script on system boot. Your rc.local file should look like this:
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
# In order to enable or disable this script just change the execution
# By default this script does nothing.
Your system will now start the virtual machine at boot.
Now we need to configure cleanly suspending the machine on system shutdown. Fortunately VirtualBox provides this facility for us.
If you look through /etc/init.d/vboxdrv you will find a section that reads
# enter the following variables in /etc/default/virtualbox:
# SHUTDOWN_USERS="foo bar"
# check for running VMs of user foo and user bar
# select one of these shutdown methods for running VMs
Do "sudo nano /etc/default/virtualbox" to create the required file and then enter the following:
I chose "savestate" as I decided that pausing the virtual machine during reboot was quicker and more efficient than fully shutting it down.
So, there we have it. Your system will now cleanly and quietly deal with your virtual machine during system reboot.