Skip to content

About

Unofficial port of libvirt to Windows: virsh, the daemons, QEMU guests with WHPX, virtual networks

Topics

Resources

Contributing

Stars

2 stars

Watchers

0 watching

Forks

Latest commit

 

History

44 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libvirt for Windows (unofficial port)

build

Français · Site

libvirt 12.9.0 built natively for Windows x64: virsh, the daemons (virtqemud, virtnetworkd, virtsecretd, libvirtd…) and QEMU guests accelerated by the Windows Hypervisor Platform (WHPX). This is libvirt's own code with its platform layers ported, not a rewrite: the same API, domain and network XML, virsh commands and RPC protocol.

Important

Not an official libvirt release, and not affiliated with the libvirt project. The Windows changes were written with an AI assistant; libvirt declines contributions that include AI-generated content (docs/hacking.rst), so nothing here is to be submitted upstream. Experimental software: try it on machines you can afford to break.

The history shows the port as a diff: the first commit is libvirt as downloaded, the second one is the Windows port.

Status

Tested on Windows 11 (build 26300) with Ubuntu 24.04 guests; TAP and Wintun (below) in a Windows 11 26300 virtual machine with Alpine guests.

Area Works and tested Not done or not tested
Daemons libvirtd and the modular daemons, --daemon, reload and stop (signals as named events), reconnection to running guests after a restart Windows services
Remote UNIX sockets; TLS (qemu+tls://, with virtproxyd or libvirtd); ssh (with the ssh of Windows or of MSYS2), libssh, libssh2 and ext transports
Secrets define, set, get, undefine, persistence
QEMU whpx domain type; define, start, destroy, suspend, resume; screenshot; qemu-monitor-command; virsh console (serial on a UNIX socket); NIC hotplug; setmem (balloon, memory given back to the host with the QEMU patch); dommemstat; save, restore, managedsave, dump; live migration (direct and --p2p, between two libvirt instances, also with --copy-storage-all), snapshots (internal and external, with or without memory, revert, delete), all with the QEMU patch; virsh sysinfo, <smbios mode='host'/> and <sysinfo>, the host UUID from SMBIOS
Guest networking type='user' (libslirp); type='network' and type='bridge' to a libvirt network; type='ethernet' on a TAP-Windows adapter (created, named, addressed and deleted by libvirt; domifstat), or an existing one with managed='no'; type='bridge' and <forward mode='bridge'/> networks on a network bridge of Windows (the host's LAN)
Virtual networks forward mode nat and isolated; DHCP and DHCPv6 (ranges, hosts by MAC, DUID or name); DNS (hosts, TXT, SRV, PTR, forwarders, local domain); IPv6 (SLAAC or DHCPv6); net-update; net-dhcp-leases; domifaddr; autostart; QoS (domiftune, floors, network bandwidth); domifstat; forward modes route and open (Wintun)
Storage pools of type dir: define, build, start, refresh, autostart; netfs (SMB shares; NFS 3 and 4 through libvirt_nfsmount (libnfs and WinFsp, which must be installed; without WinFsp, the Client for NFS of Windows, not tested); find-storage-pool-sources lists the shares of a host) and fs (a volume mounted on the target directory; pool-build --overwrite formats it), with administrator rights (or the developer mode of Windows for netfs); volumes (raw, qcow2 with qemu-img): create, clone, resize, upload, download, wipe, delete; disks of --copy-storage-all made in the destination's pool LVM, iSCSI, disk, multipath, RBD, Gluster, ZFS pools: no Windows counterpart done
Node devices nodedev-list (and --tree), nodedev-dumpxml: the computer (SMBIOS), PCI devices, USB devices, network interfaces (link state and speed), disks; host nodeinfo, nodecpustats, nodecpumap, host CPU model and TSC frequency in capabilities device events (a reload enumerates them again); PCI passthrough and mediated devices: Windows lends devices to guests only with Hyper-V (Discrete Device Assignment, pcip.sys), not on Windows Home, and QEMU has no use of it
Host interfaces iface-list (--all, --inactive), iface-dumpxml (Ethernet, Wi-Fi, TAP and Wintun adapters; a network bridge of Windows as a bridge with its members; IPv4 and IPv6 configuration), iface-mac, iface-name, iface-start and iface-destroy (enable and disable an adapter, with administrator rights) iface-define: Windows keeps the configuration of its adapters
Network filters nwfilter-define, -list, -dumpxml, bindings; the filters of interfaces on a libvirt network (clean-traffic...), with every protocol and attribute, connection states, reject; IP address learning (any, dhcp) interfaces of type='ethernet' and on bridges of Windows (TAP-Windows adapters): no filter
LXC lxc:///system: the LXC driver of libvirt in a small Alpine Linux VM that virtlxcd runs (virtlxcd --setup makes it once) containers, their file systems and networks are in that VM; lxc-enter-namespace
Other drivers VirtualBox

How it works

On Linux On this port
fork + exec CreateProcess suspended, resumed after the handshake
Signals named events Local\libvirt-signal-PID-SIG, console control handlers
UNIX sockets AF_UNIX sockets of Windows 10 1803 and later
/run emptied at boot autostart marks older than the boot ignored
Symbolic links symbolic links, or without the privilege system files as Cygwin/MSYS2 make them
PTY consoles QEMU serial on a UNIX socket, virsh console through the Windows console
KVM WHPX (<domain type='whpx'>), TCG otherwise
dmidecode, /sys/class/dmi the SMBIOS table of the firmware (GetSystemFirmwareTable), written as dmidecode writes it
udev, sysfs (node devices) SetupAPI and the device tree of Windows, the IP helper API, the storage IOCTLs
/proc/cpuinfo, /proc/stat, KVM (TSC) the processor relations of Windows, NtQuerySystemInformation, the Windows Hypervisor Platform (TSC frequency); MSRs, which Windows does not let user space read, are left out
statvfs, fallocate (storage) GetDiskFreeSpaceEx; volumes written out
mount (fs and netfs pools) a directory symbolic link to \\HOST\SHARE; a volume mount point
udev, netcf (host interfaces) the IP helper API and the network class of SetupAPI; netsh to enable and disable
Bridge, TAP, dnsmasq, iptables libvirt_netswitch: one process per network, an Ethernet switch on a UNIX socket that QEMU joins with -netdev stream, libslirp for NAT, its own DHCP/DHCPv6/DNS, QoS by token buckets
type='ethernet' TAP devices TAP-Windows6 adapters created by SetupAPI; Wintun adapters for route and open
Host bridges (br0), brctl/ip link network bridges of Windows, netsh bridge add/remove
firewalld zone libvirt Windows firewall rules of the group libvirt
tc the switch shapes what a guest receives and polices what it sends
ebtables, iptables, nftables (nwfilter) the filters compiled into a program the switch runs on each frame of the port, with its own connection tracking; each interface has its socket on the switch
libpcap (IP address learning, DHCP snooping) a monitor socket of the interface on the switch
A Linux kernel (LXC) an Alpine Linux VM under WHPX, its libvirt reached through SSH
File descriptors given to QEMU (getfd, SCM_RIGHTS) sockets duplicated into QEMU (get-win32-socket); files (save, restore, dump) relayed by a thread of libvirt over a socket pair; QEMU connects to the migration destination itself
Replacing running binaries renamed NAME.busy-STAMP by the install, removed by the next one

Requirements

  • Windows 10 1803 or later, x64. For hardware acceleration, the Windows Hypervisor Platform optional feature.
  • MSYS2, UCRT64 environment.
  • QEMU for Windows with the patch in windows/qemu: without it WHPX crashes while libvirt probes QEMU.
  • For NFS storage pools: WinFsp (and mingw-w64-ucrt-x86_64-libnfs to build libvirt_nfsmount).

Build

From an MSYS2 UCRT64 shell:

git clone --recurse-submodules https://github.com/EGKrb/libvirt-windows
cd libvirt-windows
windows/build.sh deps     # MSYS2 packages
windows/build.sh          # configure, build, install into install/

BUILD and PREFIX change the build and install directories. The install can run while daemons and networks run, and keeps edited configuration files (the new version goes beside them as NAME.new).

Run

The DLLs come from MSYS2: put install\bin, C:\msys64\ucrt64\bin and QEMU on PATH, then from PowerShell:

install\sbin\virtnetworkd.exe --daemon
install\sbin\virtqemud.exe --daemon
install\bin\virsh.exe -c qemu:///system net-list --all
install\bin\virsh.exe -c qemu:///system define guest.xml
install\bin\virsh.exe -c qemu:///system start guest
install\bin\virsh.exe -c qemu:///system console guest

A guest with WHPX, the default network and a serial console:

<domain type='whpx'>
  <name>guest</name>
  <memory unit='MiB'>2048</memory>
  <vcpu>2</vcpu>
  <os><type arch='x86_64' machine='q35'>hvm</type></os>
  <features><acpi/><apic/></features>
  <cpu mode='host-passthrough'/>
  <devices>
    <emulator>C:\Program Files\qemu\qemu-system-x86_64.exe</emulator>
    <disk type='file' device='disk'>
      <driver name='qemu' type='qcow2'/>
      <source file='C:/vms/guest.qcow2'/>
      <target dev='vda' bus='virtio'/>
    </disk>
    <interface type='network'>
      <source network='default'/>
      <model type='virtio'/>
    </interface>
    <serial type='unix'>
      <source mode='bind' path='C:/vms/guest-serial0.sock'/>
    </serial>
    <console type='unix'>
      <source mode='bind' path='C:/vms/guest-serial0.sock'/>
      <target type='serial'/>
    </console>
    <graphics type='vnc' port='-1' listen='127.0.0.1'/>
  </devices>
</domain>

A daemon is stopped by its SIGTERM event:

$p = (Get-Content install\var\run\virtqemud.pid).Trim()
[System.Threading.EventWaitHandle]::OpenExisting("Local\libvirt-signal-$p-15").Set()

Configuration is in install\etc\libvirt, logs in install\var\log\libvirt (a network's switch logs to network\NAME.log), run state in install\var\run\libvirt.

Networks

  • nat and isolated networks work out of the box, as the default network. Guests reach the host's services by the gateway address (192.168.122.1).
  • route and open need Wintun: wintun.dll (amd64) beside install\libexec\libvirt_netswitch.exe, and administrator rights. The host then has a virbr0 interface with the gateway address, as on Linux.
  • type='ethernet' needs the TAP-Windows6 driver of OpenVPN (9.27 or later, hardware id root\tap0901) in the driver store (pnputil /add-driver OemVista.inf /install), and administrator rights: libvirt creates an adapter named after the interface (vnet0), gives it the <source><ip/></source> addresses and routes, and deletes it with the guest. With <target dev='NAME' managed='no'/> it uses an existing adapter of that name and leaves it.
  • Bridges to the host's LAN, as br0 on Linux: a network bridge of Windows whose connection name is the bridge name. netsh bridge create takes two adapters: the host's NIC and any other one, such as a TAP-Windows adapter made with devcon install OemVista.inf tap0901 (from the TAP-Windows6 distribution); then rename the bridge (Rename-NetAdapter). An <interface type='bridge'><source bridge='br0'/>, or a network <forward mode='bridge'/><bridge name='br0'/>, gets a TAP-Windows adapter that libvirt adds to the bridge (netsh bridge add) and deletes with the guest. Needs the TAP driver and administrator rights, as above. A bridge name that is a libvirt network's (virbr0) is its switch, as before.
  • The Windows firewall puts these TAP and Wintun interfaces in the Public profile. As firewalld's libvirt zone on Linux, a route network (or open with <bridge zone='libvirt'/>) gets inbound rules (group libvirt, removed with the network) for ICMP, ICMPv6, DHCP, DHCPv6, DNS, SSH and TFTP from its subnets; anything else a guest opens to the host needs a rule of yours, as do type='ethernet' interfaces.

Layout

  • windows/build.sh: build script; windows/qemu: the QEMU patch; windows/site: the GitHub Pages site.
  • scripts/windows-install.py: install over a running libvirt.
  • src/network/netswitch.c: the switch of a virtual network.
  • The rest is libvirt, with the Windows changes in place. Every change since upstream: git diff $(git rev-list --max-parents=0 HEAD).

License

As libvirt: the library under the LGPL 2.1 or later, some tools under the GPL 2.0 or later; see COPYING and COPYING.LESSER. libvirt is a project of the libvirt developers: https://libvirt.org.

About

Unofficial port of libvirt to Windows: virsh, the daemons, QEMU guests with WHPX, virtual networks

Topics

Resources

Contributing

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages