May 192018
 

For connect to virtual machine screen via VNC you need:

  1. Retrieve VM domain number (execute in XenServer console):
    xe vm-list params=dom-id name-label=[vm name] | grep dom-id
  2. Retrieve VNC port for this domain (execute in XenServer console):
    xenstore-read /local/domain/[domain]/console/vnc-port
  3. Make remote connection ([port] – last two digits from previous output), execute in remote console:
    vncviewer -via root@[xenserver] localhost:[port]

All together from remote console xen_vm_screen.sh:

#!/bin/bash
XEN_HOST=$1
VM=$2
XEN_USER=root
DOMAIN=`ssh $XEN_USER@$XEN_HOST "xe vm-list params=dom-id name-label=$VM | awk -F ':' '{gsub(/[ \t]+/, \"\", \\\$2); print \\\$2}'"`
VM_PORT=`ssh $XEN_USER@$XEN_HOST "xenstore-read /local/domain/$DOMAIN/console/vnc-port"`
vncviewer -via $XEN_USER@$XEN_HOST localhost:${VM_PORT:2:2}

Execute it as:

bash ./xen_vm_screen.sh vm_host_name vm_name