Libvirtd Hypervisor

Network Interface

# as root run
> virsh net-autostart --network default --disable

> brctl addbr br0
> brctl addif br0 enp3s0

> nmcli con add ifname br0 type bridge con-name br0
> nmcli con add type bridge-slave ifname enp3s0 master br0
> nmcli con show
> nmcli con show --active

# restart network or reboot
#!/bin/bash
nmcli con down enp3s0
nmcli con up br0

Storage Pool

> chown -R vmadmin:vmadmin /var/lib/libvirt/images
> virsh pool-define-as pool-001 dir - - - - /var/lib/libvirt/images
> virsh pool-build     pool-001
> virsh pool-start     pool-001
> virsh pool-autostart pool-001
# test
> virsh vol-create-as pool-001 \
        test-001-volume 1GiB \
        --format qcow2
# delete
> virsh vol-delete --pool pool-001 test-001-volume

Test VM network

> virt-install \
    --name debian-023 \
    --ram 1024 \
    --disk pool=pool-001,size=10,bus=virtio,format=qcow2 \
    --vcpus 1 \
    --os-type linux \
    --os-variant debian10 \
    --network bridge=br0 \
    --graphics none \
    --location http://deb.debian.org/debian/dists/bullseye/main/installer-amd64 \
    --extra-args 'console=ttyS0,115200n8 serial' \
    --console pty,target_type=serial \
    --force --debug

Import Proxmox Images

> zstd -d vzdump-qemu-5048-2020_12_04-15_20_53.vma.zst
> vma extract -v vzdump-qemu-5048-2020_12_04-15_20_53.vma ../newfolder-not-created
disk-drive-scsi0.raw  qemu-server.conf
> qemu-img convert -O qcow2 disk-drive-scsi0.raw disk-drive-scsi0.qcow2
> zstd disk-drive-scsi0.qcow2

Using Serial Console

> mkdir TMP
> guestmount -d imported-odoo -i TMP
> TMP/etc/default/grub
...
GRUB_CMDLINE_LINUX=""
...
GRUB_CMDLINE_LINUX='console=tty0 console=ttyS0,19200n8'
GRUB_TERMINAL=serial
GRUB_SERIAL_COMMAND="serial --speed=19200 --unit=0 --word=8 --parity=no --stop=1"

> guestunmount TMP
> guestfish -a disk-drive-scsi0.qcow2 run \
: mount /dev/sda1 / \
: command "update-grub

Run Image

> virt-install \
    --name imported-odoo \
    --memory 2048 \
    --vcpus 2 \
    --disk disk-drive-scsi0.qcow2,bus=virtio \
    --import \
    --os-variant debian10 \
    --network bridge=virbr0,model=virtio \
    --noautoconsole \
    --console pty,target_type=serial

Alpine VM

> wget https://nl.alpinelinux.org/alpine/v3.5/releases/x86_64/alpine-virt-3.5.2-x86_64.iso

> virt-install \
   	--virt-type kvm	\
   	--name alpine	  \
   	--memory 1024	 \
   	--disk size=10	 \
   	--noautoconsole	 \
   	--cdrom alpine-virt-3.5.2-x86_64.iso	 \
   	--network bridge=virbr0,model=virtio

> virsh console --domain alpine

Debian VM

> virt-install \
    --name debian-023 \
    --ram 1024 \
    --disk pool=default,size=100,bus=virtio,format=qcow2 \
    --vcpus 1 \
    --os-type linux \
    --os-variant archlinux \
    --network bridge=virbr0,model=virtio \
    --graphics none \
    --location http://deb.debian.org/debian/dists/bullseye/main/installer-amd64 \
    --extra-args 'console=ttyS0,115200n8 serial' \
    --console pty,target_type=serial \
    --force --debug

Snapshots

# live
> virsh snapshot-create-as --domain ho-hassos-03 \
  --name "test-snapshot" \
  --description "Snapshot" \
  --live
>> error: Operation not supported: live snapshot creation is supported only during full system snapshots

> virsh domblklist ho-hassos-03
...
Target   Source
------------------------------------------------------
 vda      /var/lib/libvirt/images/haos_ova-6.6.qcow2

# use "disk-only"
> virsh snapshot-create-as --domain ho-hassos-03 \
  --name "test-snapshot" \
  --description "Snapshot" \
  --disk-only
...
Domain snapshot test-snapshot created

> virsh snapshot-list ho-hassos-03
...
 Name            Creation Time               State
------------------------------------------------------------
 test-snapshot   2021-11-22 19:38:37 +0100   disk-snapshot

> virsh snapshot-info ho-hassos-03 --current
...
Name:           test-snapshot
Domain:         ho-hassos-03
Current:        yes
State:          disk-snapshot
Location:       external
Parent:         -
Children:       0
Descendants:    0
Metadata:       yes

Resize Images

> qemu-img resize \
  /var/lib/libvirt/images/almalinux8.qcow2 +10G
# start vm
# add correct size
> virsh blockresize \
  --domain almalinux8 /var/lib/libvirt/images/almalinux8.qcow2 20G