Skip to content

Instantly share code, notes, and snippets.

@tbatchelli
Created March 15, 2011 03:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tbatchelli/870284 to your computer and use it in GitHub Desktop.
Save tbatchelli/870284 to your computer and use it in GitHub Desktop.
#!/bin/bash
# register-vm.sh <path-to-vm> [<dest-dir>] (default dest-dir is ~/vmfest)
models_dir={$2-~/vmfest}/models
nodes_dir={$2-~/vmfest}/nodes
mkdir -p $models_dir
mkdir -p $nodes_dir
echo "Registering image $1"
source_path=$1
file_name=$(basename $source_path)
dest_path=$models_dir/$file_name
vm_name="vmfest-HD-register-hack"
echo "Cloning to $dest_path"
VBoxManage clonehd $source_path $dest_path
# all this is needed to ensure that the cloned hd is properly registered
VBoxManage createvm --name $vm_name --register
VBoxManage storagectl $vm_name --name "sata" --add sata
VBoxManage storageattach $vm_name --storagectl "sata" --port 0 --device 0 --mtype immutable --type hdd --medium $dest_path
VBoxManage unregistervm $vm_name --delete
# make the hd immutable
VBoxManage modifyhd $dest_path --type immutable
echo "Done."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment