KVM

Install

apt-get install qemu-kvm virtinst virt-manager bridge-utils libosinfo-bin
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

Commands

virsh list                                                       #show running vm´s
virsh list --all                                                 #show all vm´s 
virsh undefine vm1
virsh destroy vm1
virsh start vm-name
virsh autostart test                                             #
virsh reboot vm-name
virsh shutdown vm-name
virsh suspend vm-name
virsh resume vm-name
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
virt-manager                                                     #gui to show, manage and create vm´s
virsh snapshot-list vm-name        
virsh snapshot-create-as vm-name
virsh snapshot-create-as --domain vm-name --name snap-name
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-delete --current --metadata vm-name               #delete "disk-snapshot"

Pool

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

Volume

virsh vol-list default
virsh vol-list default --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

clone domain/ vm

Simple Guest Clone

clone-vm.sh
#!/bin/bash
 
#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 ]
then
        echo "VM \"$DESTVM\" cloned."
else
        echo "Problem - VM not cloned!"
fi

Log

journalctl -a -b -k -u libvirtd.service
systemctl status libvirtd.service
kvm/kvm.txt · Last modified: 2020/02/26 12:41 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