title: libvirt & KVM breadcrumbs:
libvirt is a tool for managing platform virtualization like KVM and QEMU (among others). I'll only focus on using it with KVM (and QEMU) here.
apt-get install --no-install-recommends iptables bridge-utils qemu-system qemu-utils libvirt-clients libvirt-daemon-system virtinst libosinfo-bin
dnsmasq-base
for accessing guests using their hostnames.libvirt
group to allow them to manage libvirt without sudo. Otherwise, remember to always specify use sudo to use the correct context/system URI/whatever.virsh net-edit default
<dns enable='no'/>
.<dhcp>...</dhcp>
.virsh net-start default
virsh net-autostart default
virsh pool-define-as default --type=dir --target=/var/lib/libvirt/images
virsh pool-start default
virsh pool-autostart default
LIBVIRT_DEFAULT_URI=qemu:///system
to explicitly use the system URI (rarely needed).virsh version
virsh list --all
virsh dominfo <vm>
virsh {start | shutdown | reboot | kill} <vm>
virsh {suspend | resume} <vm>
virsh console <vm>
Ctrl+]
(US) or Ctrl+¨
(NO)virt-install --name=example-vm --os-variant=debian10 --ram=$((1*1024)) --vcpus=1 --disk=path=/var/lib/libvirt/images/example-vm.qcow2,bus=virtio,size=5 --network=network=default,model=virtio --graphics=none --extra-args="console=ttyS0" --location=debian-10.7.0-amd64-netinst.iso
osinfo-query os
--check=all=off
.--network=bridge=something
instead of --network=network=something
.--noautoconsole
to avoid that.--location
, use --cdrom
instead. This disallows using arguments like --extra-args
, so you'll need to find another console.--cdrom
and no console is allocated), replace --graphics=none
with --noautoconsole --graphics=vnc,password=<password>
. It only binds to localhost by default, so use something like SSH port forwarding (ssh -L 5900:127.0.0.1:5900 <user>@<addr>
) to access it remotely. Remember to disable it in the VM config when no longer needed.virt-clone --original=<source-vm> --name=<vm> -f <vm>.qcow2
virsh undefine <vm>
virsh autostart [--disable] <vm>
virsh edit <vm>
virsh dumpxml <vm>
virsh domdisplay <vm>
qemu-monitor-command <vm> --hmp <command>
/var/log/libvirt/qemu/
.virbr0
, called default
in libvirt.virsh net-list
virsh net-dumpxml <network>
virsh net-edit <network>
virsh pool-list [--all] [--details]
virsh list-vol <pool> [--details]
virsh vol-info <file>
qemu-img resize <file> <size-change>
(e.g. +1G)/var/lib/libvirt/images/
./etc/libvirt/qemu/
.virsh snapshot-list <vm>
virsh snapshot-info --domain=<vm> [--current]
virsh snapshot-create-as --domain=<vm> --name=<snapshot> --description=<description>
virsh snapshot-revert {--domain=<vm> | --current} --snapshotname=<snapshot> [--running]
guestfish
.{% include footer.md %}