VMware Cloud Community
totoroliu
Enthusiast
Enthusiast
Jump to solution

How to add Virtual Serial Port to a VM in ESX 6.5 from Linux command line or API?

Hi,

I'm developing a script to import an OVF VM to an ESX 6.5 host.

I'm using ovftool command to run the import.

When I try to pass Virtual Serial Port properties (retreieved from .vmx file when I did manually via vSphere Client GUI),

ovftool returned warning:

$ ovftool \

--name="Test04" \

--acceptAllEulas \

-ds=datastore1 \

-dm=thin \

--net:'Network 1=VM Network' \

--prop:serial0.fileType='network' \

--prop:serial0.fileName='telnet://:7004' \

--prop:serial0.yieldOnMsrRead='TRUE' \

--prop:serial0.present='TRUE' \

./Test04.ovf \

vi://root:PASSWORD@172.18.125.43

Opening OVF source: ./FortiGate-VM64.ovf

Opening VI target: vi://root@172.18.125.43:443/

Deploying to VI: vi://root@172.18.125.43:443/

Transfer Completed                   

Warning:

- OVF property with key: 'serial0.fileName' does not exists.

- OVF property with key: 'serial0.fileType' does not exists.

- OVF property with key: 'serial0.present' does not exists.

- OVF property with key: 'serial0.yieldOnMsrRead' does not exists.

Completed successfully

And Virtual Serial Port is not added after the ovftool import.

After ovftool import,

I have also tried manully edit .vmx file by appending 4 lines at the end:

serial0.fileName = "telnet://:7003"

serial0.fileType = "network"

serial0.present = "TRUE"

serial0.yieldOnMsrRead = "TRUE"

but it still has no effect.

How can I add a "Virtual Serial Port" to an ESX 6.5 VM

without going through vSphere Client GUI or Web GUI?

Is it possibe to use vim-cmd from ESX host shell?

or any solution in Linux?

0 Kudos
1 Solution

Accepted Solutions
jasnyder
Hot Shot
Hot Shot
Jump to solution

You can do it with PowerCLI - check this page for reference for the first part of the script below - Access Virtual Machine through Console ( Serial Port) - PowerCLI and GUI examples: Add Serial port t...

Some of your settings I didn't see a way to set on the device or backing, so you can set using the New-AdvancedSetting cmdlet - New-AdvancedSetting - vSphere PowerCLI Cmdlets Reference

Example script below.  The 4 New-AdvancedSetting lines at the end are somewhat redundant, but I left them in case you wanted to make those settings after the device was already added through another mechanism.

$vm = Get-VM -Name "vm_name"

$dev = New-Object VMware.Vim.VirtualDeviceConfigSpec

$dev.operation = "add"

$dev.device = New-Object VMware.Vim.VirtualSerialPort

$dev.device.key = -1

$dev.device.backing = New-Object VMware.Vim.VirtualSerialPortURIBackingInfo

$dev.device.backing.direction = "server"

$dev.device.backing.serviceURI = "telnet://:7003"

$dev.device.connectable = New-Object VMware.Vim.VirtualDeviceConnectInfo

$dev.device.connectable.connected = $true

$dev.device.connectable.StartConnected = $true

$dev.device.yieldOnPoll = $true

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

$spec.DeviceChange += $dev

$vm.ExtensionData.ReconfigVM($spec)

New-AdvancedSetting -Entity $vm -Name serial0.fileName -Value "telnet://:7003" -Confirm:$False -Force:$True

New-AdvancedSetting -Entity $vm -Name serial0.fileType -Value "network" -Confirm:$False -Force:$True

New-AdvancedSetting -Entity $vm -Name serial0.present -Value TRUE -Confirm:$False -Force:$True

New-AdvancedSetting -Entity $vm -Name serial0.yieldOnMsrRead -Value TRUE -Confirm:$False -Force:$True

VM before running script:

pastedImage_3.png

After running:

pastedImage_5.png

If you want to chain this in the same script with ovftool, you could call ovftool first in the PowerShell script then run everything listed here against the same value for the VM name you pass into ovftool.

View solution in original post

5 Replies
jasnyder
Hot Shot
Hot Shot
Jump to solution

You can do it with PowerCLI - check this page for reference for the first part of the script below - Access Virtual Machine through Console ( Serial Port) - PowerCLI and GUI examples: Add Serial port t...

Some of your settings I didn't see a way to set on the device or backing, so you can set using the New-AdvancedSetting cmdlet - New-AdvancedSetting - vSphere PowerCLI Cmdlets Reference

Example script below.  The 4 New-AdvancedSetting lines at the end are somewhat redundant, but I left them in case you wanted to make those settings after the device was already added through another mechanism.

$vm = Get-VM -Name "vm_name"

$dev = New-Object VMware.Vim.VirtualDeviceConfigSpec

$dev.operation = "add"

$dev.device = New-Object VMware.Vim.VirtualSerialPort

$dev.device.key = -1

$dev.device.backing = New-Object VMware.Vim.VirtualSerialPortURIBackingInfo

$dev.device.backing.direction = "server"

$dev.device.backing.serviceURI = "telnet://:7003"

$dev.device.connectable = New-Object VMware.Vim.VirtualDeviceConnectInfo

$dev.device.connectable.connected = $true

$dev.device.connectable.StartConnected = $true

$dev.device.yieldOnPoll = $true

$spec = New-Object VMware.Vim.VirtualMachineConfigSpec

$spec.DeviceChange += $dev

$vm.ExtensionData.ReconfigVM($spec)

New-AdvancedSetting -Entity $vm -Name serial0.fileName -Value "telnet://:7003" -Confirm:$False -Force:$True

New-AdvancedSetting -Entity $vm -Name serial0.fileType -Value "network" -Confirm:$False -Force:$True

New-AdvancedSetting -Entity $vm -Name serial0.present -Value TRUE -Confirm:$False -Force:$True

New-AdvancedSetting -Entity $vm -Name serial0.yieldOnMsrRead -Value TRUE -Confirm:$False -Force:$True

VM before running script:

pastedImage_3.png

After running:

pastedImage_5.png

If you want to chain this in the same script with ovftool, you could call ovftool first in the PowerShell script then run everything listed here against the same value for the VM name you pass into ovftool.

totoroliu
Enthusiast
Enthusiast
Jump to solution

@jasnyder

Is PowerCLI available to Linux OS?

0 Kudos
jasnyder
Hot Shot
Hot Shot
Jump to solution

Yes as of a few months ago it is possible to use it on Linux.  I have not personally played with it yet, but here is an article explaining the setup.  How To Install and Use PowerShell and PowerCLI on Linux -- Virtualization Review

totoroliu
Enthusiast
Enthusiast
Jump to solution

Is it possible to do it through vCLI commands?

either commands from vCLI package or

commands directly on the ESX host shell

0 Kudos
totoroliu
Enthusiast
Enthusiast
Jump to solution

Now I'm using this hacky way to do it directly on ESX hypervisor host:

1. Get VMID

VMID=$(vim-cmd vmsvc/getallvms | sed -n "s:^([0-9])\s${VM_NAME}\s.$:\1:p")

2. Unregister VM

vim-cmd vmsvc/unregister "${VMID}"

3. Update .vmx file to add/define "Virtual Serial Port"

echo "

serial0.fileName = "telnet://:7003"

serial0.fileType = "network"

serial0.present = "TRUE"

serial0.yieldOnMsrRead = "TRUE"

" >> /vmfs/volumes/datastore1/${VM_NAME}/${VM_NAME}.vmx

4. Register VM

vim-cmd solo/registervm /vmfs/volumes/datastore1/${VM_NAME}/${VM_NAME}.vmx