Skip to content

Instantly share code, notes, and snippets.

@schu
Created May 26, 2015 12:46
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 schu/95417a659b02f7ee143f to your computer and use it in GitHub Desktop.
Save schu/95417a659b02f7ee143f to your computer and use it in GitHub Desktop.
#!/bin/bash
set -eu
if [[ $# -lt 2 ]]; then
echo "usage: $0 <image.vdi> <name.box> [<vagrant package args>...]" >&2
exit 1
fi
readonly NAME="vdi2vagrantbox-${RANDOM}"
readonly IMG=$1
readonly BOX=$2
shift 2
VBoxManage createvm --name "${NAME}" --ostype Linux26_64 --register
VBoxManage storagectl "${NAME}" \
--name SATA --add sata --controller IntelAHCI
VBoxManage storageattach "${NAME}" \
--storagectl SATA --port 0 --device 0 --type hdd --medium "${IMG}"
vagrant package --base "${NAME}" --output "${BOX}" "$@"
# VBoxManage unregistervm "${NAME}" --delete
VBoxManage unregistervm "${NAME}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment