virsh is a powerful command-line tool included in libvirt that allows you to manage virtual machines and associated resources in KVM.
Through virsh, you can create, start, stop, modify, and monitor domains (virtual machines), as well as manage networks, volumes, and storage pools.


1. Domain (Virtual Machine) Management

CommandDescription
virsh list --allLists all virtual machines, both active and inactive.
virsh start vm_nameStarts a previously defined virtual machine.
virsh shutdown vm_nameShuts down a virtual machine gracefully.
virsh destroy vm_nameStops a virtual machine immediately (similar to forcefully powering it off).
virsh suspend vm_nameSuspends the execution of a virtual machine.
virsh resume vm_nameResumes a suspended machine.
virsh reboot vm_nameReboots the virtual machine.
virsh reset vm_nameResets a virtual machine as if the physical reset button was pressed.
virsh autostart vm_nameEnables automatic startup of the VM when the host boots.
virsh dominfo vm_nameShows detailed information about the VM (state, UUID, CPU, memory, etc.).
virsh dumpxml vm_nameShows the complete XML definition of the VM.
virsh edit vm_nameOpens the VM’s XML definition in an editor for modification.
virsh undefine vm_nameRemoves the VM definition without deleting its disk.
virsh domrename old_name new_nameChanges the name of a virtual machine.

2. Information and Monitoring

CommandDescription
virsh domstate vm_nameShows the current state of a VM (running, shut off, etc.).
virsh domstats vm_nameShows real-time CPU, network, and disk statistics.
virsh domblklist vm_nameLists block devices (disks) associated with a VM.
virsh domblkinfo vm_name vdaShows detailed information about a virtual disk.
virsh domiflist vm_nameShows network interfaces connected to the VM.
virsh domifaddr vm_nameShows IP addresses assigned to the VM’s network interfaces.
virsh cpu-stats vm_nameShows detailed CPU usage statistics for the VM.
virsh dommemstat vm_nameShows memory usage statistics for a VM.
virsh console vm_nameConnects to the virtual machine’s text console.
virsh vncdisplay vm_nameShows the VNC port assigned to the VM for graphical access.

3. Storage

CommandDescription
virsh pool-listLists all storage pools.
virsh pool-info pool_nameShows detailed information about a pool.
virsh pool-start pool_nameStarts a storage pool.
virsh pool-destroy pool_nameStops a storage pool.
virsh pool-undefine pool_nameRemoves the pool definition.
virsh vol-list pool_nameLists volumes (disks) within a pool.
virsh vol-info --pool pool_name vol_nameShows information about a volume.
virsh vol-create-as pool_name vol_name 20G --format qcow2Creates a new 20 GB volume in QCOW2 format.
virsh vol-delete --pool pool_name vol_nameDeletes a volume from a pool.
virsh vol-clone --pool pool_name source_vol new_volClones an existing volume.

4. Virtual Networks

CommandDescription
virsh net-list --allLists all virtual networks, both active and inactive.
virsh net-info net_nameShows detailed information about a network.
virsh net-start net_nameStarts a virtual network.
virsh net-destroy net_nameStops a virtual network.
virsh net-autostart net_nameEnables automatic startup of a network.
virsh net-edit net_nameEdits the XML configuration of a network.
virsh net-dumpxml net_nameShows the XML definition of a network.
virsh net-update net_nameUpdates network parameters without needing to restart it.
virsh net-dhcp-leases net_nameShows IP addresses delivered by DHCP on a network.

5. Snapshots and Backups

CommandDescription
virsh snapshot-list vm_nameLists available snapshots for a VM.
virsh snapshot-create-as vm_name snapshot_name "Description"Creates a snapshot with name and description.
virsh snapshot-revert vm_name snapshot_nameReverts the VM to the state saved in a snapshot.
virsh snapshot-delete vm_name snapshot_nameDeletes a specific snapshot.
virsh backup-begin vm_name --target /backup/Initiates a backup of the VM’s disks.
virsh backup-dumpxml vm_nameShows XML information about an ongoing backup task.

6. Migration and State Saving

CommandDescription
virsh save vm_name /ruta/estado.saveSaves the current state of a VM to a file.
virsh restore /ruta/estado.saveRestores a VM from a saved file.
virsh migrate --live vm_name qemu+ssh://host_destino/systemMigrates a running VM to another host via SSH.

7. Host and Hypervisor Information

CommandDescription
virsh nodeinfoShows information about the host’s CPU, memory, and architecture.
virsh capabilitiesShows the hypervisor’s capabilities (CPU, virtualization, etc.).
virsh domcapabilitiesShows capabilities supported by VMs.
virsh versionShows the version of libvirt and the hypervisor.
virsh hostnameShows the hostname running libvirt.
virsh uriShows the connection URI to the hypervisor.

8. Additional Tips

  • To run commands without privileges, you can use --connect qemu:///session or adding your user to the group kvm and libvirt.
  • If managing system VMs, use sudo virsh --connect qemu:///system.
  • Use virsh help <section> to see all available commands in a group (for example, virsh help domain).
  • All changes made via virsh edit are saved directly to the configuration XML files in /etc/libvirt/qemu/.