Skip to content
Commitpedia
Log in Join & edit

virsh cheat sheet: everyday libvirt commands

A quick reference for virsh: list, start, stop and inspect VMs, change CPUs and memory, manage networks, storage pools and snapshots, with notes on which commands are destructive.

Edit history of virsh cheat sheet: everyday libvirt commands: 1 recorded edit
Edit history · 1 edit
Type
Article
Edits
1
Editors
1
First issued
15 Oct 2026
Last edit
15 Oct 2026
Reading
2 min

virsh is the command-line client for libvirt. In libvirt a VM is called a domain. Most commands take the domain name, ID or UUID. Run virsh help or virsh help COMMAND for the exact options in your installed version.

Connecting

virsh -c qemu:///system list --all     # system instance (servers)
virsh -c qemu:///session list --all    # your per-user instance
export LIBVIRT_DEFAULT_URI=qemu:///system
virsh uri                               # which connection am I using?
virsh nodeinfo                          # host CPU and memory summary

Listing and inspecting domains

virsh list                   # running domains
virsh list --all             # running and stopped
virsh list --all --name      # names only, good for scripts
virsh dominfo web01          # state, vCPUs, memory, autostart
virsh domstate web01 --reason
virsh domifaddr web01        # IP addresses (default source: DHCP leases)
virsh domblklist web01 --details
virsh dumpxml web01          # full XML definition

Power and lifecycle

virsh start web01
virsh shutdown web01         # asks the guest OS to shut down
virsh reboot web01
virsh suspend web01          # pause
virsh resume web01
virsh destroy web01          # immediate power-off, like pulling the plug
virsh autostart web01        # start at host boot
virsh autostart --disable web01
virsh console web01          # serial console; leave with Ctrl+]

shutdown depends on the guest reacting (ACPI or the guest agent), so it may take a while or do nothing. destroy does not delete anything, but the guest loses unsaved data, just like a power cut.

Changing configuration

virsh edit web01                            # edit XML safely in $EDITOR
virsh setvcpus web01 4 --config --maximum   # raise the maximum (next boot)
virsh setvcpus web01 4 --config
virsh setmaxmem web01 8G --config
virsh setmem web01 8G --config
virsh define web01.xml                      # register a domain from XML

--config changes the persistent definition (applies at next start); --live changes the running guest, if the guest and hypervisor support it. virsh edit is equivalent to dumpxml, editing the file and define, but it also checks the XML for errors, so prefer it over editing files under /etc/libvirt/ by hand.

Removing a domain

Warning: removing storage is permanent. First check which disks belong to the VM with virsh domblklist web01 --details, and make sure no other VM uses them.

virsh undefine web01                         # remove the definition, keep disks
virsh undefine web01 --nvram                 # needed for UEFI guests with an NVRAM file
virsh undefine web01 --snapshots-metadata    # needed if snapshots exist
virsh undefine web01 --remove-all-storage    # also deletes the VM's storage volumes

Networks

virsh net-list --all
virsh net-info default
virsh net-start default
virsh net-autostart default
virsh net-dumpxml default
virsh net-dhcp-leases default

Storage pools and volumes

virsh pool-list --all --details
virsh vol-list default
virsh vol-create-as default data01.qcow2 20G --format qcow2
virsh vol-clone web01.qcow2 web02.qcow2 --pool default
virsh attach-disk web01 /var/lib/libvirt/images/data01.qcow2 vdb --driver qemu --subdriver qcow2 --persistent

Snapshots

virsh snapshot-create-as web01 --name pre-update --description "before dnf update"
virsh snapshot-list web01
virsh snapshot-current web01 --name
virsh snapshot-revert web01 pre-update    # destructive: discards changes since the snapshot
virsh snapshot-delete web01 pre-update

Statistics

virsh domstats web01
virsh domstats --state --cpu-total --balloon
virsh dommemstat web01

Note that shutdown, setvcpus and setmem may return before the change is complete; the virsh manual points this out explicitly.

Official documentation

See also

  • 0098 What Proxmox VE is: KVM virtual machines, LXC containers and a web UI Proxmox VE is an open source virtualization platform based on Debian. It runs KVM virtual machines and LXC containers and is managed… Beginner · Concept · Linux Article Basics · Installation & first steps 15 Oct 2026
  • 0100 Create a VM and a cloud-init template with qm Create KVM virtual machines from the command line with qm, then build a reusable cloud-init template from a cloud image and clone… Intermediate · How-to · Linux Article Basics · VMs & containers 15 Oct 2026
  • 0123 KVM vs QEMU vs libvirt: how Linux virtualization fits together KVM is the Linux kernel part that uses CPU virtualization extensions, QEMU is the program that emulates a full machine around it,… Beginner · Concept · Linux Article Basics 15 Oct 2026
  • 0125 Create a KVM virtual machine with virt-install Use virt-install to create libvirt/KVM guests: install from an ISO, run a text-only install over the serial console, or import a cloud… Intermediate · How-to · Linux Article Basics 15 Oct 2026
  • 0126 KVM snapshots and cloning with virsh and virt-clone Take, list, revert and delete libvirt snapshots with virsh, understand internal vs external and disk-only snapshots, and clone a stopped VM with… Advanced · How-to · Linux Article Basics 15 Oct 2026
  • 0127 Fix: “Requested operation is not valid: network ‘default’ is not active” A libvirt VM will not start because the virtual network it uses, usually the NAT network 'default', is stopped. Start the network… Intermediate · Fix · Linux Article Basics 15 Oct 2026

Repos in the wild

History

Every saved edit is kept. The plot on the sleeve draws one line per edit. Open any edit to see exactly what changed.

  1. commitpedia-admin +3,848 chars

Report a problem

Something wrong, unsafe or copied? Tell the editors.
What is wrong?