-
-
Save growtopiajaw/00a87a87d1f6b3899f318e7b2d882a0c to your computer and use it in GitHub Desktop.
Convert VMDK to OVA using VirtualBox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# http://jbrazile.blogspot.com.es/2012/01/scripted-vmdkova-images-wboxgrinder-and.html | |
# | |
NAME=$1 | |
OS=$2 | |
IMAGE= | |
SZMB=384 | |
INSTDIR=/tmp/ova-gen/boxes | |
BUILDDIR=/tmp/ova-gen/builds | |
if type VBoxManage >/dev/null 2>&1; then | |
echo | |
echo -e "Oracle VM VirtualBox is installed. Proceeding..." | |
echo | |
elif type apt-get >/dev/null 2>&1; then | |
echo | |
echo -e "Oracle VM VirtualBox is NOT installed. Installing..." | |
echo | |
wget -q https://www.virtualbox.org/download/oracle_vbox_2016.asc -O- | sudo apt-key add - | |
wget -q https://www.virtualbox.org/download/oracle_vbox.asc -O- | sudo apt-key add - | |
sudo sh -c 'echo "deb http://download.virtualbox.org/virtualbox/debian $(lsb_release -sc) contrib" >> /etc/apt/sources.list' | |
sudo apt-get update | |
sudo apt-get -y install virtualbox-6.0 | |
else | |
echo -e "Oracle VM VirtualBox is NOT installed. Please install it." | |
echo -e "Google is your friend" | |
exit 1 | |
fi | |
if [ -z "$NAME" ]; then | |
echo "Usage: ova-gen.sh <appliance-name> [ostype]" | |
echo "Example: ova-gen.sh my-virtual-machine-name Ubuntu_64" | |
echo "You may get a list of [ostype] at http://bit.ly/2YkjZvF" | |
exit 1 | |
fi | |
if [ -z "$OS" ]; then | |
OS=Linux26_64 | |
echo Setting OS type to $OS | |
fi | |
rm -rf $INSTDIR $BUILDDIR | |
mkdir -p $BUILDDIR $INSTDIR | |
if [ ! -d "build/appliances" ]; then | |
echo "Invalid directory. Running from Boxgrinder template build dir?" | |
echo "Directory build/appliances not found." | |
echo "Please create the directory and put your .vmdk image in build/appliances/<your-image-name>.vmdk" | |
exit 1 | |
fi | |
for vmdk in `find build/appliances/ -name '*.vmdk'`; do | |
echo Copying $vmdk to $INSTDIR | |
cp $vmdk $INSTDIR | |
IMAGE="$INSTDIR/`basename $vmdk`" | |
echo "IMAGE: $IMAGE" | |
done | |
VBoxManage createvm --name ${NAME} --ostype ${OS} --register --basefolder ${INSTDIR} | |
VBoxManage modifyvm ${NAME} --memory ${SZMB} --vram 32 | |
VBoxManage storagectl ${NAME} --name "SATA Controller" --add sata --controller IntelAHCI | |
VBoxManage storageattach ${NAME} --storagectl "SATA Controller" --type hdd --port 0 --device 0 --medium ${IMAGE} | |
VBoxManage export ${NAME} --manifest -o ${BUILDDIR}/${NAME}.ova | |
VBoxManage unregistervm ${NAME} --delete | |
echo "Your appliance is ready at ${BUILDDIR}/${NAME}.ova" | |
echo "Your ${NAME}.vmdk has been converted into ${NAME}.ova at ${BUILDDIR}/${NAME}.ova" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment