Created
April 23, 2015 15:23
-
-
Save pdxjohnny/736a4749ac4b8165ee44 to your computer and use it in GitHub Desktop.
Start Virtualbox VMs on boot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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