apt-get install qemu-kvm virtinst virt-manager bridge-utils libosinfo-bin
apt install -y qemu qemu-kvm libvirt-daemon libvirt-clients bridge-utils virt-manager    #ubuntu 20.04
sudo adduser $USER kvm 
#apt-get install qemu-kvm libvirt-bin virtinst bridge-utils cpu-checker
sudo kvm-ok                                                                       #check      
systemctl status libvirtd.service
https://github.com/LuyaoHuang/virsh-bash-completion                               #bash completion


Set your network devices on OS level such as (example with 2 network interfaces “enp4s0” and “eno1” which is bridge slave interface for bridge “vmbr0”):

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
 version: 2
 renderer: networkd
     dhcp4: no
     dhcp6: no
     addresses: []
     mtu: 1500
       addresses: []
       search: [local]
     dhcp4: no
     dhcp6: no
     dhcp4: no
     dhcp6: no
     interfaces: [eno1]
     addresses: []
     mtu: 1500
     #  addresses: [,]
     #  stp: true
     #  forward-delay: 4


virsh list                                                       #show running vm´s
virsh list --all                                                 #show all vm´s 
virsh undefine vm1
virsh destroy vm1                                                #forcefully and immediately stop a given domain - the vm won´t be destoyed, just stopped.
virsh start vm-name
virsh autostart test                                             #
virsh reboot vm-name
virsh shutdown vm-name
virsh suspend vm-name
virsh resume vm-name
virsh domrename foo bar                                          #rename vm from foo to bar
virsh autostart vm-name
virsh autostart --disable vm-name
virsh domrename $OLD_NAME $NEW_NAME
virsh domrename --domain oldname newname                         #rename domain/ vm       
virsh edit vm-name                                               #edit vm properties
osinfo-query os                                                  #list available os when specify os by "--os-variant" - package "libosinfo-bin" is required!
virsh net-list                                                   #list running network configs
virsh net-list --all                                             #list all network configs
virsh dumpxml vm-name                                            #xml-config to stdout
virsh dumpxml master > master.xml                                #backup vm
virsh define master.xml                                          #restore vm 
virt-manager                                                     #gui to show, manage and create vm´s


virsh snapshot-list vm-name                                                 #list all snaps       
virsh snapshot-list vm-name--tree 
virsh snapshot-create-as vm-name
virsh snapshot-create-as --domain vm-name --name snap-name
virsh snapshot-create-as vm-name
virsh snapshot-create-as vm-name "snap1" --diskspec sda,file=/var/backups/snapshots/snap1-vm-name.qcow2 --disk-only --atomic
virsh snapshot-info --domain vm-name --snapshotname snap-name
virsh snapshot-revert --current vm-name
virsh snapshot-delete --current vm-name
virsh snapshot-delete --domain vm-name --snapshotname snap-name
virsh snapshot-create-as --disk-only vm-name
virsh snapshot-edit --rename  --domain vm-name --snapshotname snap-name     #rename
virsh snapshot-delete --current --metadata vm-name                          #delete "disk-snapshot"
qemu-img info --backing-chain test.qcow2
qemu-img info test.qcow2
qemu-img convert -O output_format source destination
virsh domblklist vm-name
virsh blockcommit vm-name sda --active --verbose --pivot

Change Path Of "backing file"

sudo qemu-img rebase \
  -f qcow2 \
  -u \


sudo qemu-img rebase \
  -f qcow2 \

Merge snapshot and backing file into standalone disk

cp test1-base new-master                                 #test1-base = base-disk
qemu-img rebase -b new-master test1-master-0             #snapshot="test1-master-0"
qemu-img commit test1-master-0
qemu-img commit new-master                               #output if success: "Image committed"
Image committed.
qemu-img info new-master


virsh blockcopy --domain kmaster sda \
  /data/images/backup/copy.qcow2 \
  --wait --verbose --shallow \


virsh pool-list --all                                            #show also inactice pool
virsh pool-list                                                  #show active storage pool
virsh pool-list --details                                        #show details like disk usage
virsh pool-info poolname                                         #detailed pool info
virsh pool-autostart poolame
virsh pool-start poolname
virsh pool-undefine poolname                                     #delete pool "default"
virsh pool-destroy poolname                                      #set inactive
virsh pool-edit poolname
virsh pool-define-as --name default --type dir --target /media/work/kvm
virsh pool-refresh --pool default
virsh pool-refresh --pool kvm-vm


virsh vol-list default
virsh vol-list default --details
virsh vol-list kvm-vm --details
virsh vol-delete volume-name.qcow2  --pool default
virsh vol-create-as default test_vol2.qcow2 2G
virsh vol-clone --pool default vol1.qcow2 vol2.qcow2
qemu-img resize volume-name.qcow2 30G && virsh pool-refresh --pool poolname0 #vm has to be shutdown!

Pool refesh an volume list:

virsh pool-refresh --pool poolname0
virsh pool-refresh --pool poolname1
virsh vol-list poolname0 --details
virsh vol-list poolname1 --details

clone domain/ vm

Simple Guest Clone

#author:  Thomas Roehm
#version: 1.0
echo ""
echo "Overview VM´s:"
echo ""
virsh list --all
echo ""
read -p "Please enter the name of the vm you want to clone: " SOURCEVM
echo ""
read -p "Please enter the name of the cloned vm: " DESTVM
echo ""
virt-clone \
--original $SOURCEVM \
--auto-clone \
--name $DESTVM
STATUS=$(echo $?)
echo ""
if [ $STATUS -eq 0 ]
        echo "VM \"$DESTVM\" cloned."
        echo "Problem - VM not cloned!"


journalctl -a -b -k -u libvirtd.service
systemctl status libvirtd.service
kvm/kvm.txt · Last modified: 2022/03/12 09:13 by tmade
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Noncommercial-Share Alike 4.0 International
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki