KVM Cheatsheet

Feb 10, 2020

Description Command
List all running VMs virsh list
List all VMs virsh list --all
List autostarting VMs virsh list --autostart
Returns basic information about VM virsh dominfo vm01
Output the IP address and port number for the VNC display virsh vncdisplay vm01
Edit the XML configuration file for a VM (XML files from /etc/libvirt/qemu) virsh edit vm01
Output the domain information as an XML dump to stdout virsh dumpxml vm01
Find out VNC port virsh dumpxml vm01 | grep vnc
List the number of vCPUs, the running time, the affinity to physical processors virsh vcpuinfo vm01
List number and type of CPU, and size of the physical memory virsh nodeinfo
Start a inactive VM virsh start vm01
Gracefully shuts down a VM virsh shutdown vm01
Reboot a VM virsh reboot vm01
Set a VM to start automatically on system startup virsh autostart vm01
Disable autostart for VM virsh autostart --disable vm01
Immediately terminate the VM (does not delete any storage volumes used by the guest) virsh destroy vm01
Suspend a running VM (the VM is still in memory) virsh suspend vm01
Moves a VM of the suspended state virsh resume vm01
Connect the virtual serial console for the guest virsh console vm01
Define a domain (create a new VM based on a XML file) virsh define /etc/libvirt/qemu/vm01.xml
Undefine a domain (only the XML config file is deleted) virsh undefine vm01
Print an XML document describing the capabilities of the hypervisor virsh capabilities
Print a brief information of all block devices associated with domain virsh domblklist vm01
Give information about the disk image filename qemu-img info /var/lib/libvirt/images/vm01.qcow2
Resize disk from 10 GB to 20 GB for a VM (online operation) virsh blockresize vm01 /var/lib/libvirt/images/vm01.qcow2 20G
Create a snapshot (creation timestamp by default) virsh snapshot-create vm01
Create a snapshot with a specific name virsh snapshot-create-as vm01 --name snapshot.b4.patching
List snapshots for a VM virsh snapshot-list vm01
Display informations for a snapshot virsh snapshot-info --domain vm01 snapshot.b4.patching
Restore a snapshot virsh snapshot-revert vm01 snapshot.b4.patching
Delete a snapshot virsh snapshot-delete --domain vm01 --snapshotname snapshot.b4.patching
Detach a disk virsh detach-disk --domain vm01 --persistent --live --target vdb
Edit a VM with a different editor (vi editor by default) EDITOR=nano virsh edit vm01
List all volumes from a pool virsh vol-list default
Delete a volume virsh vol-delete --pool default vm01.qcow2
Refresh the pool virsh pool-refresh default
Perform a consistency check on the disk image filename qemu-img check /var/lib/libvirt/images/vm01.qcow2
List files in a virtual machine virt-ls -l -d vm01 /etc
Display a file in a virtual machine virt-cat -d vm01 /etc/fstab
Edit a file in a virtual machine (shut down before you use this command) virt-edit -d vm01 /etc/fstab
Display disk usage virt-df -h -d vm01
List filesystems virt-filesystems -l -h -d vm01
List partitions virt-filesystems -l -h --partitions -d vm01
Display /var/log/message file virt-log -d vm01 | less
Display CPU usage virt-top

Important files and directories

  • Default locations for VMs: /var/lib/libvirt/images
  • Location of XML files: /etc/libvirt/qemu
  • Location of log files: /var/log/libvirt/qemu


  • Shutdown all running VMs:
# for i in `virsh list | grep running | awk '{print $2}'`; do virsh shutdown $i; done
  • Delete the VM, remove the configuration and file:
# virsh shutdown vm01
# virsh undefine vm01
# virsh vol-delete --pool default vm01.qcow2
  • Clone a VM:
# virsh shutdown vm01
# virt-clone --original vm01 --name vm01-clone --file vm01-clone.qcow2
  • Increase memory (from 1 to 2 GB):
# virsh dominfo vm01
# virsh shutdown vm01
# virsh setmaxmem vm01 2048 --config
# virsh setmem vm01 2048 --config
# virsh dominfo vm01
# virsh start vm01
  • Increase CPU (from 1 to 2 CPUs):
# virsh dominfo vm01
# virsh shutdown vm01
# virsh setvcpus --domain vm01 --maximum 2 --config
# virsh setvcpus --domain vm01 --count 2 --config
# virsh dominfo vm01
# virsh start vm01

How to Install KVM on RHEL 7

How to fix "File too large" error

comments powered by Disqus