KVM host & libvirt

require

grep -E --color=always 'vmx|svm| lm ' /proc/cpuinfo | uniq

install

apt install \
    bridge-utils \
    cpu-checker \
    qemu-kvm \
    qemu-system-x86
    # qemu-system
    # --no-install-recommends

lsmod | grep kvm
#rmmod kvm
#modprobe -a kvm

kvm-ok

ls -lF /dev/kvm
# crw-rw---- 1 root kvm 10, 232 May 10 05:30 /dev/kvm

[optional] libvirt

apt install \
    libguestfs-tools \
    libosinfo-bin \
    libvirt-clients \
    libvirt-daemon-system \
    virtinst

make virsh commands available to some non-root user

usermod -aG libvirt USER

ls -lF /var/run/libvirt/libvirt-sock # root:libvirt

enable the daemon

systemctl status libvirtd
systemctl status libvirt-guests

check

ps auxww | grep libvirtd$
virsh list --all
virsh nodeinfo

virt-host-validate
osinfo-query os | less
libguestfs-test-tool

nested

to enable nested virtualization e.g. to setup XEN dom0 within KVM

vi /etc/modprobe.d/kvm.conf

options kvm_amd nested=1

# doesn't show up
#options kvm_amd amd_iommu=pt

rmmod kvm_amd
modprobe kvm_amd
    modinfo kvm_amd | grep nested

cat /sys/module/kvm_amd/parameters/nested
#cat /sys/module/kvm_amd/parameters/amd_iommu

network

see host-network

additional notes

storage

assuming /data/ is an NFS mount point already, enable it as storage for vdisks and configs

virsh pool-list
virsh pool-dumpxml default > pool.xml
virsh pool-destroy default
vi pool.xml

    <path>/data/guests</path>

mkdir -p /data/guests/
virsh pool-create pool.xml
virsh pool-list

ready to go

mkdir -p /data/guests/

ifconfig virbr0

and install some guests

live-migration

to be able to talk to the other hypervisors and enable the farm, you will have to share a few SSH keys.

to migrate a guest, make sure the machine type is compatible on both ends,

kvm -M ?

and fix it (DO NOT USE the pc alias that is pointing to different latest versions depending on the hypervisors – choose the latest available on all hypervisors e.g. pc-i440fx-2.5) if required,

virsh shutdown GUESTNAME
virsh edit GUESTNAME

  <os>
    <type arch='x86_64' machine='pc-i440fx-2.5'>hvm</type>
    <boot dev='hd'/>
  </os>

the available virtual network devices can be displayed as such,

qemu-system-x86_64 -net nic,model=? /dev/null

e.g.,

qemu: Supported NIC models: ne2k_pci,i82551,i82557b,i82559er,rtl8139,e1000,pcnet,virtio

replacing rtl8139 with virtio,

    <interface type='bridge'>
      <mac address='xx:xx:xx:xx:xx:xx'/>
      <source bridge='xenbr0'/>
      <model type='virtio'/>
            <driver name='vhost' txmode='iothread' ioeventfd='on' event_idx='off' queues='5' rx_queue_size='256' tx_queue_size='256'>
              <host csum='off' gso='off' tso4='off' tso6='off' ecn='off' ufo='off' mrg_rxbuf='off'/>
              <guest csum='off' tso4='off' tso6='off' ecn='off' ufo='off'/>
            </driver>
    </interface>

you may also have to disable caching on the virtual drive,

  <driver name='qemu' type='qcow2' cache='none'/>

refs https://access.redhat.com/solutions/158363

you will then be able to live-migrate,

virsh -c qemu+ssh://ANOTHER-KVM-SRV/system list
virsh migrate GUESTNAME qemu+ssh://ANOTHER-KVM-SRV/system

Resources

install

https://help.ubuntu.com/lts/serverguide/libvirt.html

https://help.ubuntu.com/community/KVM/Installation

https://wiki.xen.org/wiki/Libvirt

https://www.cyberciti.biz/faq/installing-kvm-on-ubuntu-16-04-lts-server/

https://wiki.debian.org/KVM

https://wiki.debian.org/libvirt

https://computingforgeeks.com/virsh-commands-cheatsheet/

tuning

Tuning KVM https://www.linux-kvm.org/page/Tuning_KVM

Tuning Kernel https://www.linux-kvm.org/page/Tuning_Kernel

Memory https://www.linux-kvm.org/page/Memory

Chapter 6. Overcommitting with KVM https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/virtualization_administration_guide/chap-virtualization-tips_and_tricks-overcommitting_with_kvm

Chapter 7. KSM https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/virtualization_administration_guide/chap-KSM

How to use the Kernel Samepage Merging feature https://www.kernel.org/doc/Documentation/vm/ksm.txt

KVM host won’t use memory for caching https://serverfault.com/questions/710172/kvm-host-wont-use-memory-for-caching

Virtualization (KVM) and excessive cached RAM https://unix.stackexchange.com/questions/241142/virtualization-kvm-and-excessive-cached-ram

Kernel same-page merging https://en.wikipedia.org/wiki/Kernel_same-page_merging

virt-install

https://raymii.org/s/articles/virt-install_introduction_and_copy_paste_distro_install_commands.html#Ubuntu_14.04

nested

https://storpool.com/blog/nested-virtualization-with-kvm-and-opennebula

kvm virtio

https://wiki.gentoo.org/wiki/QEMU/Linux_guest

https://www.linux-kvm.org/page/Boot_from_virtio_block_device

https://wiki.archlinux.org/title/KVM

network

https://wiki.debian.org/LXC/LibVirtDefaultNetwork

https://wiki.debian.org/KVM#Libvirt_default_network

https://unix.stackexchange.com/questions/340521/create-virbr0-for-virsh

https://linuxconfig.org/how-to-use-bridged-networking-with-libvirt-and-kvm

storage

http://ask.xmodulo.com/change-default-location-libvirt-vm-images.html

live-migration

https://mike42.me/blog/libvirt-migrate-a-vm-from-qemusession-to-qemusystem

https://wiki.libvirt.org/page/Failed_to_connect_to_the_hypervisor

http://blog.programster.org/kvm-offline-migration

https://libvirt.org/migration.html

https://libvirt.org/formatdomain.html

https://libvirt.org/formatdomain.html#elementsNICS

https://wiki.ubuntu.com/QemuKVMMigration

https://bugs.launchpad.net/ubuntu/+source/libvirt/+bug/1617214

https://bugs.launchpad.net/ubuntu/+source/libvirt/+bug/1637438

https://www.linux-kvm.org/page/Management_Tools

https://www.linux-kvm.org/page/Networking

https://www.redhat.com/archives/libvirt-users/2015-February/msg00024.html

https://access.redhat.com/errata/RHSA-2016:2577


HOME | GUIDES | LECTURES | LAB | SMTP HEALTH | HTML5 | CONTACT
Copyright © 2024 Pierre-Philipp Braun