“The libvirt project is a toolkit to manage virtualization platforms”

goals:

  • manage pools
  • manage volumes
  • handle domains
  • networking
  • vmm
  • spice

core requirements

## install following packages
> pacman -S libvirt \
		virt-install \
		ebtables \
		dnsmasq \
		bridge-utils

see: wiki.libvirt.org

storage pool

## create new directory pool informations
> virsh pool-define-as pool-001 dir - - - - /var/lib/libvirt/images

## build define pool
> virsh pool-build     pool-001
> virsh pool-start     pool-001
> virsh pool-autostart pool-001

## show pool
> virsh pool-list --all

## test
> virsh vol-create-as pool-001 \
        test-001-volume 1GiB \
        --format qcow2

## remove pool
> virsh vol-delete --pool pool-001 test-001-volume

storage volume

## create volume
> virsh vol-create-as poolname volumename 10GiB --format aw|bochs|raw|qcow|qcow2|vmdk

## list volume
> virsh vol-list

## resize volume
> virsh vol-resize  --pool poolname volumename 12GiB

## delete volume
> virsh vol-delete  --pool poolname volumename

handle domains

## list maschines
> virsh list --all

## install maschine
> virt-install \
  --name foo_testing \
  --memory 1024 \
  --vcpus=2,maxvcpus=4 \
  --cpu host \
  --cdrom $HOME/foo_install.iso \
  --disk size=2,format=qcow2 \
  --network user \
  --virt-type kvm

## import volume
> virt-install \
  --name demo \
  --memory 512 \
  --disk /home/user/vm/foo.img \
  --import

## test domain
> virsh start foo_testing

## connect
> virt-viewer --connect qemu:///session foo_testing

## shutdown
> virsh shutdown foo_testing

## destroy
> virsh destroy foo_testing

## edit domain
> virsh edit foo_testing

networking - add bridge

# edit /tmp/bridge.xml
<network>
  <name>br0</name>
  <forward mode="bridge"/>
  <bridge name="br0" />
</network>

# define interface
> virsh net-define /tmp/bridge.xml

# start or autostart interface
> virsh net-start br0
> virsh net-autostart br0

test networking by using web installer

> 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

vmm requirements

## packages for vmm and spice
> pacman -S remote-viewer \
	virt-manager \
	spice-vdagent \
	xf86-video-qxl

configurations

## add user to group libvirt to access socket passwordless
> usermod -aG libvirt username

## start and enable libvirtd
> systemctl enable libvirtd && \
	systemctl start libvirtd

## enable default network
> virsh net-autostart default && \
	virsh net-start default

connect with remote-vieser like spice://localhost:5900

optional allow other groups like kvm to access socket passwordless
create /etc/polkit-1/rules.d/50-libvirt.rules and add:

/* Allow users in kvm group to manage the libvirt
daemon without authentication */
polkit.addRule(function(action, subject) {
    if (action.id == "org.libvirt.unix.manage" &&
        subject.isInGroup("kvm")) {
            return polkit.Result.YES;
    }
});

after that add user to group kvm

resize disks from 10gb to 50gb

# resize disk
> qemu-img resize \
  /var/lib/libvirt/images/debian-clone-002.qcow2 \
  +40G

# start vm
> virsh start debian11-clone-009

# resize block
> virsh blockresize \
  --domain debian11-clone-009 \
  /var/lib/libvirt/images/debian-clone-009.qcow2 \
  50G