Apr 282011
 

I use virtualbox a lot and have for years.  One of the things I can never remember is how to clone a vdi disk image.  I sometimes need to quickly deploy a testing environment, say 3 – 10 identical base machines, and this script makes it really quick and easy.  Enjoy….

#!/bin/bash
# Written by Ed Wiget
# This script is very simple, you simply enter the full path of a virtualbox
# disk to clone and then the full path of the virtualbox disk you are cloning
# to.
vboxmanage=`which VBoxManage`
clonecmd=clonehd
echo "Please enter the full path of the virtualbox disk to clone from..."
echo "i.e. /home/mydir/./VirtualBox\ VMs/Arch\ MooseFS\ Master\ Testing/Arch\ MooseFS\ Master\ Testing.vdi"
read sourcevdi
echo "Please enter the full path of the virtuablx disk to clone to..."
echo "i.e. /home/mydir/./VirtualBox\ VMs/Arch\ MooseFS\ Master\ Testing/Arch\ MooseFS\ Master\ Testing2.vdi"
read destinationvdi
echo "Now cloning ${sourcevdi} to ${destinationvdi}"
echo ""
echo "The full command is...."
echo "${vboxmanage} ${clonecmd} ${sourcevdi} ${destinationvdi}"
${vboxmanage} ${clonecmd} ${sourcevdi} ${destinationvdi}
echo "done"