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?

1

1 Answer 1

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
2
  • Original Thread, slightly changed and picked best answer IMO, just giving credit here Commented Oct 24, 2015 at 2:41
  • This is with Ubuntu Server 14.04 x64 and Vbox 5.* Commented Oct 24, 2015 at 2:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .