Skip to content

Commit e025355

Browse files
frezbosmira
authored andcommitted
feat(talosctl): support running qemu x86 on Mac
Supporting running x86 VM's on Mac. Signed-off-by: Noel Georgi <git@frezbo.dev> (cherry picked from commit 94905c7)
1 parent 21a914a commit e025355

2 files changed

Lines changed: 10 additions & 12 deletions

File tree

pkg/provision/providers/qemu/arch.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
package qemu
66

77
import (
8-
"errors"
98
"fmt"
109
"os/exec"
1110
"path/filepath"
12-
"runtime"
1311
"slices"
1412
)
1513

@@ -25,13 +23,7 @@ const (
2523
// Valid returns an error if the architecture is not supported.
2624
func (arch Arch) Valid() error {
2725
switch arch {
28-
case ArchArm64:
29-
return nil
30-
case ArchAmd64:
31-
if runtime.GOOS == "darwin" {
32-
return errors.New("only arm emulation is supported on darwin")
33-
}
34-
26+
case ArchArm64, ArchAmd64:
3527
return nil
3628
default:
3729
return fmt.Errorf("unsupported arch: %q", arch)
@@ -140,7 +132,8 @@ func (arch Arch) PFlash(uefiEnabled bool, extraUEFISearchPaths []string) []PFlas
140132
"/usr/share/ovmf",
141133
"/usr/share/OVMF",
142134
"/usr/share/qemu",
143-
"/usr/share/ovmf/x64", // Arch Linux
135+
"/usr/share/ovmf/x64", // Arch Linux
136+
"/opt/homebrew/share/qemu", // Darwin
144137
}
145138

146139
// Secure boot enabled firmware files
@@ -149,7 +142,7 @@ func (arch Arch) PFlash(uefiEnabled bool, extraUEFISearchPaths []string) []PFlas
149142
"OVMF_CODE.secboot.4m.fd", // Arch Linux
150143
"OVMF_CODE.secboot.fd",
151144
"OVMF.secboot.fd",
152-
"edk2-x86_64-secure-code.fd", // Alpine Linux
145+
"edk2-x86_64-secure-code.fd", // Alpine Linux, Darwin
153146
"ovmf-x86_64-ms-4m-code.bin",
154147
}
155148

@@ -159,6 +152,7 @@ func (arch Arch) PFlash(uefiEnabled bool, extraUEFISearchPaths []string) []PFlas
159152
"OVMF_CODE.4m.fd", // Arch Linux
160153
"OVMF_CODE.fd",
161154
"OVMF.fd",
155+
"edk2-x86_64-code.fd", // Darwin
162156
"ovmf-x86_64-4m-code.bin",
163157
}
164158

@@ -167,6 +161,7 @@ func (arch Arch) PFlash(uefiEnabled bool, extraUEFISearchPaths []string) []PFlas
167161
"OVMF_VARS_4M.fd",
168162
"OVMF_VARS.4m.fd", // Arch Linux
169163
"OVMF_VARS.fd",
164+
"edk2-i386-vars.fd", // Darwin
170165
"ovmf-x86_64-4m-vars.bin",
171166
}
172167

pkg/provision/providers/qemu/arch_darwin.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44

55
package qemu
66

7+
import "runtime"
8+
79
const accelerator = "hvf"
810

911
func (arch Arch) acceleratorAvailable() bool {
10-
return true
12+
// hvf only supports emulating native architectures
13+
return string(arch) == runtime.GOARCH
1114
}

0 commit comments

Comments
 (0)