2

I want to automatically start a VirtualBox Virtual Machine at boot on a Ubuntu 14 Linux Headless Server.

I have tried @reboot via crontab, but the VboxHeadless command does not seem to work in conjunction with @reboot. I think its a timing issue.

So I have researched more and was guided to make a Upstart Script. How can I go about this?

5

Create Script >> Make it executable >> "Install" script via update-rc.d

cat << 'EOL' >/etc/init.d/StartVM
#!/bin/sh

#Edit these variables!
VMUSER=user
VMNAME=VM1
VMNAME2=Test

case "$1" in
  start)
    echo "Starting VirtualBox VM ..."
    sudo -u $VMUSER VBoxHeadless --startvm $VMNAME &
    sudo -u $VMUSER VBoxHeadless --startvm $VMNAME2 &
    ;;
  stop)
    echo "Saving state of Virtualbox VM ..."
    sudo -u $VMUSER VBoxManage controlvm $VMNAME savestate
    sudo -u $VMUSER VBoxManage controlvm $VMNAME2 acpipowerbutton
    ;;
  *)
    echo "Usage: /etc/init.d/StartVM {start|stop}"
    exit 1
    ;;
esac

exit 0
EOL
sudo chmod +x /etc/init.d/StartVM
sudo update-rc.d StartVM defaults
  • Original Thread, slightly changed and picked best answer IMO, just giving credit here – FreeSoftwareServers Oct 24 '15 at 2:41
  • This is with Ubuntu Server 14.04 x64 and Vbox 5.* – FreeSoftwareServers Oct 24 '15 at 2:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.