Autostart headless VirtualBox images on Ubuntu

Autostart virtual box images on boot
created by on 2013-10-21

This is the tutorial that works: https://forums.virtualbox.org/viewtopic.php?f=7&t=51799

This configuration starts a headless Windows 7 VirtualBox instance on system-start:

headless-windows7.conf

# headless-windows7 - start a headless Windows 7

description "Starts a headless Windows 7 VirtualBox instance on system-start"
author "Andreas Koch <andyk[email protected]>"

# Configuration
env user=andreas
export user

env vmname="Windows 7 (64bit)"
export vmname

# When to start the service
start on runlevel [2345]

# When to stop the service
stop on runlevel [016]

# Automatically restart process if crashed
respawn

# Essentially lets upstart know the process will detach itself to the background
expect fork

# Start
pre-start script
	echo "Starting headless VM: $vmname"
    sudo -H -b -u $user /usr/bin/vboxheadless --startvm "$vmname"
end script

# Stop
pre-stop script
    echo "Saving state of headless VM: $vmname"
    sudo -H -u $user /usr/bin/vboxmanage controlvm "$vmname" savestate
end script

Related information

Tags:
Fork allmark on GitHub