Skip to content

Commit

Permalink
Support running x86 QEMU on arm64
Browse files Browse the repository at this point in the history
  • Loading branch information
spowelljr committed Jul 10, 2024
1 parent 37bf577 commit b08324a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
14 changes: 10 additions & 4 deletions pkg/drivers/qemu/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions pkg/minikube/registry/drvs/qemu2/qemu2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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" {
Expand Down

0 comments on commit b08324a

Please sign in to comment.