Virsh, the framewok of Hell

This post is just a memento

The commands I use the most at the moment:

sudo virsh
virsh -c qemu+ssh://USER@HOST/system
ex: virsh -c qemu+ssh://superuser@owly.arch-libertas.net/system

Useful to connect to the hypervisor without having to do an ssh and then do a sudo.

In a previous post I said that I rarely use CLI for my VMs, it’s true, but sometimes it’s easier.

List which VMs are running:

list --state-running 
 ID   Nom                 État
------------------------------------------------
 1    centos8-Test1       en cours d’exécution
 2    centos8-Test2       en cours d’exécution
 3    centos8-Test-DHCP   en cours d’exécution

Or any machine:

list --all 
 ID   Nom                    État
---------------------------------------------------
 1    centos8-Test1          en cours d’exécution
 2    centos8-Test2          en cours d’exécution
 3    centos8-Test-DHCP      en cours d’exécution
 -    centos1                fermé
 -    centos2                fermé
 -    debianAnsible          fermé
 -    fedora33               fermé
 -    openbsd6.7Ansible      fermé
 -    openbsd6.8DHCP         fermé
 -    openbsd_Bind_Arasaka   fermé
 -    pfsense                fermé
 -    Spinrite               fermé

See which IPs are assigned to which VM:

domifaddr --domain centos8-Test-DHCP 
 Nom        adresse MAC          Protocol     Address
-------------------------------------------------------------------------------
 vnet4      52:54:00:c5:19:b8    ipv4         192.168.122.108/24

domifaddr --domain openbsdMail 
 Nom        adresse MAC          Protocol     Address
-------------------------------------------------------------------------------
 vnet1      52:54:00:74:ef:df    ipv4         192.168.122.181/24

You can see the mounted drives:

domblkinfo --domain centos8-Test-DHCP --all 
 Target   Capacité     Allocation   Physical
------------------------------------------------
 vda      8589934592   1901666304   1901527040
 sda      -            -            -

domblkinfo --domain openbsdMail --all
 Target   Capacité      Allocation    Physical
---------------------------------------------------
 vda      21474836480   21478375424   21478375424
 vdb      26843545600   14081318912   26847870976
 vdc      2147483648    573612032     2148073472
 hda      -             -             -

Full of states like memory or cpu, vcpu etc…

dommemstat --domain centos8-Test-DHCP
actual 2097152
swap_in 0
swap_out 0
major_fault 267
minor_fault 136129
unused 1697212
available 1872968
usable 1654292
last_update 1604848057
disk_caches 60280
hugetlb_pgalloc 0
hugetlb_pgfail 0
rss 788304

domstats --domain centos8-Test-DHCP
Domain: 'centos8-Test-DHCP'
  state.state=1
  state.reason=1
  cpu.time=66610156000
  cpu.user=16893223000
  cpu.system=49716932000
  cpu.cache.monitor.count=0
  balloon.current=2097152
  balloon.maximum=2097152
  balloon.swap_in=0
  balloon.swap_out=0
  balloon.major_fault=267
  balloon.minor_fault=136129
  balloon.unused=1697212
  balloon.available=1872968
  balloon.usable=1654292
  balloon.last-update=1604848057
  balloon.disk_caches=60280
  balloon.hugetlb_pgalloc=0
  balloon.hugetlb_pgfail=0
  balloon.rss=788304
  vcpu.current=2
  vcpu.maximum=2
  vcpu.0.state=1
  vcpu.0.time=36560000000
  vcpu.0.wait=0
  vcpu.1.state=1
  vcpu.1.time=23290000000
  vcpu.1.wait=0
  net.count=2
  net.0.name=vnet4
  net.0.rx.bytes=149548
  net.0.rx.pkts=2026
  net.0.rx.errs=0
  net.0.rx.drop=0
  net.0.tx.bytes=31271
  net.0.tx.pkts=384
  net.0.tx.errs=0
  net.0.tx.drop=0
  net.1.name=vnet5
  net.1.rx.bytes=155848
  net.1.rx.pkts=1927
  net.1.rx.errs=0
  net.1.rx.drop=0
  net.1.tx.bytes=2334
  net.1.tx.pkts=33
  net.1.tx.errs=0
  net.1.tx.drop=0
  block.count=2
  block.0.name=vda
  block.0.path=/var/lib/libvirt/images/centos8-Test-DHCP.qcow2
  block.0.backingIndex=2
  block.0.rd.reqs=14473
  block.0.rd.bytes=507012608
  block.0.rd.times=275833879491
  block.0.wr.reqs=1147
  block.0.wr.bytes=73890304
  block.0.wr.times=27870685843
  block.0.fl.reqs=264
  block.0.fl.times=18803373300
  block.0.allocation=1842855936
  block.0.capacity=8589934592
  block.0.physical=1901666304
  block.1.name=sda
  block.1.rd.reqs=38
  block.1.rd.bytes=844
  block.1.rd.times=139869
  block.1.wr.reqs=0
  block.1.wr.bytes=0
  block.1.wr.times=0
  block.1.fl.reqs=0
  block.1.fl.times=0

In short, with dom[something] we have a lot of information on the domain, so the VM. What else do we have?

hostname 
lapdancetop-home

hostname 
Owly.arch-libertas.net

Convenient to know on which machine you are on.

Start up, switch off gently, cut the power like a savage hellish brute.

start fedora33 
Domaine fedora33 démarré

domstate --domain fedora33 
en cours d’exécution

shutdown fedora33 
Le domaine fedora33 est en cours d’arrêt

destroy fedora33 
Domaine fedora33 détruit

domstate --domain fedora33 
fermé

Delete a VM

undefine VMname

Playing with snapshots:

snapshot-create-as --name TestSnap --domain centos8-Test-DHCP 
L'instantané du domaine TestSnap a été créé

snapshot-list --domain centos8-Test-DHCP 
 Nom        Creation Time               État
-------------------------------------------------
 TestSnap   2020-11-08 15:28:43 +0000   running

snapshot-create-as --name TestSnap2 --domain centos8-Test-DHCP 
L'instantané du domaine TestSnap2 a été créé

snapshot-list --domain centos8-Test-DHCP 
 Nom         Creation Time               État
--------------------------------------------------
 TestSnap    2020-11-08 15:28:43 +0000   running
 TestSnap2   2020-11-08 15:30:25 +0000   running

snapshot-delete --domain centos8-Test-DHCP --current 
Domain snapshot TestSnap2 deleted

snapshot-list --domain centos8-Test-DHCP 
 Nom        Creation Time               État
-------------------------------------------------
 TestSnap   2020-11-08 15:28:43 +0000   running

And the coolest thing, the migration, sending live, without stopping the VM from a host to another one 🙂 on the other hand after a few hours of pain, I still can’t get it to work because the CPUs between the transmitter and the receiver are different 🙁

migrate --live --copy-storage-all --unsafe --domain centos8-Test1-clone-Migration --desturi qemu+ssh://superusername@192.168.178.29/system tcp://192.168.178.29
superusername@192.168.178.29's password: 
erreur :opération échouée : guest CPU doesn't match specification: missing features: fma,movbe,bmi1,avx2,bmi2,invpcid,pdpe1gb,abm

But I will keep looking to use this option with different hardware 😀