Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

First create the script, then make it executable, then "install it".

sudo nano /etc/init.d/StartVM && sudo chmod +x /etc/init.d/StartVM && sudo update-rc.d StartVM defaults

/etc/init.d/StartVM Contents:

#!/bin/sh
#Start VirtualBox @boot 
#Gracefully Shutdown @shutdown
#/etc/init.d/StartVM
#

#Edit these variables!
VMUSER=user
VMNAME1=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 savestate
    ;;
  *)
    echo "Usage: /etc/init.d/StartVM {start|stop}"
    exit 1
    ;;
esac

exit 0 
  • No labels