vagrant box to libvirtd (QEMU) VM

2018-03-26 185 words 1 min read

Like ova images, you can use box images as well with Qemu. After all, both have the disk images, so here is the script to do that. Just put the script somewhere in your path and run with ova or box image name :

 

#!/bin/bash - 
#===============================================================================
#
#          FILE: ova2vm.sh
# 
#         USAGE: ./ova2vm.sh 
# 
#   DESCRIPTION: 
# 
#       OPTIONS: ---
#  REQUIREMENTS: ---
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: Amit Agarwal (aka),
#  ORGANIZATION: Mobileum
#       CREATED: 12/28/2017 13:59
# Last modified: Sun Mar 11, 2018  12:01PM
#      REVISION:  ---
#===============================================================================

set -o nounset                              # Treat unset variables as an error
dest='/mnt/Backup/VM'
ORIG=${PWD}

if [[ $# == 0 ]]
then
    echo "You need to provide ova/vmdk filename"
    exit
fi
if [[ $1 == *ova || $1 == *box ]]
then
    tmp=$(mktemp -d /tmp/amitXXXXXXX)
    cd  $tmp
    tar xvf $ORIG/$1
    file=$(echo $PWD/*vmdk)
else
    file=$1
    echo "Not a OVA file"
fi
dfile="$dest/$(basename $file)"

read -p "Enter the name for VM :: " vmname
qemu-img convert $file $dfile -p -c -O qcow2
virt-install --disk $dfile --ram 512 \
    --virt-type kvm --vcpus 1 --name "$vmname" --import

author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it