Skip to content

Instantly share code, notes, and snippets.

@sianios
Created March 5, 2015 13:17
Show Gist options
  • Save sianios/155a464eb001f046df98 to your computer and use it in GitHub Desktop.
Save sianios/155a464eb001f046df98 to your computer and use it in GitHub Desktop.
Simple bash script to manage Headless VM with VirtualBox
#!/bin/bash
usage="Usage: ./vb.sh [option] [VM name]"
options="
Options:
list List available virtual machines
running List running virtual machines
start Start virtual machine
stop Send shutdown signal to OS to shutdown machine
poweroff Shutdown machine like pulling the plug
save Save state of running virtual machine
reset Send a restart signal to OS
"
case $1 in
list) VBoxManage list vms ;;
running) VBoxManage list runningvms ;;
start) VBoxHeadless -startvm $2 & ;;
stop) VBoxManage controlvm $2 acpipowerbutton ;;
poweroff) VBoxManage controlvm $2 poweroff ;;
save) VBoxManage controlvm $2 savestate ;;
reset) VBoxManage controlvm $2 reset ;;
*) echo -e ""$usage" \n" "$options"
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment