XenServer Management Command Line

Copied from https://console.kim.sg/xenserver-management-command-line/

In a pool without HA.

Check who is alive and dead

xe host-list params=uuid,name-label,host-metrics-live

Login to any of the slave and check if it’s in emergency mode

xe host-is-in-emergency-mode

View all server hosts

xe host-list

Elect a new Poolmaster.

xe pool-emergency-transition-to-master

Recover the other pool servers

xe pool-recover-slaves

Determine the VMs still running on that failed server.

xe vm-list is-control-domain=false resident-on=UUID_OF_Failed_server

Reset the power state

xe vm-reset-powerstate resident-on= UUID_of_failed_server –-force –-multiple

 

This server can not be forgotten because there are some user VMs still running.

Get list of servers

xe host-list

Find what’s runnong on each server

xe vm-list resident-on=58ee6a78-c20c-4069-b07d-0b092e15fc1c

Reset the power state

xe vm-reset-powerstate uuid=603432e2-c85c-42fa-7bcd-430ddef6688a --force
xe vm-reset-powerstate uuid=062a61b6-0ee3-9383-adf9-e2a506e5e3be --force

Forget the dead poolmaster server

xe host-forget uuid=58ee6a78-c20c-4069-b07d-0b092e15fc1c

How to apply xenserver patches on CLI

Assign UUID to the patch

xe patch-upload file-name=path_to_update_file\XS000.xsupdate

Apply the patch using the generated uuid

xe patch-pool-apply uuid=

Confirm the patch

xe patch-list
xe patch-list | grep name-label | sort

 

Export & import VM to windows share

Login to the server hosting the vm you wish to export and mount destination

mount -t cifs -o username=xxx@xxx.com.sg //192.168.1.9/Common /mnt/

Export/import your vm

xe vm-export vm=xxx filename=/mnt/xxx.xva
xe vm-import filename=xxx.xva

Import vm to shared storage in a pool

xe sr-list
xe vm-import filename=Ubuntu.xva sr-uuid=214b4445-ef9b-626f-ca8b-58b8cbf4b281

Umount them once completed

umount /mnt

 

Export vm to external USB drive

Verify USB drive

fdisk -l

Format USB drive if required

mkfs -t ext3 /dev/sdx1

Mount USB

mkdir /mnt/usb
mount /dev/sdx1 /mnt/usb

Export vm using xenserver XAPI

xe vm-export vm=XXX filename=/mnt/usb/xxx.xva

Umount once completed

umount /mnt/usb

 

How to remove local SR (Storage Repository)

Identify UUID of SR you wish to remove

xe sr-list name-label=Local\ storage

Identify UUID of PBD (physical block device)

xe pbd-list sr-uuid=<UUID-OF-SR)

Remove by unplugging UUID of PBD

xe pbd-unplug uuid=<UUID-OF-PBD>

Remove completely by forgetting UUID of SR

xe sr-forget uuid=<UUID-OF-SR>

If you have trouble removing, check below logs

/var/log/messages.*
/var/log/SMlog.*

 

How to add local SR (Storage Repository)

Find disk ID of new device

cat /proc/partitions
ll /dev/disk/by-id

Create new SR type LVM

xe sr-create content-type=user device-config:device=/dev/disk/by-id/<scsi-xx> host-uuid=<host-uuid> name-label=”Local Storage 2” shared=false type=lvm

Create new SR type EXT

xe sr-create content-type=user device-config:device=/dev/sdx4 host-uuid=<host-uuid> name-label="Local EXT3" shared=false type=ext

 

Check VM running on which host

VM is running on which Host?

xe vm-list resident-on=

 

Check Xen server host spec & version

more /proc/cpuinfo
more /etc/redhat-release
xe patch-list
xe patch-list | grep name-label | sort

Change Xenserver hostname

xe host-set-hostname-live host-uuid=xx-xx-xx-xx-xx host-name=xxxx

 

 

Troubleshooting HA

Get list of xenserver hosts (alive & dead)

xe host-list
xe host-list params=uuid,name-label,host-metrics-live

Find what’s runnong on each host

xe vm-list resident-on=uuid-of-each-xen-server-host

Who is master now?

xe pool-list
more /etc/xensource/pool.conf

 

Change pool master in HA mode

Check HA status

xe pool-list params=name-label,uuid,ha-enabled

Disable HA

xe pool-ha-disable

Choose a new host to become a new pool master

xe host-list
xe pool-designate-new-master host-uuid=

Finally enable back HA

xe pool-ha-enable

 

Lost pool storage repository (SR) and heartbeat (lost everything)

Error: “The host could not join the liveset because the HA daemon could not access the heartbeat disk.”
Confirm that you lost everything and hosts are all in emergency mode

xe host-is-in-emergency-mode

Disable HA and unplug lost SR

xe host-emergency-ha-disable --force
xe pool-emergency-transition-to-master
xe sr-list name-label=XXX
xe pbd-list sr-uuid=<UUID-OF-SR)
xe pbd-unplug uuid=<UUID-OF-PBD>
xe-toolstack-restart
# Never get to use below command 
xe pool-designate-new-master
xe pool-emergency-reset-master

Use your backup to import your VMs

 

Adding a new network card to Xenserver

Scan to see if hwardware has dedected new NIC

lspci
lspci | grep -i ethernet
ifconfig -a

Scan and allow Xenserver to use new NIC

xe pif-scan host-uuid=xxxxxx-xxxxx-xxxx-xxxx-xxxxxx

#You can get host uuid by
xe host-list

Check for interface detected by Xenserver

xe pif-list

You may wish to set some custom param

xe pif-param-set uuid=<UUID of physical interface> other-config:ethtool-autoneg=”off”
xe pif-param-set uuid=<UUID of physical interface> other-config:ethtool-duplex=”full”
xe pif-param-set uuid=<UUID of physical interface> other-config:ethtool-speed=1000

To remove interface

xe pif-forget uuid=

 

Troubleshooting Xenserver

Temporarily enable DNS for ntp update

sudo echo "nameserver 8.8.8.8" | sudo tee -a /etc/resolv.conf
/etc/init.d/ntpd restart

Restart toolstack on master

xe-toolstack-restart