Section: Virtualization Support (1)
Updated: 2007-08-14
Index Return to Main Contents


virsh - management user interface  


virsh <subcommand> [args]  


The virsh program is the main interface for managing virsh guest domains. The program can be used to create, pause, and shutdown domains. It can also be used to list current domains. Libvirt is a C toolkit to interact with the virtualization capabilities of recent versions of Linux (and other OSes). It is free software available under the GNU Lesser General Public License. Virtualization of the Linux Operating System means the ability to run multiple instances of Operating Systems concurrently on a single hardware system where the basic resources are driven by a Linux instance. The library aims at providing long term stable C API initially for Xen paravirtualization but should be able to integrate other virtualization mechanisms, it currently also supports QEmu and KVM.

The basic structure of most virsh usage is:

  virsh <command> <domain-id> [OPTIONS]

Where command is one of the commands listed below, domain-id is the numeric domain id, or the domain name (which will be internally translated to domain id), and OPTIONS are command specific options. There are a few exceptions to this rule in the cases where the command in question acts on all domains, the entire machine, or directly on the xen hypervisor. Those exceptions will be clear for each of those commands.

The virsh program can be used either to run one command at a time by giving the command as an argument on the command line, or as a shell. If no command is given in the command line, virsh will start a minimal interpreter waiting for your commands and the quit command will exit the program.  


All virsh operations rely upon the libvirt library, which passes virsh commands to xend/qemu or any of the other virtual libraries that libvirt supports. For this reason you should start xend/qemu as a service when your system first boots. This can usually be done using the command service start libvirtd.

Most virsh commands require root privileges to run due to the communications channels used to talk to the hypervisor. Running as non root will return an error.

Most virsh commands act asynchronously, so just because the virsh program returned doesn't mean the action is complete. This is important, as many operations on domains, like create and shutdown, can take considerable time (30 seconds or more) to bring the machine into a fully compliant state. If you want to know when one of these actions has finished you must poll through virsh list periodically.  


The following commands are generic i.e. not specific to a domain.
help optional command
This prints a small synopsis about all commands available for virsh. help command will print out a detailed help message on that command.
quit this interactive terminal
Will print out the major version info about what this built from.


virsh version

Compiled against library: libvirt 0.0.6

Using library: libvirt 0.0.6

Using API: Xen 3.0.0

Running hypervisor: Xen 3.0.0

connect URI optional --readonly
(Re)-Connect to the hypervisor. This is a built-in command after shell start up, and usually takes a URI parameter specifying how to connect to the hypervisor. The documentation page at <> lists the values supported but the most common are:
this is used to connect to the local Xen hypervisor, this is the default
allow to connect locally as root to the daemon supervizing QEmu and KVM domains
allow to connect locally as a normal user to the his own set of QEmu and KVM domains

The --readonly option allows for read-only connections.

Returns basic information about the node, like number and type of CPUs, and size of the physical memory.
Print an XML document describing the capabilities of the hypervisor we are currently connected to. This includes a section on the host capabilities in terms of CPU and features, and a set of descriptions for each kind of guest which can be virtualized. For a more complete description see:
list optional [ --inactive | --all ]
Prints information about one or more domains. If no domains are specified, prints out information about all active domains. --inactive will show only inactive domains, --all will show all domains.

An example format for the list is as follows:

virsh list
 Id Name                 State 


  0 Domain-0             running 
  2 fedora               paused

Name is the name of the domain. ID the domain numeric id.
 State is the run state (see below).  


The State field lists 6 states for a Xen Domain, and which ones the current Domain is in.

r - running
The domain is currently running on a CPU
b - blocked
The domain is blocked, and not running or runnable. This can be caused because the domain is waiting on IO (a traditional wait state) or has gone to sleep because there was nothing else for it to do.
p - paused
The domain has been paused, usually occurring through the administrator running xm pause. When in a paused state the domain will still consume allocated resources like memory, but will not be eligible for scheduling by the Xen hypervisor.
s - shutdown
The domain is in the process of shutting down, i.e. the guest operating system has been notified and should be in the process of stopping its operations gracefully.
c - crashed
The domain has crashed, which is always a violent ending. Usually this state can only occur if the domain has been configured not to restart on crash. See xmdomain.cfg for more info.
d - dying
The domain is in process of dying, but hasn't completely shutdown or crashed.


The following commands manipulate domains directly. As stated previously, most commands take domain-id as the first parameter. The domain-id can be specified as a short integer, a name or a full UUID.
autostart optional --disable domain-id
Configure a domain to be automatically started at boot.

The option --disable disables autostarting.

console domain-id
Connect the virtual serial console for the guest.
create FILE
Create a domain from an XML document FILE. This command starts the domain described in FILE, but does not save the domain config; the domain config will disappear altogether when the domain is shut down. The XML fed to virsh create should match the XML created by virsh dumpxml domain-id.
define FILE
Define a domain from an XML document FILE. The domain definition is created, but the domain is not started. Unlike domains started with virsh create, domain definitions created with virsh define will persist until they are undefined.
destroy domain-id
Immediately terminate the domain domain-id. This doesn't give the domain OS any chance to react, and it is the equivalent of ripping the power cord out on a physical machine. In most cases you will want to use the shutdown command instead.
dominfo domain-id
Returns basic information about the domain.
domuuid domain-name-or-id
Convert a domain name or id to domain UUID
domid domain-name
Converts a domain name to a domain id using libvirt's internal mapping.
dominfo domain-id
Returns basic information about the domain.
domname domain-id
Convert a domain id to a domain name
domstate domain-id
Returns state about a running domain.
dumpxml domain-id
Output the domain information as an XML dump to stdout. This format can be used by the create and define commands.
reboot domain-id
Reboot a domain. This acts just as if the domain had had the reboot command run from the console. The command returns as soon as it has executed the reboot action, which may be significantly before the domain actually reboots.

For a xen vm the behavior of a domain when it reboots is set by the on_reboot parameter in the domain XML.

restore state-file
Restores a domain from an virsh save state file. See save for more info.
save domain-id state-file
Saves a running domain to a state file so that it can be restored later. Once saved, the domain will no longer be running on the system, so the memory allocated for the domain will be free for other domains to use. virsh restore restores from this state file.

This is roughly equivalent to doing a hibernate on a running computer, with all the same limitations. Open network connections may be severed upon restore, as TCP timeouts may have expired.

setmem domain-id kilobytes
Change the current memory allocation in the guest domain. This should take effect immediately. The memory limit is specified in kilobytes.
setmaxmem domain-id kilobytes
Change the maximum memory allocation limit in the guest domain. This will not change the domain's current memory usage. The memory limit is specified in kilobytes.
setvcpus domain-id count
Change the number of virtual CPUs active in the guest domain. Note that count may be limited by the host, the hypervisor, or the domain's original description.
shutdown domain-id
Gracefully shuts down a domain. This coordinates with the domain OS to perform graceful shutdown, so there is no guarantee that it will succeed, and may take a variable length of time depending on what services must be shutdown in the domain.

For a xen guest vm the behavior of a domain when it reboots is set by the on_shutdown parameter of the domain XML.

suspend domain-id
Suspend a running domain. It is kept in memory but won't be scheduled anymore.
resume domain-id
Moves a domain out of the suspended state. This allows a previously suspended domain to become eligible for scheduling by the underlying hypervisor.
undefine domain-id
Undefine (destroy) the configuration for an inactive domain. Since the domain is not running the domain name or UUID must be used as the domain-id.
vcpuinfo domain-id
Returns basic information about the domain virtual CPUs, like the number of vCPUs, the running time, and the affinity to physical processors.
vcpupin domain-id vcpu cpulist
Pin domain VCPUs to host physical CPUs. The vcpu number must be provided, and cpulist must be a comma separated list of physical CPU numbers.
vncdisplay domain-id
Output the IP address and port number for the VNC display. If the information is not available the process will provide an exit code of 1.


The following commands manipulate devices associated with domains. The domain-id can be specified as an short integer, a name or a full UUID. To better understand the values allowed as options for the command reading the documentation at <> on the format of the device sections to get the most accurate set of accepted values.
attach-device domain-id FILE
Attach a device to the domain, using a device definition in an XML file. See the documentation to learn about libvirt XML format for a device.
attach-disk domain-id source target optional --driver driver --subdriver subdriver --type type --mode mode
Attach a new disk device to the domain. source and target are paths for the files and devices. driver can be file, tap or phy depending on the kind of access. type can indicate cdrom or floppy as alternative to the disk default. mode can specify the two specific mode readonly or shareable.
attach-interface domain-id type source optional --target target --mac mac --script script
Attach a new network interface to the domain. type can be either network to indicate a physical network device or bridge to indicate a bridge to a device. source indicates the source device. target allows you to indicate the target device in the guest. mac allows you to specify the MAC address of the network interface. script allows you to specify a path to a script handling a bridge instead of the default one.
detach-device domain-id FILE
Detach a device from the domain. Takes the same kind of XML description as attach-device.
detach-disk domain-id target
Detach a disk device from a domain. The target is the device as seen from the domain.
detach-interface domain-id type optional --mac mac
Detach a network interface from a domain. type can be either network to indicate a physical network device or bridge to indicate a bridge to a device. It is recommended to use the mac option to distinguish between the interfaces if more than one are present on the domain.


The following commands manipulate networks. Libvirt has the capability to define virtual networks which can then be used by domains and linked to actual network devices. For more detailed informations about this feature see the documentation at <>. A lot of the commands for virtual networks are similar to the one used for domains, but the way to name a virtual network is either by its name or UUID.
net-autostart network optional --disable
Configure a virtual network to be automatically started at boot. The --disable option disables autostarting.
net-create file
Create a virtual network from an XML file. See the documentation to get a description of the XML network format used by libvirt.
net-define file
Define a virtual network from an XML file. The network is defined but not instantiated.
net-destroy network
Destroy a given virtual network specified by its name or UUID. This takes effect immediately.
net-dumpxml network
Output the virtual network information as an XML dump to stdout.
net-list optional --inactive or --all
Returns the list of active networks. If --all is specified this will also include defined but inactive networks. If --inactive is specified only the inactive ones will be listed.
net-name network-UUID
Convert a network UUID to a network name.
net-start network
Start a (previously defined) inactive network.
net-undefine network
Undefine the configuration for an inactive network.
net-uuid network-name
Convert a network name to network UUID.


The hypervisor to connect to by default. Set this to a URI, in the same format as accepted by the connect option.


xm(1), xmdomain.cfg(5), xentop(1) , <>  


  Andrew Puch <apuch @> 
  Daniel Veillard <veillard @>

  Based on the xm man page by 
  Sean Dague <sean at dague dot net>
  Daniel Stekloff <dsteklof at us dot ibm dot com>



Bugs can be viewed on the Red Hat bugzilla site <>, under the libvirt component: <>



BUGS manual pages