Skip to content

Add Hyper-V backend for Windows support #2

Open

Description

@JAORMX

Motivation

propolis currently only runs on Linux (KVM) and macOS (Hypervisor.framework) via libkrun. There is no Windows support. This issue tracks adding a Hyper-V backend to enable running OCI container images as microVMs on Windows.

Depends on: #1 (hypervisor abstraction layer)

Background

Why Hyper-V?

  • Native Windows hypervisor — ships with Windows 10/11 Pro and Server editions
  • HCS (Host Compute Service) — well-maintained Go bindings via hcsshim, used by Docker Desktop and containerd
  • LCOW support — HCS natively supports Linux Containers on Windows (running Linux guests on Hyper-V)
  • No CGO required — hcsshim is pure Go, unlike the libkrun backend

Alternatives considered

Alternative Why not
Hyperlight No OS in guest, no filesystem, no networking, no OCI support, no Go SDK. Fundamentally different execution model (function sandbox, not container VM).
QEMU + WHPX Too heavyweight. Full device emulation stack adds significant complexity and binary size.
WSL2 + KVM KVM support in WSL2 is unreliable — works in some WSL versions, regressed in others. Not shippable.
Firecracker Linux/KVM only, no Windows support.

Proposed Implementation

Backend: hypervisor/hyperv/

Implements the hypervisor.Backend interface from #1:

//go:build windows

type Backend struct {
    // KernelPath is the path to the Linux kernel to boot.
    KernelPath string

    // InitRDPath is the optional path to an initrd image.
    InitRDPath string
}

func (b *Backend) Name() string { return "hyperv" }

func (b *Backend) PrepareRootFS(ctx context.Context, rootfsPath string, initCfg InitConfig) (string, error) {
    // 1. Write /.propolis_init.json to rootfs (generic init config)
    // 2. Convert flat rootfs directory to VHDX disk image
    // 3. Return path to VHDX
}

func (b *Backend) Start(ctx context.Context, cfg VMConfig) (VMHandle, error) {
    // 1. Create LCOW utility VM via hcsshim
    // 2. Attach root VHDX
    // 3. Configure networking (hvsock transport)
    // 4. Add filesystem mounts (Plan 9 shares)
    // 5. Start VM
    // 6. Return hcsHandle wrapping uvm.UtilityVM
}

Key components

Rootfs → VHDX conversion

The OCI image extraction pipeline produces a flat directory. Hyper-V needs a VHDX disk image. Options to investigate:

  • virtdisk.dll Windows API (CreateVirtualDisk, AttachVirtualDisk)
  • hcsshim's internal LCOW layer utilities
  • diskpart / Convert-VHD PowerShell (fragile, last resort)

Networking: gvisor-tap-vsock over hvsock

gvisor-tap-vsock already supports Hyper-V socket transport (AF_HYPERV). The same virtual network stack used by libkrun's in-process networking can be reused with a different transport:

  • libkrun: AcceptQemu() over Unix socketpair
  • Hyper-V: AcceptHyperV() over hvsock

The NetEndpoint type from #1 carries the transport info:

NetEndpoint{Type: NetEndpointHVSocket, Path: serviceGUID}

Guest init

libkrun reads /.krun_config.json via its built-in init. Hyper-V needs a different mechanism:

  • Write /.propolis_init.json with the same schema ({cmd, env, working_dir})
  • Extend the guest/boot package to read this config and exec the workload
  • Or use a minimal custom init binary in the initrd

Linux kernel

Unlike libkrun (which bundles a kernel in libkrunfw), Hyper-V requires a separate kernel image. Options:

  • Bundle a kernel build (like Docker Desktop uses LinuxKit)
  • Build a custom minimal kernel with virtio + 9p + ext4
  • Let users provide their own via Backend.KernelPath

Platform-specific files needed

File Purpose
hypervisor/hyperv/backend.go Backend implementation via hcsshim
hypervisor/hyperv/handle.go VMHandle wrapping uvm.UtilityVM
hypervisor/hyperv/vhd.go Rootfs dir → VHDX conversion
hypervisor/default_windows.go DefaultBackendName = "hyperv"
preflight/hyperv_windows.go Check Hyper-V is enabled
preflight/resources_windows.go Disk/CPU/RAM checks
internal/procutil/process_windows.go Process identification via QueryFullProcessImageName
extract/libname_windows.go .dll naming convention

VM lifecycle

Unlike libkrun (where krun_start_enter() takes over the process and never returns), Hyper-V manages VM lifecycle via API calls:

type hcsHandle struct {
    vm *uvm.UtilityVM
}

func (h *hcsHandle) Stop(ctx context.Context) error {
    // Graceful: vm.Shutdown()
    // Force:    vm.Terminate()
    // Cleanup:  vm.Close()
}

func (h *hcsHandle) IsAlive() bool { return h.vm.State() == StateRunning }
func (h *hcsHandle) ID() string    { return h.vm.ID() }

No two-process model needed. No signals. No Setsid. Pure API-driven lifecycle.

Open Questions

  • Kernel bundling: LinuxKit kernel? Custom minimal build? User-provided? What's the right default for a library?
  • VHD creation: Which Windows API is most reliable for creating ext4-formatted VHDX from a directory tree?
  • Guest init: Extend guest/boot package, or build a separate init binary for Hyper-V guests?
  • CI/CD: How to test? Windows runners with nested virtualization? Mock HCS interfaces? Integration test matrix?
  • hvsock vs named pipe: Which transport for gvisor-tap-vsock? hvsock is more natural for Hyper-V, named pipes are simpler.
  • Hyper-V editions: Require Pro/Enterprise (full Hyper-V) or also support Home (limited WHP)?
  • Filesystem mounts: Plan 9 shares via hcsshim, or alternative mechanism?

Implementation phases

  1. Introduce hypervisor.Backend abstraction layer #1 must land first — the abstraction layer
  2. Windows platform files — preflight, procutil, extract, default backend (can be done in parallel with 3)
  3. Hyper-V backend — hcsshim integration, VHD creation, hvsock networking
  4. Guest init — extend guest/boot or build custom init for non-libkrun backends
  5. Kernel packaging — decide on and implement kernel bundling strategy
  6. CI — Windows test infrastructure

Activity

  1. added
    enhancement
    on Feb 19, 2026
  2. thejoeejoee commented on Nov 10, 2026

    @thejoeejoee
    Contributor

    Feasibility & Technical Analysis against current main (a0df24a)

    With #1 (hypervisor.Backend abstraction) merged, we analyzed what it would take to implement the Hyper-V backend on top of current stacklok/go-microvm main.

    Overall: feasible, and CGO_ENABLED=0 on Windows can be preserved, but several interfaces and assumptions have evolved since this issue was drafted, and there are three key architectural gaps (hcsshim/internal/uvm visibility, guest-side AF_HYPERV ↔ NIC bridging, and NTFS UID/GID loss during rootfs extraction) that affect the design.


    1. Drift between the issue proposal and current main

    1. hypervisor.Backend & VMConfig have grown (hypervisor/backend.go:11-64)
      • VMConfig now includes Disks []Disk, VsockPorts []VsockPort, LogLevel uint32, and FilesystemMount.{ReadOnly, SimplifiedOwnership}.
      • NetEndpointType (hypervisor/backend.go:72-83) already defines NetEndpointNone, NetEndpointUnixSocket, NetEndpointNamedPipe, and NetEndpointHVSocket.
    2. PrepareRootFS path containment check (microvm.go:251-261, vm.go:155)
      • microvm.go validates that the path returned by backend.PrepareRootFS(ctx, rootfs.Path, initCfg) satisfies isWithin(rootfs.Path, preparedPath) || preparedPath == rootfs.Path.
      • Returning an external sibling path for the VHD/VHDX will fail validation with "backend returned rootfs path outside original". Either PrepareRootFS must write rootfs.vhd inside rootfs.Path (e.g. filepath.Join(rootfsPath, "rootfs.vhd")), or return rootfsPath and keep the VHD at a deterministic subpath consumed by Start().
    3. Default backend selection is still hardcoded (microvm.go:243-244)
      • hypervisor/default_*.go does not exist yet; microvm.go:244 calls libkrun.NewBackend() directly when cfg.backend == nil. Moving this to build-tagged defaultBackend() helpers decouples microvm.go from hypervisor/libkrun on Windows.
    4. NetEndpoint construction in microvm.go (microvm.go:318-320) and net.Provider (net/provider.go)
      • net.Provider currently exposes SocketPath() string and microvm.go:318 hardcodes Type: hypervisor.NetEndpointUnixSocket. To support NetEndpointHVSocket, net.Provider needs an endpoint descriptor (or NetEndpoint method) rather than assuming a Unix domain socket path.

    2. Three Architectural Blockers to Address in the Design

    A. hcsshim's uvm package is internal/ (cannot be imported)

    The issue sketches uvm.CreateLCOW and *uvm.UtilityVM, which live under github.com/Microsoft/hcsshim/internal/uvm (internal/uvm/create_lcow.go). Go forbids importing internal/ packages across module boundaries.

    • Solution: Use the public github.com/Microsoft/hcsshim/hcs package (hcs.CreateComputeSystem, hcs.OpenComputeSystem, *hcs.System) with an HCS Schema v2 (hcsshim/internal/schema2 or a minimal local struct) ComputeSystem JSON document declaring VirtualMachine (ComputeTopology, Devices.{Scsi, HvSocket, Plan9}, and GuestOs / LinuxKernelFile + InitrdFile). This stays 100% pure Go (vmcompute.dll via golang.org/x/sys/windows lazy proc).

    B. Guest Networking: AF_HYPERV does not create a guest NIC (eth0)

    In the libkrun backend, libkrun emulates a virtio-net device (eth0 in the guest) backed by the host Unix socket connected to gvisor-tap-vsock.

    • In Hyper-V LCOW, an HvSocket (AF_VSOCK / hv_sock inside the Linux guest) is a stream socket, not a network interface—the guest kernel has no eth0, so guest/netcfg.Configure (guest/netcfg/netcfg.go:22, which configures eth0 via netlink) will fail unless a virtual interface is created.
    • Also note: gvisor-tap-vsock v0.9.0 does not have an AcceptHyperV() method on virtualnetwork.VirtualNetwork. It exposes AcceptQemu(ctx, net.Conn) (4-byte big-endian length-prefixed L2 frames over any io.ReadWriteCloser/net.Conn, used by net/hosted/provider.go:294,299).
    • Solution:
      1. Host side (net/hosted/provider.go): Listen on AF_HYPERV using github.com/linuxkit/virtsock/pkg/hvsock (already an indirect dependency in go.mod via gvisor-tap-vsock) and pass accepted net.Conn connections into the existing vn.AcceptQemu(bgCtx, conn) path.
      2. Guest side: The guest init/agent must create a TAP interface named eth0, dial the host AF_VSOCK (hv_sock) service port/GUID, and bridge L2 frames with the 4-byte length prefix (QemuProtocol) between eth0 and the vsock stream before netcfg.Configure runs.

    C. NTFS loses POSIX UID/GID/mode/xattrs if RootFS is extracted to a host directory first

    Currently, image/ extracts OCI layers into host directories and uses internal/xattr (override_other.go is a no-op on Windows) and rootfs/clone.go (os.Lchown, syscall.Stat_t) to preserve ownership/permissions. Extracting to an NTFS directory and then converting that directory to VHDX loses Linux UIDs, GIDs, symlink semantics, and setuid bits.

    • Solution: Use github.com/Microsoft/hcsshim/ext4/tar2ext4 (public, pure Go, no CGO, no virtdisk.dll or host disk mounting required).
    • tar2ext4.ConvertTarToExt4(r, w, tar2ext4.ConvertWhiteout, tar2ext4.AppendVhdFooter) converts an OCI layer/merged tar stream directly into an ext4 filesystem image with a fixed VHD footer while preserving full POSIX UID/GID, permissions, xattrs, and .wh. whiteouts without touching NTFS metadata.

    3. Exact GOOS=windows CGO_ENABLED=0 Compile Audit

    Testing GOOS=windows CGO_ENABLED=0 go build ./... against main (a0df24a) shows:

    Already compiling cleanly on Windows:

    • hypervisor, net, net/hosted, net/egress, virtiofs (prepare_other.go), internal/xattr (override_other.go), internal/procutil, ssh, state, guest/env, guest/vmconfig.

    Files failing compilation on Windows and required fixes:

    File / Package Failure on GOOS=windows Action Needed
    internal/pathutil/mode.go:53, private.go:107 syscall.Stat_t undefined Split into mode_unix.go / mode_windows.go and private_unix.go / private_windows.go
    extract/libname.go:9 libName undefined (only _darwin/_linux) Add extract/libname_windows.go (or build-tag extract to !windows if only used by libkrun)
    preflight/checker.go:61 registerPlatformChecks undefined Add preflight/platform_windows.go (hyperv_windows.go + resources_windows.go)
    rootfs/clone.go:136,143,266 cloneFile and fileOwner only in clone_{darwin,linux}.go Add rootfs/clone_windows.go
    options.go:197 (microvm.go:497,514) syscall.Kill undefined on Windows Move default killProcess into build-tagged process_unix.go / process_windows.go
    runner/spawn.go:44,117,191 & hypervisor/libkrun syscall.Kill, SysProcAttr.Setsid, isExpectedProcess Tag runner/ and hypervisor/libkrun/ with //go:build !windows (or linux || darwin) and split default backend selection in microvm.go:244

    4. Answers & Recommendations for the 7 Open Questions

    1. Kernel bundling:
      • Today the kernel comes from libkrunfw (versions.env: LIBKRUNFW_VERSION=v5.6.2, built in images/builder/Containerfile:30-33).
      • For Hyper-V LCOW, the guest kernel needs CONFIG_HYPERV, hv_vmbus, hv_storvsc, hv_sock, hv_utils, 9pnet_virtio / 9p, ext4, and tun.
      • Recommendation: Accept an explicit WithKernelPath / WithInitrdPath option on hyperv.Backend first, and add an LCOW kernel + minimal initrd target to images/builder/Containerfile (or fetch LinuxKit's LCOW kernel release artifact into the cache directory) in Phase 5.
    2. VHDX creation:
      • Recommendation: Use github.com/Microsoft/hcsshim/ext4/tar2ext4 with tar2ext4.AppendVhdFooter to produce a fixed .vhd in pure Go. Avoid virtdisk.dll (AttachVirtualDisk) for rootfs preparation because mounting virtual disks on the Windows host requires elevation and loses POSIX metadata on NTFS.
    3. Guest init (guest/boot vs separate init):
      • guest/boot.Run() (guest/boot/boot.go:41) is a library helper that mounts essentials (/proc, /sys, /dev), configures eth0, mounts virtio-fs workspaces, applies sysctls/seccomp/cap-drop, and starts optional sshd—it does not read /.krun_config.json or exec the workload (libkrun's built-in init.krun does that).
      • Furthermore, guest/mount/mount.go:105 hardcodes fstype "virtiofs".
      • Recommendation:
        • Add fstype support ("virtiofs" vs "9p") to guest/vmconfig (VirtioFSMountInfo) and guest/mount.Workspace.
        • Add a small Linux guest PID 1 binary (or guest/boot mode) for Hyper-V that: (1) mounts essential filesystems, (2) starts the hv_sock ↔ eth0 TAP relay, (3) runs guest/boot.Run(), and (4) reads the init config (Cmd, Env, WorkingDir) and execs the entrypoint under reaper.
    4. CI/CD:
      • GitHub Actions windows-latest runners support nested virtualization / Hyper-V on standard hosted runners when enabled, but start by adding a fast GOOS=windows CGO_ENABLED=0 go build ./... + unit test job in .github/workflows/ci.yaml so Windows compilation never regresses.
    5. hvsock vs named pipe:
      • Use AF_HYPERV (hvsock) between guest and host (NetEndpointHVSocket). A Linux guest inside Hyper-V cannot directly dial a Windows host Named Pipe (\\.\pipe\...) without HvSocket anyway; HCS HvSocket bridges guest AF_VSOCK directly to host AF_HYPERV.
    6. Windows Home vs Pro/Enterprise:
      • HCS (vmcompute.dll + Linux Utility VMs) requires the Windows Hyper-V platform components (Hyper-V-Hypervisor / VirtualMachinePlatform). Checking for the HCS service (vmcompute) and hypervisor presence in preflight/hyperv_windows.go gives a clear actionable error when the feature isn't enabled. (Also worth noting: upstream containers/libkrun lists a native Windows WHP backend as upcoming on its roadmap, which could eventually allow the libkrun backend itself to work on Windows WHP alongside HCS.)
    7. Plan 9 (9p) vs virtio-fs for FilesystemMounts:
      • HCS LCOW natively exposes host directories via Plan9 (9p2000.L over VMBus/virtio). In hyperv.Backend.Start, map each FilesystemMount to a Plan9 share + HvSocket port, and in guest/mount/mount.go mount with fstype="9p" and trans=virtio,version=9p2000.L,msize=524288 (honoring ReadOnly). Reject SimplifiedOwnership and OverrideUID/OverrideGID on Windows during validation (consistent with microvm.go:96). Also note that WithRootFSShare (microvm.go:179) assumes virtio-fs and should be rejected by hyperv.Backend.validate().
  3. thejoeejoee commented on Nov 11, 2026

    @thejoeejoee
    Contributor

    Open questions: HCS backend vs. libkrun on WHP

    While working on #173 (HCS v2 backend), libkrun's Windows support kept moving upstream, and I'd like maintainer input before taking the HCS path further.

    What changed upstream

    • containers/libkrun main (2.0.0-dev) has a WHP backend in src/whp (latest commits Sep 2026). It also has a Windows virtio-fs passthrough in src/devices/src/virtio/fs/windows/ (commits through Nov 2026), including handling for LinuxSimplifiedFixedOwner. The README still lists Windows as "upcoming".
    • Docker Sandboxes on Windows run on the Windows Hypervisor Platform (WHP) called directly, not on HCS.

    Trade-offs as I see them

    HCS v2 (#173) libkrun + WHP
    Host privileges Admin or Hyper-V Administrators, plus HcsGrantVmAccess Unprivileged (needs the HypervisorPlatform Windows feature)
    Rootfs ext4 VHD built per prepare (tar2ext4); POSIX metadata has to be carried through NTFS virtio-fs, same as macOS and Linux
    Shares Plan9 over vsock port 564 (separate guest mount path) virtio-fs
    Network Guest AF_VSOCK ↔ TAP relay, plus host AF_HYPERV port coordination virtio-net over a unix stream socket (AF_UNIX stream sockets work on Windows)
    Kernel/init Separate kernel, initrd and guest init (not built yet) libkrunfw and the existing init
    Code shared with the macOS/Linux backend Very little Most of hypervisor/libkrun and the guest
    Availability Today, on Windows 10/11 Pro/Enterprise and Server Not released yet; x86_64 only for now

    Questions

    1. Direction: is HCS still the preferred Windows backend, as Add Hyper-V backend for Windows support #2 originally proposed with hcsshim, or would you rather wait for libkrun on WHP and keep a single backend across all platforms?

    2. Splitting feat(hyperv): add Hyper-V backend and Windows host support #173: would you accept the hypervisor-agnostic part on its own first? That part is:

      • build-tag splits for Windows host portability (internal/pathutil, internal/procutil, runner, options, hooks, extract, rootfs)
      • default_backend_{unix,windows}.go
      • the net.EndpointProvider interface
      • Windows preflight checks
      • the Windows test-compile fixes

      The HCS-specific parts (hypervisor/hyperv, image/vhd, the Plan9/vsock guest mount, and the hvrelay network relay) would then stay as a draft or experimental PR.

    3. Privileges: is an HCS backend that needs admin or Hyper-V Administrators acceptable for go-microvm's consumers? For CLI tools that run as the user, this is a significant UX cost.

    4. Guest artifacts for HCS: if HCS stays, should go-microvm ship its own kernel and initrd? The kernel would need CONFIG_HYPERV*, HYPERV_VSOCKETS, 9P_FS, TUN and EXT4. Or would consumers be expected to bring their own? And is an initrd preferred over injecting /.krun_init into the VHD?

    5. libkrun on Windows: is anyone in contact with the libkrun maintainers about a timeline? Specifically:

      • Windows release builds of libkrun and libkrunfw
      • which virtio-net backends will work on Windows (unixstream vs unixgram)
      • whether the go-microvm-runner process model carries over unchanged
    6. CI: is a Windows build/vet job (GOOS=windows CGO_ENABLED=0) acceptable now, so that portability doesn't regress whichever backend is chosen? Is a Windows runner with nested virtualization an option for boot tests later?

    7. Windows on ARM64: is it a target? If so, HCS is currently the only option that supports it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions