Generally, you will use virsh to control VMs, but there are a few useful functions you can get from xm but not virsh. We cover the most common commands here.

How to list the currently running VM on physical server?

# xm list
Name                                        ID   Mem VCPUs      State   Time(s)
0004fb00000600004689b1d1cc6e83d9             1  1027     1     r—–    293.5
Domain-0                                     0   830     4     r—–   1242.7

How to list the virtual CPUs which are assigned to VM with domain ID 1?

# xm vcpu-list 1
Name                                ID  VCPU   CPU State   Time(s) CPU Affinity
0004fb00000600004689b1d1cc6e83d9     1     0     2   -b-     287.8 any cpu

How to check the state of domain?

How to list the vNICs which are assigned to VM?

# xm network-list 1
Idx BE     MAC Addr.     handle state evt-ch tx-/rx-ring-ref BE-path
0   0  00:21:f6:cd:c2:87    0     4      6     768  /769     /local/domain/0/backend/vif/1/0

How to check the up time of the VM?

# xm uptime
Name                                ID Uptime
0004fb00000600004689b1d1cc6e83d9     2  0:01:07
Domain-0                             0  4:21:58

How to list the block devices associated with VM?

# xm block-list 1
Vdev  BE handle state evt-ch ring-ref BE-path
51712  0    0     4      12     9     /local/domain/0/backend/vbd/1/51712
51728  0    0     4      13     10    /local/domain/0/backend/vbd/1/51728

How to reboot domain from OVS server?

After reboot operation it will change the domain ID.

# xm list
Name                                        ID   Mem VCPUs      State   Time(s)
0004fb00000600004689b1d1cc6e83d9             3  1033     1     -b—-      1.3
Domain-0                                     0   831     4     r—–      1461.7

How to run the dry check to see whether domain is able to access the resources?

# xm dry-run /OVS/Repositories/0004fb0000030000f1532acb312df8a2/VirtualMachines/0004fb00000600004689b1d1cc6e83d9/vm.cfg
Using config file “/OVS/Repositories/0004fb0000030000f1532acb312df8a2/VirtualMachines/0004fb00000600004689b1d1cc6e83d9/vm.cfg”.
Checking domain:
0004fb00000600004689b1d1cc6e83d9: PERMITTED
Checking resources:
file:/OVS/Repositories/0004fb0000030000f1532acb312df8a2/VirtualDisks/0004fb0000120000f81558f292b2f52e.img: PERMITTED
file:/OVS/Repositories/0004fb0000030000f1532acb312df8a2/ISOs/V41362-01.iso: PERMITTED

How to save a domain?

To save the machine, issue:

# xm save [domain name or id] [savefile]

This command tells the domain to suspend itself; the domain releases its resources back to domain 0, detaches its interrupt handlers, and converts its physical memory mappings back to domain-virtual mappings (because the physical memory mappings will almost certainly change when the domain is restored).

How to restore a domain?

Restoring the domain is easy:

Restoration operates much like saving in reverse; the hypervisor allocates memory for the domain, writes out pages from the savefile to the newly allocated memory, and translates shadow page table entries to point at the new physical addresses. When this is accomplished, the domain resumes execution, reinstates everything it removed when it suspended, and begins functioning as if nothing happened.