Created
June 8, 2021 13:54
-
-
Save thesp0nge/879a36907c14cf10dcb0c974e2012f55 to your computer and use it in GitHub Desktop.
An OVA to QCOW2 file format converter, useful for KVM
This file contains 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/bash | |
MYNAME=`basename $0` | |
QEMU=`which qemu-img` | |
if [ ! -x $QEMU ]; then | |
echo "$MYNAME: qemu-img is not installed. Can't continue." | |
exit -5 | |
fi | |
if [ ! $# -eq 1 ]; then | |
echo "$MYNAME: missing ova filename" | |
exit -1 | |
fi | |
OVA=$1 | |
if [ ! -f $OVA ]; then | |
echo "$MYNAME: $OVA is not a file" | |
exit -2 | |
fi | |
if [ ! -r $OVA ]; then | |
echo "$MYNAME: $OVA is not readable" | |
exit -3 | |
fi | |
echo "[+] converting $OVA to qcow2 format" | |
cwd=`pwd` | |
tmp_dir=$(mktemp -d -t ova-to-virt-XXXXXXXXXX) | |
mv $OVA $tmp_dir | |
cd $tmp_dir | |
tar xfv $OVA > /dev/null | |
VMDK=`find . -iname "*.vmdk" | head -n 1` | |
if [ ! -f $VMDK ]; then | |
echo "$MYNAME: $VMDK is not a file" | |
exit -2 | |
fi | |
if [ ! -r $VMDK ]; then | |
echo "$MYNAME: $VMDK is not readable" | |
exit -3 | |
fi | |
QCOW=`basename $VMDK .vmdk`.qcow2 | |
$QEMU convert -O qcow2 $VMDK $QCOW | |
if [ ! -f $QCOW ]; then | |
echo "$MYNAME: $QCOW is not a file" | |
exit -2 | |
fi | |
if [ ! -r $QCOW ]; then | |
echo "$MYNAME: $QCOW is not readable" | |
exit -3 | |
fi | |
echo "[+] done" | |
mv $QCOW $cwd | |
cd $cwd | |
rm -rf $tmp_dir | |
if [ ! $UID -eq 0 ]; then | |
echo "$MYNAME: login as root and execute 'mv $QCOW /var/lib/libvirt/images'" | |
exit 0 | |
fi | |
mv $QCOW /var/lib/libvirt/images | |
echo "$MYNAME: $QCOV is in libvirt image directory. Now you can create a VM using it as disk" | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment