Specifications
Managing Virtual Machines with
virsh
You can use the virsh application to manage virtual machines. This utility is built around the
libvirt management API and operates as an alternative to the xm tool or the graphical Virtual
Machine Manager. Unprivileged users can employ this utility for read-only operations. If you
plan on running xend/qemu, you should enable xend/qemu to run as a service. After modifying
the respective configuration file, reboot the system, and xend/qemu will run as a service. You
can use virsh to script vm work. Like the xm tool, you run virsh from the command line.
1. Connecting to a Hypervisor
You can use virsh to initiate a hypervisor session:
virsh connect <name>
Where <name> is the machine name of the hypervisor. If you want to initiate a read—only
connection, append the above command with —readonly.
2. Creating a Virtual Machine
You can make a new virtual machine session from an XML machine definition. If you have a
pre-existing guest that you created previously with the xm tool, you can also create a virtual
machine for it:
virsh create <path to XML configuration file>
3. Configuring an XML Dump
You can use virsh to perform a data dump for an existing virtual machine.
virsh dumpxml [domain-id | domain-name | domain-uuid]
This command outputs the domain information (in XML) to stdout . If you save the data to a
file, you can use the create option to recreate the virtual machine.
4. Suspending a Virtual Machine
You can use virsh to suspend a domain:
Chapter 15.
29