[ESXi] Create virtual machine from OVF / OVA template using OVF Tool

The limitation of creating virtual machines from OVF / OVA using Web Client is that you cannot use Templates that are stored on Datastore. If you only create 1 virtual machine, it’s okay, but if you need to create 3-4 virtual machines at the same time for research, it will take a lot of time to manipulate and wait for the web client to upload the OVA / OVF file 3-4 times. In addition, it is also prone to timeout errors if the OVA file is too large.

To solve this problem, I will use the OVFTool tool to create a virtual machine from the OVA Template file being stored in the Datastore. Operations are performed on a computer running Windows 10, without having to access the ESXi web client.

1. Install OVF Tool

OVF Tool is VMWare’s command line tool for importing and exporting OVF / OVA Template files for its virtualization products.

Download the latest version of OVF Tool here: Open Virtualization Format Tool (ovftool) – VMware {code}

See instructions for using OVF Tool: Online Documentation – OVF Tool User’s Guide – VMware {code}

You need to install the OVF Tool on the desktop, not the ESXi server. I downloaded the OVF Tool for Windows x64 and installed it on my computer.

And on EndearvourOS / Arch Linux, I installed OVF Tool from AUR

yay -S vmware-ovftool

2. Download OVA to Datastore

Access the ESXi server using SSH and use the command wget to download Ubuntu’s OVA

cd /vmfs/volumes/datastore1
mkdir ISO
cd ISO
wget http://www.casler.org/wordpress/wp-content/uploads/2019/04/ddwrt-x86-20190327.ova

3. Get the link of OVA

Open a web browser, access the address: https://<ESXi-IP-Address>/folderlog in with the default account.

Find the folder containing the downloaded ova file, right-click and select Copy link to copy the link of this ova file.

The link of the OVA will be similar to the following: https://192.168.0.35/folder/ISO/ddwrt-x86-20190327.ova?dcPath=ha-datacenter&dsName=datastore1

You will use this link to create a new virtual machine using the OVF Tool

4. Create a virtual machine with OVF Tool

Open Windows PowerShell, access the folder containing the OVF Tool: C:Program FilesVMWareVMWare OVF Tool.

Check the parameters of the OVA file with the command

.ovftool "https://192.168.0.35/folder/ISO/focal-server-cloudimg-amd64.ova?dcPath=ha-datacenter&dsName=datastore1"

You need to enter your ESXi account & password. The parameters of the virtual machine will be returned as below

Create a new virtual machine from OVA file using ovftool with the following command

.ovftool -ds=datastore1 "https://192.168.0.35/folder/ISO/ddwrt-x86-20190327.ova?dcPath=ha-datacenter&dsName=datastore1" "vi://192.168.0.35"

Attention:

  • Replace value datastore1 of parameters -ds with the name of the datastore you want to store the new virtual machine in
  • Replace 192.168.0.35 with the IP address of the ESXi.

The OVF Tool will ask you to log in twice: once to access the OVA file and once to create a new virtual machine.

OVF Tool reports an error: Error: No network mapping specified. OVF networks: Masked asafeplace. Target networks: VM Networks

The reason is that on ESXi, there are not 2 networks available with the names Masked and asafeplace set in the configuration of the OVA file. Therefore, I need to add parameters --net:"<SourceVMNetwork>=<DestinationVMNetwork>

.ovftool -ds=datastore1 --net:"Masked=VM Network" --net:"asafeplace=VM Network" "https://192.168.0.35/folder/ISO/ddwrt-x86-20190327.ova?dcPath=ha-datacenter&dsName=datastore1" "vi://192.168.0.35"

Wait about 10-30 seconds. This time, the virtual machine has been created successfully.

Accessing the web client, the new virtual machine will appear with the name: ddwrt-x86-20190327. ESXi automatically names the virtual machine based on the file name ova.

I will create a new virtual machine, this time I add parameters -n=DD-WRT2 (name the virtual machine) and --powerOn (virtual machine starts automatically after creation)

.ovftool -ds=datastore1 --net:"Masked=VM Network" --net:"asafeplace=VM Network" -n=DD-WRT2 --powerOn "https://192.168.0.35/folder/ISO/ddwrt-x86-20190327.ova?dcPath=ha-datacenter&dsName=datastore1" "vi://192.168.0.35"

DD-WRT2 virtual machine after creation is automatically run on ESXi.

4. Note

  • You can use the OVA file stored on the desktop, stored on the Datastore or saved on the NAS, as long as ESXi can connect to the link of the OVA file.
  • You should only download the OVA / OVF template file from a trusted source, or create your own OVA from your existing virtual machine. Using a bad template can get a virus / backdoor pre-installed in the virtual machine that you have no control over.
  • Each OVA / OVF Template file will have different parameter requirements when executed with the OVF Tool to create a successful virtual machine. For example, above, I have to have parameters --net DD-WRT virtual machine can be created. Therefore, it is necessary to pay attention to check the information of the template with the command ovftool fileova.ova for proper parameter usage.

Hope you are succesful.

If my article brings useful information and knowledge to you, don’t be afraid to invite me a glass of beer to have more motivation to share more. Thank you!

PLEASE BEER

Leave a Reply

Your email address will not be published. Required fields are marked *