#!/bin/sh # # vmdk2vdi 1.0 20080207 # by Vicente Aguilar # http://www.bisente.com/blog/2008/02/07/vmware-to-virtual-box-vmdk2vdi/ # # Converts a VMWare .vmdk disk image into a VirtualBox .vdi one # # This script is beerware: If you like it, you owe me a beer. :) # QEMUIMG=${QEMUIMG:=/Applications/Q.app/Contents/MacOS/qemu-img} VDITOOL=${VDITOOL:=/Applications/VirtualBox.app/Contents/MacOS/vditool} UNAME=${UNAME:=$(uname -s)} echo "vmdk2dvi 1.0 by Vicente Aguilar http://www.bisente.com" echo if [ "$UNAME" == "Darwin" ] then if [ ! -f "$QEMUIMG" ] then echo "Can't find qemu-img." echo "Please download and install Q from:" echo "http://www.kju-app.org/kju/" exit 1 fi if [ ! -f "$VDITOOL" ] then echo "Can't find vditool." echo "Please download and install Virtual Box from:" echo "http://www.virtualbox.org/" exit 1 fi else QEMUIMG="$(which qemu-img)" if [ $? -ne 0 ] then echo "Can't find qemu-img." echo "Please download and install qemu from:" echo "http://fabrice.bellard.free.fr/qemu/" echo "Or use apt-get, yum or whatever your UNIX flavor uses." exit 1 fi DVITOOL="$(which dvitool)" if [ $? -ne 0 ] then echo "Can't find vditool." echo "Please download and install Virtual Box from:" echo "http://www.virtualbox.org/" echo "Or use apt-get, yum or whatever your UNIX flavor uses." exit 1 fi fi SHRINK=0 if [ "$1" == "-s" ] then SHRINK=1 shift fi if [ $# -lt 2 ] then echo "Error, missing parameters." echo "Usage: vmdk2vdi [-s] " echo " -s Shrink resulting image" echo exit 1 fi IN=$1 OUT=$2 TEMP=/tmp/vmdk2vdi-$RANDOM.raw "$QEMUIMG" convert "$IN" "$TEMP" "$VDITOOL" DD "$OUT" "$TEMP" rm -rf "$TEMP" [ $SHRINK ] && "$VDITOOL" SHRINK "$OUT"