virsh -c qemu+ssh://user@host/system lista remote host
Overview
KVM is the hypervisor built into the Linux kernel; libvirt is the
management layer on top of it, and virsh is its CLI. This stack also runs
linux-labs itself (the ephemeral lab VMs). The libvirtd daemon runs under
systemd.
bash
virsh list --all # all domains (VMs): running and stopped
virsh nodeinfo # host resources
egrep -c 'vmx|svm' /proc/cpuinfo # hardware virtualization support (>0 = present)
Connecting to a remote host: virsh -c qemu+ssh://user@host/system ....
Recipes
2
Managing VMs
bash
virsh start vm1 # start it
virsh shutdown vm1 # graceful shutdown (ACPI)
virsh destroy vm1 # hard power-off (= pulling the plug)
virsh reboot vm1
virsh console vm1 # serial console (exit: Ctrl+])
virsh dominfo vm1 # state, memory, vCPUs
virsh autostart vm1 # start automatically with the host
virsh undefine vm1 # remove the definition (the disk stays!)
Networks and storage
bash
virsh net-list --all # virtual networks
virsh net-dumpxml default # the network's XML
virsh net-start default
virsh net-autostart default
virsh pool-list # storage pools
virsh vol-list default # volumes (VM disks)
virsh domiflist vm1 # a VM's network interfaces (MAC, bridge)
virsh dumpxml vm1 # the VM's full definition (XML)
libvirtd isn't running (systemctl status libvirtd), or you lack
permissions — the user must be in the libvirt group. The system instance
needs the URI qemu:///system.
The VM won't start
virsh start vm1 prints an error; check journalctl -u libvirtd and the
log at /var/log/libvirt/qemu/vm1.log for details. Common causes: missing
disk file, a port already in use, not enough memory.
The VM has no network
The virtual network isn't running: virsh net-list --all → net-start.
Check the bridge and the firewall on the host.
Can't get into the VM
virsh console vm1 (needs serial enabled in the guest OS) — exit with
Ctrl+]. Or use SSH if the VM has networking.