docs
  • README
  • John's Notes and Documentation
    • Linux
      • Distributions
        • Arch Linux
          • Common Applications
          • Setting up pacaur with the Arch User Repository
          • Bluetooth
          • Hibernate
          • Graphical Configuration
          • libvirt
          • Post Install Tasks
            • Time
            • Reflector
            • SMTP
            • ZFS Configuration
            • smart
            • nfs
            • Package Management
              • aurutils
            • Programming Languages
              • nodejs
              • ruby
            • Restore Installed Applications
            • User Configuration Management
            • User Namespaces
            • Gaming with Wine
            • ZFS Dataset Structure
            • Raspberry PI Secure VPN Torrentbox
        • NixOS
          • Remotely Accessing Install Media
          • root on ZFS Install
      • systemd
        • Network Bonding
      • Tuning
        • CPU Tuning
        • Limits
        • Sysctls
        • Network Reliability With iwlwifi
        • Surface Pro 4 Power Tuning
        • ZFS Arc Max on Linux
      • TrueNAS
        • Setup
  • BSD
    • FreeBSD
      • iocage
      • Poudriere in a bhyve VM
    • FreeNAS
      • Copy SSH Keys off FreeNAS
      • FreeNAS Service jails
      • iocage Service jails
        • Couchpotato jail
        • Deluge jail
        • Emby jail
        • Poudriere WebUI jail
        • Podcatcher jail
        • Sabnzbd jail
        • Sickrage jail
        • Syncthing jail
        • Duplicity jail
        • Lets Encrypt jail
      • Wrong Version jail
    • pfSense
      • Sending Specific Traffic Through OpenVPN
  • Desktop and Userspace
    • Gaming
      • Grim Dawn
      • Path of Exile
    • Internet
      • Re-authenticate IRC Nickname
      • Lightdm VNC Connection with Password
    • Media
      • Convert Audio to Video
      • Convert Text to Speech
  • System Administration
    • Security
      • GPG Subkeys
    • Shell Scripting
      • dd
      • find
      • rsync
      • vim
    • ZFS
      • Mirrors
  • Certifications
    • CKA
      • Core-Concepts
      • Scheduling
      • Logging
      • Application Lifecycle Management
      • Cluster Maintenance
      • Security
      • Storage
      • Networking
      • Install Kubernetes with kubeadm
      • JSON PATH
Powered by GitBook
On this page
  • Libvirt ZFS Dataset
  • Kernel
  • ZVOL Backing Store
  • Setup
  • Create ZVOL
  • Authentication
  • System Service
  • Connect
  • UEFI
  • User
  • Create Guest
  • Storage
  • ZVOL Persistance
  • VirtIO
  • Network
  1. John's Notes and Documentation
  2. Linux
  3. Distributions
  4. Arch Linux

libvirt

PreviousGraphical ConfigurationNextPost Install Tasks

Last updated 5 months ago

Setup .

Libvirt ZFS Dataset

To keep my libvirt setup outside of any boot environments I give them their own dataset.

zfs create -o mountpoint=legacy vault/sys/chin/var/lib/libvirt
mkdir /var/lib/libvirt
mount -t zfs vault/sys/chin/var/lib/libvirt /var/lib/libvirt

Add to fstab

nano /etc/fstab
vault/sys/chin/var/lib/libvirt            /var/lib/libvirt                    zfs       rw,relatime,xattr,noacl     0 0

Kernel

Check modules are loaded.

lsmod | grep kvm
lsmod | grep virtio

If blank, .

echo "virtio" > /etc/modules-load.d/virtio.conf

Install the dependencies.

  • KVM/QEMU

  • Network

    • Nat/DHCP

    • bridged networking

  • UEFI

  • Frontends

pacman -S libvirt qemu-headless ebtables dnsmasq bridge-utils virt-manager virt-viewer ovmf

ZVOL Backing Store

I like to use ZFS ZVOL's as my backing store.

Setup

Create a dataset for ZVOLs:

zfs create -o mountpoint=none vault/zvols

User ZVOLs

Create a dataset for user 'john''s ZVOLs

zfs create -o mountpoint=none vault/zvols/john
zfs allow john create,mount,mountpoint,snapshot vault/zvols/john

Create ZVOL

To let guest do its own caching, use:

  • primarycache=metadata

Create ZVOL for a new VM. Replace with name. Volumes still need to be created by root.

zfs create -o mountpoint=none vault/zvols/john/libvirt
zfs create -V 50G vault/zvols/john/libvirt/<new VM> -o primarycache=metadata -o compression=on

Authentication

If you want passwordless authentication, as of libvirt 1.2.16, anyone in the libvirt group can access to the RW daemon socket by default.

Create the group if it doesn't exist.

groupadd libvirt

Add any users required to it.

gpasswd -a john libvirt

Make sure to re-login after.

System Service

Enable libvirtd.service.

systemctl enable --now libvirtd

To run only a user-session the daemon does not need to be enabled.

Connect

Test libvirt system-session:

virsh -c qemu:///system

Test libvirt system user-session:

virsh -c qemu:///session

UEFI

Add the following to /etc/libvirt/qemu.conf.

nano /etc/libvirt/qemu.conf
nvram = [
    "/usr/share/ovmf/ovmf_code_x64.bin:/usr/share/ovmf/ovmf_vars_x64.bin"
]

I have found UEFI may not work if I haven't set the system user to user = root in /etc/libvirt/qemu.conf.

and restart libvirtd

systemctl restart libvirtd

User

To use uefi as a user, note networking options are limited, move the nvram to a user readable location and add it to ~/.config/libvirt/qemu.conf.

cp -r /usr/share/ovmf /home/john/.config/libvirt/ovmf
chown -R john:john /home/john/.config/libvirt/ovmf

Add the following to /etc/libvirt/qemu.conf.

nano ~/.config/libvirt/qemu.conf
nvram = [
    "/home/john/.config/libvirt/ovmf/ovmf_code_x64.bin:/home/john/.config/libvirt/ovmf/ovmf_vars_x64.bin"
]

Create Guest

Use virsh or virt manager.

Storage

Select virtIO Network and storage for best performance. Select ZVOL raw device. Mine was /dev/vault/zvols/john/libvirt/<new VM>.

ZVOL Persistance

If using a user session the block device might need to be changed to be owned by the user running the VM.

# /etc/udev/rules.d/99-local-zvol.rules
# Give persistant ownership of ZVOL to user
KERNEL=="zd*" SUBSYSTEM=="block" ACTION=="add|change" PROGRAM="/lib/udev/zvol_id /dev/%k"
RESULT=="vault/zvols/john/libvirt/win" OWNER="john" GROUP="john" MODE="0750"

Refresh the rules with udevadm control --reload

VirtIO

Install drivers:

At the "Where do you want to install Windows?" screen, select the option Load Drivers, uncheck the box for "Hide drivers that aren't compatible with this computer's hardware".

Browse to the wanted driver(s) at:

SCSI: "viostor\w10\amd64" Networking: "NetKVM\w10\amd64"

Network

To use another interface, don't configure anything on the host and select macvtap passthrough, and select the interface.

Install then reboot.

As of ZFS delegation using zfs allow works on linux. Delegate permissions giving the abiity to snapshot and create datasets.

By default, anybody in the wheel group can authenticate with polkit as defined in /etc/polkit-1/rules.d/50-default.rules (see ).

Temporarily the device can be chown'd, but the owner will not live through reboot. For persistence by creating a new file 99-local-zvol.rules in /etc/udev/rules.d/ that contains the following (replacing the ZVOL path and user):

I ISO and attached the drivers pre-install.

libvirt
load them explicitly
libvirt
qemu-headless
ebtables
dnsmasq
bridge-utils
ovmf
virt-manager
virt-viewer
zfsonlinux 0.7.0
Polkit#Administrator identities
add a udev rule
downloaded