lima-vm/lima · critical

HcsCreateOperation

Error message

HcsCreateOperation: %w

What it means

hcsCreateOperation calls the Win32 HcsCreateOperation API via syscall; if it returns a NULL operation handle, lima wraps the syscall's error value (e1) as 'HcsCreateOperation: <err>'. This is the first step of every async HCS call, so any compute-system create/start/terminate/state query can surface it. It almost always means the Host Compute Service is unavailable or broken on the host.

Solutions

  1. Verify the vmcompute (Host Compute Service) Windows service exists and is running: sc query vmcompute
  2. Enable required Windows features: Virtual Machine Platform / Hyper-V (dism /online /enable-feature ...)
  3. Repair system files (sfc /scannow, DISM /RestoreHealth) if vmcompute.dll is damaged
  4. Ensure the Windows build supports HCS, or switch to a non-HCS lima driver

Example fix

// before (admin PowerShell)
PS> sc query vmcompute   # service not found -> HcsCreateOperation fails
// after: enable the feature and reboot
PS> dism /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
PS> Restart-Computer
Defensive patterns

Strategy: validation

Validate before calling

func hcsAvailable() error {
	if runtime.GOOS != "windows" {
		return errors.New("hcs requires Windows")
	}
	// Host Compute Service must be present
	if _, err := os.Stat(`C:\Windows\System32\vmcompute.dll`); err != nil {
		return errors.New("Host Compute Service (vmcompute.dll) missing; enable Virtual Machine Platform")
	}
	return nil
}

Try / catch

if err := limactl.Start(inst); err != nil {
	if strings.Contains(err.Error(), "HcsCreateOperation") {
		// HCS unavailable: check 'sc query vmcompute', enable features, reboot, retry once
	}
	return err
}

Prevention

When it happens

Trigger: Any hcsCreateComputeSystem / hcsStartComputeSystem / hcsTerminateComputeSystem / getComputeSystemState call when HcsCreateOperation fails — HCS service not running or corrupted, missing Windows feature (Virtual Machine Platform / Host Compute Service), or an OS build without the API export.

Common situations: Windows Home or stripped-down SKUs lacking HCS; 'Host Compute Service'/'Hyper-V' features disabled; vmcompute.dll missing or wrong version after a broken Windows update; running in a container or VM without nested virtualization.

Related errors


AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01). Data as JSON: /api/errors/e939a1a7af2c70c8. Report an issue: GitHub.

Appendix: source

Thrown at pkg/driver/hcs/hcs_api_windows.go:75

		r0 &= 0xffff
	}
	return syscall.Errno(r0)
}

// coString copies a CoTaskMem-allocated PWSTR into a Go string and frees it.
func coString(p *uint16) string {
	if p == nil {
		return ""
	}
	s := windows.UTF16PtrToString(p)
	windows.CoTaskMemFree(unsafe.Pointer(p))
	return s
}

func hcsCreateOperation() (hcsOperation, error) {
	r0, _, e1 := syscall.SyscallN(procHcsCreateOperation.Addr(), 0, 0)
	if r0 == 0 {
		return 0, fmt.Errorf("HcsCreateOperation: %w", e1)
	}
	return hcsOperation(r0), nil
}

func hcsCloseOperation(op hcsOperation) {
	_, _, _ = syscall.SyscallN(procHcsCloseOperation.Addr(), uintptr(op))
}

// hcsWait drives one async HCS call to completion and returns the result
// document (which carries structured error info on failure).
func hcsWait(op hcsOperation, what string, callErr error) (string, error) {
	if callErr != nil {
		return "", fmt.Errorf("%s: %w", what, callErr)
	}
	var result *uint16
	r0, _, _ := syscall.SyscallN(procHcsWaitForOperationResult.Addr(),
		uintptr(op), uintptr(infiniteTimeout), uintptr(unsafe.Pointer(&result)))
	doc := coString(result)

View on GitHub (pinned to dd909d0973)