From b08324a354cd186a7beafedb4e6c5eb671c7bf94 Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Wed, 10 Jul 2024 13:37:30 -0500 Subject: [PATCH] Support running x86 QEMU on arm64 --- pkg/drivers/qemu/qemu.go | 14 ++++++++++---- pkg/minikube/registry/drvs/qemu2/qemu2.go | 4 ++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/pkg/drivers/qemu/qemu.go b/pkg/drivers/qemu/qemu.go index 5d1569a4aa6a..84dd24593e88 100644 --- a/pkg/drivers/qemu/qemu.go +++ b/pkg/drivers/qemu/qemu.go @@ -42,6 +42,7 @@ import ( "k8s.io/klog/v2" pkgdrivers "k8s.io/minikube/pkg/drivers" + "k8s.io/minikube/pkg/minikube/detect" "k8s.io/minikube/pkg/minikube/exit" "k8s.io/minikube/pkg/minikube/firewall" "k8s.io/minikube/pkg/minikube/out" @@ -412,14 +413,19 @@ func (d *Driver) Start() error { } // hardware acceleration is important, it increases performance by 10x - if runtime.GOOS == "darwin" { + var accel string + if detect.IsAmd64M1Emulation() { + accel = "tcg" + } else if runtime.GOOS == "darwin" { // On macOS, enable the Hypervisor framework accelerator. - startCmd = append(startCmd, - "-accel", "hvf") + accel = "hvf" } else if _, err := os.Stat("/dev/kvm"); err == nil && runtime.GOOS == "linux" { // On Linux, enable the Kernel Virtual Machine accelerator. + accel = "kvm" + } + if accel != "" { startCmd = append(startCmd, - "-accel", "kvm") + "-accel", accel) } startCmd = append(startCmd, diff --git a/pkg/minikube/registry/drvs/qemu2/qemu2.go b/pkg/minikube/registry/drvs/qemu2/qemu2.go index 0e4fa2f8d4c4..4b848694abcc 100644 --- a/pkg/minikube/registry/drvs/qemu2/qemu2.go +++ b/pkg/minikube/registry/drvs/qemu2/qemu2.go @@ -31,6 +31,7 @@ import ( "k8s.io/minikube/pkg/drivers/qemu" "k8s.io/minikube/pkg/minikube/config" + "k8s.io/minikube/pkg/minikube/detect" "k8s.io/minikube/pkg/minikube/download" "k8s.io/minikube/pkg/minikube/driver" "k8s.io/minikube/pkg/minikube/localpath" @@ -76,6 +77,9 @@ func qemuFirmwarePath(customPath string) (string, error) { if runtime.GOOS == "windows" { return "C:\\Program Files\\qemu\\share\\edk2-x86_64-code.fd", nil } + if detect.IsAmd64M1Emulation() { + return "/opt/homebrew/opt/qemu/share/qemu/edk2-x86_64-code.fd", nil + } arch := runtime.GOARCH // For macOS, find the correct brew installation path for qemu firmware if runtime.GOOS == "darwin" {