Skip to content

Instantly share code, notes, and snippets.

@pdxjohnny
Created April 23, 2015 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pdxjohnny/736a4749ac4b8165ee44 to your computer and use it in GitHub Desktop.
Save pdxjohnny/736a4749ac4b8165ee44 to your computer and use it in GitHub Desktop.
Start Virtualbox VMs on boot
#!/bin/bash
# Run as root
touch /etc/init.d/startvms
chmod +x /etc/init.d/startvms
update-rc.d startvms defaults 99 01
cat <<'EOF' >> /etc/init.d/startvms
#! /bin/sh
# /etc/init.d/startvms
#
#Edit these variables!
VMUSER=username
VMNAME="My VM Name"
case "$1" in
start)
echo "Starting VirtualBox VM..."
sudo -H -b -u $VMUSER /usr/bin/VBoxHeadless -s "$VMNAME"
;;
stop)
echo "Saving state of Virtualbox VM..."
sudo -H -u $VMUSER /usr/bin/VBoxManage controlvm "$VMNAME" savestate
;;
*)
echo "Usage: /etc/init.d/startvms {start|stop}"
exit 1
;;
esac
exit 0
EOF
vim /etc/init.d/starvms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment