Skip to content

Instantly share code, notes, and snippets.

@lpenz
Created October 5, 2016 17:12
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 lpenz/3901602f38f7b114379781bc2d6adb7d to your computer and use it in GitHub Desktop.
Save lpenz/3901602f38f7b114379781bc2d6adb7d to your computer and use it in GitHub Desktop.
Create a package.box for vagrant (virtualbox) from the specified raw img file
#!/bin/bash
IMG=${1?usage: $0 <img>}
NAME=wheezy32
set -e -x
rm -f "${IMG}.vmdk" package.box
VBoxManage convertfromraw "$IMG" "${IMG}.vmdk" --format vmdk
VBoxManage unregistervm "$NAME" --delete || :
VBoxManage createvm --name "$NAME" --ostype Ubuntu --register
VBoxManage modifyvm "$NAME" --memory 1024 --acpi on --vram 32 --pae on
VBoxManage modifyvm "$NAME" --nic1 nat
VBoxManage modifyvm "$NAME" --natpf1 ssh,tcp,,2022,,22
VBoxManage storagectl "$NAME" --name 'IDE Controller' --add ide --controller PIIX4
VBoxManage storageattach "$NAME" --storagectl 'IDE Controller' --port 0 --device 0 --type hdd --medium "${IMG}.vmdk"
vagrant box remove -f "$NAME" || :
vagrant package --base "$NAME"
vagrant box add "$NAME" package.box
# VBoxManage unregistervm "$NAME" --delete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment