22.1. virsh the command line interface tool for virtualization
The virsh command is an alternative command to manage a Red Hat Enterprise Linux 5 Xen environment using a Command Line Interface(CLI). The virsh command is provided as part of the libvirt API which provides a common API to applications requiring standardized access to interact with Xen using a stable interface. Besides providing virsh the libvirt API also provide a higher level language API for C, Python, and Perl (via the CPAN network) The virsh command is an interactive shell which can either be used in scripts or interactively. The following virsh commands assume you have already run virsh and are at a virsh# prompt.
The following are basic and commonly used virsh commands:
| command | description |
|---|---|
help
|
print help |
list
|
list domains |
create
|
create a domain from an XML file |
start
|
start a previously created inactive domain |
destroy
|
destroy a domain |
define
|
define (but do not start) a domain from an XML file |
domid
|
convert a domain name or UUID to domain id |
domuuid
|
convert a domain name or id to domain UUID |
dominfo
|
domain information |
domname
|
convert a domain id or UUID to domain name |
domstate
|
domain state |
quit
|
quit this interactive terminal |
reboot
|
reboot a domain |
restore
|
restore a domain from a saved state in a file |
resume
|
resume a domain |
save
|
save a domain state to a file |
shutdown
|
gracefully shutdown a domain |
suspend
|
suspend a domain |
undefine
|
undefine an inactive domain |
virsh commands
Use the following virsh commands to manage resources:
| command | description |
|---|---|
setmem
|
changes the allocated memory. |
setmaxmem
|
changes maximum memory limit. |
setvcpus
|
changes number of virtual CPUs. |
vcpuinfo
|
domain vcpu information. |
vcpupin
|
control the domain vcpu affinity. |
virsh resource management commands
Use the following virsh commands for monitoring and troubleshooting:
| command | description |
|---|---|
version
|
show version |
dumpxml
|
domain information in XML |
nodeinfo
|
node information |
virsh monitoring and troubleshooting commands
The connect command that is used to connect or reconnect to a hypervisor.
virsh command output
The following are example outputs from common virsh commands:
the list command:
virsh # list Id Name State ---------------------------------- 0 Domain-0 running 13 r5b2-mySQL01 blocked
the dominfo command:
domain
virsh # dominfo r5b2-mySQL01 Id: 13 Name: r5b2-mySQL01 UUID: 4a4c59a7-ee3f-c781-96e4-288f2862f011 OS Type: linux State: blocked CPU(s): 1 CPU time: 11.0s Max memory: 512000 kB Used memory: 512000 kB
the domstate command:
domain
virsh # domstate r5b2-mySQL01 blocked
the domuuid command:
domain
virsh # domuuid r5b2-mySQL01 4a4c59a7-ee3f-c781-96e4-288f2862f011
the vcpuinfo command:
domain
virsh # vcpuinfo r5b2-mySQL01 VCPU: 0 CPU: 0 State: blocked CPU time: 0.0s CPU Affinity: yy
the dumpxm command:
domain
virsh # dumpxml r5b2-mySQL01 <domain type='xen' id='13'> <name>r5b2-mySQL01</name> <uuid>4a4c59a7ee3fc78196e4288f2862f011</uuid> <bootloader>/usr/bin/pygrub</bootloader> <os> <type>linux</type> <kernel>/var/lib/xen/vmlinuz.2dgnU_</kernel> <initrd>/var/lib/xen/initrd.UQafMw</initrd> <cmdline>ro root=/dev/VolGroup00/LogVol00 rhgb quiet</cmdline> </os> <memory>512000</memory> <vcpu>1</vcpu> <on_poweroff>destroy</on_poweroff> <on_reboot>restart</on_reboot> <on_crash>restart</on_crash> <devices> <interface type='bridge'> <source bridge='xenbr0'/> <mac address='00:16:3e:49:1d:11'/> <script path='vif-bridge'/> </interface> <graphics type='vnc' port='5900'/> <console tty='/dev/pts/4'/> </devices>
the version command:
domain
virsh # version Compiled against library: libvir 0.1.7 Using library: libvir 0.1.7 Using API: Xen 3.0.1 Running hypervisor: Xen 3.0.0