Oracle Linux Virtualization Manager Importing Virtual Machines from VMware vCenter

Oracle Linux Virtualization Manager: Importing Virtual Machines from VMware vCenter


Marcos Sungaila
Senior Principal Technical Product Manager

When adopting a new virtualization solution, like Oracle Linux KVM with Oracle Linux Virtualization Manager, importing virtual machines from existing solutions is a common need. This allows you to preserve existing work and be productive from the very beginning of the new deployment. If you’re considering adopting Oracle Linux Virtualization Manager, this blog will be a helpful guide. It will take you through the steps to import a virtual machine from VMware vCenter. Let’s get started!

Migrating a virtual machine from VMware to Oracle Linux Virtualization Manager

Importing a virtual machine (VM) from VMware to Oracle Linux Virtualization Manager can be performed using native tools, such as the virt-v2v command line tool or the administration web portal’s import option from virtual machines.

When importing a VM using the Oracle Linux Virtualization Manager administration web interface, the import process will use libvirt through an VPX connection to vCenter and one ESXi server available in the VMware cluster to read and transfer the VM's disks and files.

This blog focuses on importing VMs from the command line using VMware's Virtual Disk Development Kit (VDDK) library.

Overview

The import process is performed by a KVM host member of the Oracle Linux Virtualization Manager deployment or a stand-alone KVM host.

The KVM host will either connect to both the vCenter and ESXi server or just go directly to the ESXi server. It will read the VM definition and create a temporary configuration file suitable for Oracle Linux Virtualization Manager. The KVM host will download and convert the virtual disks from vmdk to qcow format, storing them locally. It will create the VM on Oracle Linux Virtualization Manager and upload the converted virtual disks to the specified storage domain.

The overall performance will depend on network speed, source storage speed, and destination storage speed.

Requirements and restrictions

  • A VM disk must reside in a regular data store in the VMware environment. If the virtual disk is allocated in a virtual disk pool, you must perform a storage vMotion to move it to a regular data store in order to import the VM to Oracle Linux Virtualization Manager.
  • All VM's virtual disks must be allocated to the same data store.
  • A virtual disk must contain at least one file on it to be downloaded, converted, and imported by virt-v2v. Empty disks will not be imported even if you partition them or add them to a Logical Volume Management (LVM)volume.
  • A VM's network interface cards (NICs) must have an assigned IP address. VMs with no valid network configuration will not import.
  • To import a VM using the virt-v2v tool, the source VM must be powered off before starting the import process.
  • Download the latest version 7 VDDK lib from Broadcom's VMware Developer Portal. You must create a Broadcom account to download the package. Check Broadcom's Software Development Kit License Agreement before downloading and using it.
  • If you plan to import Windows VMs, follow these additional steps.
  • Verify that you have enough destination free disk space for the converted virtual disks before uploading to Oracle Linux Virtualization Manager.
  • Required ports communication from the KVM host running virt-v2v to vCenter:
    • 443/TCP
    • 5480/TCP
  • Required ports communication from the KVM host to the ESXi host:
    • 443/TCP
    • 902/TCP

Prepare to import a VM from VMware

Collect source VM information

  • Gather the following information from vCenter: 
    • vCenter FQDN
    • Data center name
    • Cluster name
    • ESXi hostname and IP
    • VM display name (no spaces) and its FQDN
    • VM IP, SM, and GW
    • VM virtual network name and VLAN ID
    • VM disk count, data store location, and sizes. Ensure all VM disks are on the same datastore, perform storage vMotion on source VM, if necessary

For Linux VMs:

  • VMware tools should be removed automatically by the virt-v2v tool.

For Windows VMs:

  • VMware tools must be manually uninstalled before powering down Windows VMs.
  • Install the winvirtio drivers and the QEMU Guest Agent on the source VM BEFORE powering it down. Power down the source VM gracefully, preferably via RDP or SSH connection.

NOTE: Windows VMs might not power down gracefully when using the power down option from vCenter, leaving some pending records.

Gather the VMware thumbprints

An SSL certificate thumbprint, or SSL certificate fingerprint, is a hash of a certificate calculated using all the certificate's data and signature. Thumbprints are usually implemented with cryptographic hash functions.

Since you can import a VM connecting to vCenter or directly from an ESXi server, you can collect the thumbprint from both.

Connect to the KVM host that will import the VMs.

Gather the thumbprint from an ESXi host:


Copied to Clipboard
Error: Could not Copy
Copied to Clipboard
Error: Could not Copy
openssl s_client -connect esx1.example.com:443 </dev/null | \
  openssl x509 -in /dev/stdin -fingerprint -sha1 -noout | \
  grep -i "fingerprint"

Sample output:


Copied to Clipboard
Error: Could not Copy
Copied to Clipboard
Error: Could not Copy
SHA1 Fingerprint=9F:A6:79:DF:C1:70:EC:8C:48:FC:1C:D0:30:F4:53:BF:24:39:E6:78

Gather the thumbprint from a vCenter:


Copied to Clipboard
Error: Could not Copy
Copied to Clipboard
Error: Could not Copy
openssl s_client -connect vcenter.example.com:443 </dev/null | \
  openssl x509 -in /dev/stdin -fingerprint -sha1 -noout | \
  grep -i "fingerprint"

Sample output:


Copied to Clipboard
Error: Could not Copy
Copied to Clipboard
Error: Could not Copy
SHA1 Fingerprint=C9:69:8C:65:92:3D:19:D4:80:B7:69:1A:A9:43:47:9B:26:53:FB:88

Prepare files for running virt-v2v

You will need the credentials to access the VMware and Oracle Linux Virtualization Manager environments. For Oracle Linux Virtualization Manager, only the admin@internal user is allowed, and its password must be stored on a file locally in the KVM host. To connect to VMware, you can choose which user to use and save the password in a file.

For Oracle Linux Virtualization Manager, you can use your file name of choice. In this example, the Oracle Linux Virtualization Manager admin@internal user password is stored on the $HOME/olvm-admin-pass file:


Copied to Clipboard
Error: Could not Copy
Copied to Clipboard
Error: Could not Copy
echo "Welcome1" > $HOME/olvm-admin-pass

It is recommended that you make this file readable by root only:


Copied to Clipboard
Error: Could not Copy
Copied to Clipboard
Error: Could not Copy
chmod 0600 $HOME/olvm-admin-pass

For the VMware user password, choose the file name you want to use. In this example, the VMware user password is stored on the $HOME/vmw-user-pass file:


Copied to Clipboard
Error: Could not Copy
Copied to Clipboard
Error: Could not Copy
echo "P@ssw0rd" > $HOME/vmw-user-pass

It is recommended that you make this file readable by root only:


Copied to Clipboard
Error: Could not Copy
Copied to Clipboard
Error: Could not Copy
chmod 0600 $HOME/vmw-user-pass

Download the engine server CA public key

Download the engine server CA public key and give it an understandable name in order to avoid conflicts, configure the Engine server hostname in a variable:


Copied to Clipboard
Error: Could not Copy
Copied to Clipboard
Error: Could not Copy
ENGINE="engine.example.com"

Download the CA public key using the following command:


Copied to Clipboard
Error: Could not Copy
Copied to Clipboard
Error: Could not Copy
curl -kL 'https://'$ENGINE'/ovirt-engine/services/pki-resource?resource=ca-certificate&format=X509-PEM-CA' -o /etc/pki/tls/certs/ca-$ENGINE.pem

Expand the VDDK lib on the KVM host

Expand the VDDK tarball on your KVM host local disk. Choose a location like /usr/local, for example. Avoid using your home directory or temp directories like /tmp or /var/tmp since they have special SELinux security contexts and may block the virt-v2v command from accessing the needed files.


Copied to Clipboard
Error: Could not Copy
Copied to Clipboard
Error: Could not Copy
tar xf VMware-vix-disklib-... -C /usr/local

Confirm it has been expanded correctly by listing the /usr/local directory content and looking for the vmware-vix-disklib-distrib directory:


Copied to Clipboard
Error: Could not Copy
Copied to Clipboard
Error: Could not Copy
ls /usr/local

Test your connection to the VMware environment

Ensure that you can connect to the VMware environment by listing VMs that are available in the ESXi host:


virsh -c 'esx://root@esx1.example.com?no_verify=1' list --all

Sample output:

py
# virsh -c 'esx://root@esx1.example.com?no_verify=1' list --all
Enter root's password for esx1.example.com:
Id   Name   State-----------------------
-    ol94   shut off

Import the VM from VMware

You will need to set some variables to make the import command easier to understand.

Create a file called v2v-vars.sh with the following options and adjust the content to reflect your environment:

y
# VMware user to connect to vCenter, use the %5c characters to separate
# the Domain name and the username
export VMWUSER="VSPHERE.LOCAL%5cUSERNAME"        

# An ESXi username that can ssh into the server
export ESXUSER="USERNAME"

# VMware vCenter FQDN or IP address
export VMWVCENTER="vcenter.example.com"

# VMware Datacenter
export VMWDC="APPS"

# VMware Cluster
export VMWCL="APP1CL"

# VMware ESXi host FQDN or IP address
export VMWESX="10.4.34.101"

# Engine server FQDN. Only the Engine hostname is allowed here.
# Add the Engine IP and hostname to the local /etc/hosts file if necessary.
export ENGINE="engine.example.com"

# OLVM Storage Domain name
export OLVMDS="Data"

# Engine server CA public key
export ENGINECACERT="/etc/pki/tls/certs/ca-engine.example.com.pem"

# ESXi host thumb print
export ESXTHUMBPRINT="9F:A6:79:DF:C1:70:EC:8C:48:FC:1C:D0:30:F4:53:BF:24:39:E6:78"

# vCenter thumb print
export VCENTERTHUMBPRINT="C9:69:8C:65:92:3D:19:D4:80:B7:69:1A:A9:43:47:9B:26:53:FB:88"

# Required by the rhv-upload option
export LIBGUESTFS_BACKEND="direct"

# Allow virt-v2v to enable VirtIO options while importing the VM
export VIRTIO_WIN=$HOME/oracle-winvirtio21-qemuagent-SCoter-20240417.iso

Option 1: Import by connecting to vCenter

Load the v2v-vars.sh content into memory:


Copied to Clipboard
Error: Could not Copy
Copied to Clipboard
Error: Could not Copy
source v2v-vars.sh

Configure the IMPORT_VM variable:

py
export IMPORTING_VM="PUT_THE_VM_NAME_TO_IMPORT_HERE"

Configure the OLVM cluster name to store the imported VM:


Copied to Clipboard
Error: Could not Copy
Copied to Clipboard
Error: Could not Copy
export OLVM_CLUSTER="OLVM_CLUSTER_NAME_TO_IMPORT_THE_VM"

It is recommended that you redirect the output to a file so you can inspect it later, if necessary. The following example uses the tee command to show the command output on the screen and saves it to a file.

Run the following virt-v2v command to import the VM.


Copied to Clipboard
Error: Could not Copy
Copied to Clipboard
Error: Could not Copy
virt-v2v \
  -ic vpx://${VMWUSER}@${VMWVCENTER}/${VMWDC}/${VMWCL}/${VMWESX}?no_verify=1 \ 
  -ip $HOME/vmw-user-pass \
  ${IMPORTING_VM} \
  -io vddk-libdir=/usr/local/vmware-vix-disklib-distrib \
  -it vddk \
  -io vddk-thumbprint=${VCENTERTHUMBPRINT} \
  -o rhv-upload \
  -oc https://${ENGINE}/ovirt-engine/api \
  -op $HOME/olvm-admin-pass \
  -os ${OLVMDS} \
  -of qcow2 \
  -oo rhv-cafile=${ENGINECACERT} \
  -oo rhv-direct \
  -oo rhv-cluster=${OLVM_CLUSTER} \
  --verbose \
  --network ovirtmgmt 2>&1 | tee -a /var/log/virt-v2v-${IMPORTING_VM}.log

Previous command options explained:

  • -ic vpx://${VMWUSER}@${VMWVCENTER}/${VMWDC}/${VMWCL}/${VMWESX}?no_verify=1
    VMware vCenter URI to connect to. The no_verify option allows connecting to a VMware secure connection.
  • -ip $HOME/vmw-user-pass
    VMware user password in plain text.
  • -o rhv-upload
    uploads the VM disk and metadata directly to Oracle Linux Virtualization Manager. This requires the LIBGUESTFS_BACKEND variable to be set to "direct".
  • -oc https://${ENGINE}/ovirt-engine/api
    Oracle Linux Virtualization Manager engine URL to connect to.
  • -op %HOME/olvm-admin-pass
    Oracle Linux Virtualization Manager admin user password in plain text. Only the admin@internal user is allowed to convert and upload VMs.
  • -os <olvm-data-store>
    Storage domain name at Oracle Linux Virtualization Manager to upload the VM’s virtual disk to.
  • -oo rhv-cluster=<olvm-cluster>
    Oracle Linux Virtualization Manager Cluster name if other than default.
  • -of qcow2
    VM disk will be saved in qcow2 format.
  • -oo rhv-cafile=${ENGINECACERT}
    Oracle Linux Virtualization Manager engine public CA certificate file.
  • -oo rhv-direct
    virt-v2v will try to upload the VM disk directly through the KVM node. Otherwise, virt-v2v will use the Oracle Linux Virtualization Manager engine as a proxy. This option requires that you have network access to KVM nodes.
  • --network <ovirtmgmt>
    maps all VM NICs in the destination VM to a specific network.

Option 2: Import by connecting to an ESXi server

Load the v2v-vars.sh content into memory:


Copied to Clipboard
Error: Could not Copy
Copied to Clipboard
Error: Could not Copy
source v2v-vars.sh

Configure the IMPORT_VM variable:


Copied to Clipboard
Error: Could not Copy
Copied to Clipboard
Error: Could not Copy
export IMPORTING_VM="PUT_THE_VM_NAME_TO_IMPORT_HERE"

Configure the OLVM cluster name to store the imported VM:


Copied to Clipboard
Error: Could not Copy
Copied to Clipboard
Error: Could not Copy
export OLVM_CLUSTER="OLVM_CLUSTER_NAME_TO_IMPORT_THE_VM"

It is recommended that you redirect the output to a file so you can inspect it later, if necessary.  The following example uses the tee command to show the command output on the screen and saves it to a file.

Run the following virt-v2v command to import the VM.


Copied to Clipboard
Error: Could not Copy
Copied to Clipboard
Error: Could not Copy
virt-v2v \
  -ic esx://${ESXUSER}@${VMWESX}?no_verify=1 \
  -ip $HOME/vmw-user-pass \
  ${IMPORTING_VM} \
  -io vddk-libdir=/usr/local/vmware-vix-disklib-distrib \
  -it vddk \
  -io vddk-thumbprint=${ESXTHUMBPRINT} \
  -o rhv-upload \
  -oc https://${ENGINE}/ovirt-engine/api \
  -op $HOME/olvm-admin-pass \
  -os ${OLVMDS} \
  -of qcow2 \
  -oo rhv-cafile=${ENGINECACERT} \
  -oo rhv-direct \
  -oo rhv-cluster=${OLVM_CLUSTER} \
  --verbose \
  --network ovirtmgmt 2>&1 | tee -a /var/log/virt-v2v-${IMPORTING_VM}.log

Troubleshooting

You can run the virt-v2v command with the verbose mode (-v) and the trace mode (-x). To help you debug,  enable the LIBGUESTFS_DEBUG variable as follows:


Copied to Clipboard
Error: Could not Copy
Copied to Clipboard
Error: Could not Copy
export LIBGUESTFS_TRACE=1
export LIBGUESTFS_DEBUG=1
virt-v2v -x -v -ic vpx://...

You can find additional variables that can be set in the following man pages:

Conclusion

After following the above steps, you'll be able to import VMs from VMware into Oracle Linux Virtualization Manager reliably and efficiently. Below are several additional resources to help with your migration to Oracle Linux Virtualization Manager.