mirror of
https://github.com/RGBCube/vmware-to-proxmox-migration-script
synced 2025-07-25 23:47:45 +00:00
added function to create EFI disk for newly migrated VM
This commit is contained in:
parent
7399b7382e
commit
12b31b3def
1 changed files with 34 additions and 12 deletions
|
@ -69,66 +69,88 @@ function create_proxmox_vm() {
|
||||||
echo "Error: Invalid VM ID '$VM_ID'. Please enter a numeric value."
|
echo "Error: Invalid VM ID '$VM_ID'. Please enter a numeric value."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
# Check if a VM with the given ID already exists
|
# Check for VM that already exists with provided VM ID
|
||||||
if ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "qm status $VM_ID" &> /dev/null; then
|
if ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "qm status $VM_ID" &> /dev/null; then
|
||||||
echo "Error: VM with ID '$VM_ID' already exists. Please enter a different ID."
|
echo "Error: VM with ID '$VM_ID' already exists. Please enter a different ID."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Extract OVF from OVA
|
|
||||||
echo "Extracting OVF from OVA..."
|
echo "Extracting OVF from OVA..."
|
||||||
ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "tar -xvf /var/vm-migration/$VM_NAME.ova -C /var/vm-migration/"
|
ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "tar -xvf /var/vm-migration/$VM_NAME.ova -C /var/vm-migration/"
|
||||||
|
|
||||||
# Find the OVF file
|
|
||||||
local ovf_file=$(ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "find /var/vm-migration -name '*.ovf'")
|
local ovf_file=$(ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "find /var/vm-migration -name '*.ovf'")
|
||||||
echo "Found OVF file: $ovf_file"
|
echo "Found OVF file: $ovf_file"
|
||||||
|
|
||||||
# Find the VMDK file
|
|
||||||
echo "Finding .vmdk file..."
|
echo "Finding .vmdk file..."
|
||||||
local vmdk_file=$(ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "find /var/vm-migration -name '$VM_NAME-disk*.vmdk'")
|
local vmdk_file=$(ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "find /var/vm-migration -name '$VM_NAME-disk*.vmdk'")
|
||||||
echo "Found .vmdk file: $vmdk_file"
|
echo "Found .vmdk file: $vmdk_file"
|
||||||
|
|
||||||
# Ensure that only one .vmdk file is found
|
# Check for ensuring only one .vmdk file is found
|
||||||
if [[ $(echo "$vmdk_file" | wc -l) -ne 1 ]]; then
|
if [[ $(echo "$vmdk_file" | wc -l) -ne 1 ]]; then
|
||||||
echo "Error: Multiple or no .vmdk files found."
|
echo "Error: Multiple or no .vmdk files found."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Convert the VMDK file to raw format
|
# Convert .vmdk file to raw format
|
||||||
local raw_file="$VM_NAME.raw"
|
local raw_file="$VM_NAME.raw"
|
||||||
local raw_path="/var/tmp/$raw_file"
|
local raw_path="/var/tmp/$raw_file"
|
||||||
echo "Converting .vmdk file to raw format..."
|
echo "Converting .vmdk file to raw format..."
|
||||||
ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "qemu-img convert -f vmdk -O raw '$vmdk_file' '$raw_path'"
|
ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "qemu-img convert -f vmdk -O raw '$vmdk_file' '$raw_path'"
|
||||||
|
|
||||||
# Create the VM with UEFI BIOS, VLAN tag, and specify the SCSI hardware
|
# Create the VM
|
||||||
echo "Creating VM in Proxmox with UEFI, VLAN tag, and SCSI hardware..."
|
echo "Creating VM in Proxmox with UEFI, VLAN tag, and SCSI hardware..."
|
||||||
echo "VM ID is: $VM_ID"
|
echo "VM ID is: $VM_ID"
|
||||||
ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "qm create $VM_ID --name $VM_NAME --memory 2048 --cores 2 --net0 virtio,bridge=vmbr69,tag=$VLAN_TAG --bios ovmf --scsihw virtio-scsi-pci"
|
ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "qm create $VM_ID --name $VM_NAME --memory 2048 --cores 2 --net0 virtio,bridge=vmbr69,tag=$VLAN_TAG --bios ovmf --scsihw virtio-scsi-pci"
|
||||||
|
|
||||||
# Import the disk to local-lvm storage
|
# Import disk to local-lvm storage
|
||||||
echo "Importing disk to local-lvm storage..."
|
echo "Importing disk to local-lvm storage..."
|
||||||
ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "qm importdisk $VM_ID $raw_path local-lvm"
|
ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "qm importdisk $VM_ID $raw_path local-lvm"
|
||||||
|
|
||||||
# Attach the disk to the VM and set it as the first boot device
|
# Attach disk to VM and set it as first boot device
|
||||||
local disk_name="vm-$VM_ID-disk-0"
|
local disk_name="vm-$VM_ID-disk-0"
|
||||||
echo "Attaching disk to VM and setting it as the first boot device..."
|
echo "Attaching disk to VM and setting it as the first boot device..."
|
||||||
ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "qm set $VM_ID --scsi0 local-lvm:$disk_name --boot c --bootdisk scsi0"
|
ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "qm set $VM_ID --scsi0 local-lvm:$disk_name --boot c --bootdisk scsi0"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# Clear out temp files from /var/vm-migrations
|
# Clean up files from /var/vm-migrations on proxmox host
|
||||||
function cleanup_migration_directory() {
|
function cleanup_migration_directory() {
|
||||||
echo "Cleaning up /var/vm-migration directory..."
|
echo "Cleaning up /var/vm-migration directory..."
|
||||||
ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "rm -rf /var/vm-migration/*"
|
ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "rm -rf /var/vm-migration/*"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Clean up .ova files from local
|
||||||
function cleanup_local_ova_files() {
|
function cleanup_local_ova_files() {
|
||||||
echo "Removing local .ova files..."
|
echo "Removing local .ova files..."
|
||||||
rm -f "$VM_NAME.ova"
|
rm -f "$VM_NAME.ova"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Add an EFI disk to the VM
|
||||||
|
function add_efi_disk_to_vm() {
|
||||||
|
echo "Adding EFI disk to the VM..."
|
||||||
|
local vg_name="pve" #LVM volume group name - should be this by default
|
||||||
|
local efi_disk_size="4M"
|
||||||
|
local efi_disk="vm-$VM_ID-disk-1"
|
||||||
|
|
||||||
|
# Create EFI disk as a LV
|
||||||
|
echo "Creating EFI disk as a logical volume..."
|
||||||
|
ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "lvcreate -L $efi_disk_size -n $efi_disk $vg_name" || {
|
||||||
|
echo "Failed to create EFI disk logical volume."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Attach EFI disk to VM
|
||||||
|
echo "Attaching EFI disk to VM..."
|
||||||
|
ssh $PROXMOX_USERNAME@$PROXMOX_SERVER "qm set $VM_ID --efidisk0 local-lvm:$efi_disk,size=$efi_disk_size,efitype=4m,pre-enrolled-keys=1" || {
|
||||||
|
echo "Failed to add EFI disk to VM."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Main process
|
# Main process
|
||||||
export_vmware_vm
|
export_vmware_vm
|
||||||
transfer_vm
|
transfer_vm
|
||||||
create_proxmox_vm
|
create_proxmox_vm
|
||||||
cleanup_migration_directory
|
cleanup_migration_directory
|
||||||
cleanup_local_ova_files
|
cleanup_local_ova_files
|
||||||
|
add_efi_disk_to_vm
|
Loading…
Add table
Add a link
Reference in a new issue