From 7f13a79c9b6906f5ad8ef0025cafaca60152b676 Mon Sep 17 00:00:00 2001 From: AlexSSD7 Date: Wed, 30 Aug 2023 18:29:41 +0100 Subject: [PATCH] Some OS-specific adjustments --- cmd/utils.go | 3 --- vm/vm.go | 32 +++++++++++++++++++++----------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/cmd/utils.go b/cmd/utils.go index 96d48fa..62e77f0 100644 --- a/cmd/utils.go +++ b/cmd/utils.go @@ -32,9 +32,6 @@ func checkIfRoot() (bool, error) { func doUSBRootCheck() { switch runtime.GOOS { - case "darwin": - // Root privileges is not required in macOS. - return case "windows": // Administrator privileges are not required in Windows. return diff --git a/vm/vm.go b/vm/vm.go index 88cc660..aac92d6 100644 --- a/vm/vm.go +++ b/vm/vm.go @@ -104,29 +104,39 @@ func NewVM(logger *slog.Logger, cfg VMConfig) (*VM, error) { baseCmd := "qemu-system" + var accel string + switch runtime.GOOS { + case "windows": + // TODO: whpx accel is broken in Windows. Long term solution looks to be use Hyper-V. + + // For Windows, we need to install QEMU using an installer and add it to PATH. + // Then, we should enable Windows Hypervisor Platform in "Turn Windows features on or off". + // IMPORTANT: We should also install libusbK drivers for USB devices we want to pass through. + // This can be easily done with a program called Zadiag by Akeo. + accel = "whpx,kernel-irqchip=off" + case "darwin": + accel = "hvf" + default: + accel = "kvm" + } + switch runtime.GOARCH { case "amd64": - accel := "kvm" - if runtime.GOOS == "windows" { - // For Windows, we need to install QEMU using an installer and add it to PATH. - // Then, we should enable Windows Hypervisor Platform in "Turn Windows features on or off". - // IMPORTANT: We should also install libusbK drivers for USB devices we want to pass through. - // This can be easily done with a program called Zadiag by Akeo. - accel = "whpx,kernel-irqchip=off" - } - - cmdArgs = append(cmdArgs, "-accel", accel) baseCmd += "-x86_64" case "arm64": if cfg.BIOSPath == "" { logger.Warn("BIOS image path is not specified while attempting to run an aarch64 (arm64) VM. The VM will not boot.") } - cmdArgs = append(cmdArgs, "-accel", "hvf", "-M", "virt,highmem=off", "-cpu", "cortex-a57") + + // ",highmem=off" is required for M1. + cmdArgs = append(cmdArgs, "-M", "virt,highmem=off", "-cpu", "host") baseCmd += "-aarch64" default: return nil, fmt.Errorf("arch '%v' is not supported", runtime.GOARCH) } + cmdArgs = append(cmdArgs, "-accel", accel) + if runtime.GOOS == "windows" { baseCmd += ".exe" }