Skip to content

Instantly share code, notes, and snippets.

@riblo
Last active March 15, 2024 18:47
Show Gist options
  • Save riblo/7547c6a09230ae89a67179ca66723133 to your computer and use it in GitHub Desktop.
Save riblo/7547c6a09230ae89a67179ca66723133 to your computer and use it in GitHub Desktop.
Import VMware images (ovf based) to Proxmox VE
#!/bin/bash
# Script that import VMware images (ovf based) to Proxmox VE
# Your VM_NAME needs to be the same for: VM_NAME (directory) and VM_NAME.ovf
PROXMOX_USER=root
PROXMOX_PASS=ch4ng3m3!
PROXMOX_HOST=1.2.3.4
PROXMOX_PORT=22
PROXMOX_STORAGE=local-lvm
VM_PATH=/mnt/hgfs/shared/VM-Backup/
VM_NAME=$1
VMID=$2
if [[ -z "$1" || -z "$2" ]]; then
echo "usage: $0 <vm_name> <vm_id> "
exit 1
fi
# copy vm
sshpass -p $PROXMOX_PASS scp -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -r -P$PROXMOX_PORT $VM_PATH/$VM_NAME $PROXMOX_USER@$PROXMOX_HOST:.
# import and start vm
sshpass -p $PROXMOX_PASS ssh -A -v -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -p$PROXMOX_PORT $PROXMOX_USER@$PROXMOX_HOST bash -s << END
cd $VM_NAME
qm importovf $VMID $VM_NAME.ovf $PROXMOX_STORAGE
qm set $VMID -scsihw pvscsi -net0 model=vmxnet3,bridge=vmbr0
qm start $VMID
END
# remove vm files
if [ "$?" -eq 0 ]; then
rm -rf $HOME/$VM_NAME
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment