github.com/containers/podman/v4@v4.9.4/pkg/machine/qemu/options_darwin_arm64.go (about) 1 package qemu 2 3 import ( 4 "os" 5 "os/exec" 6 "path/filepath" 7 8 "github.com/containers/common/pkg/config" 9 ) 10 11 var ( 12 QemuCommand = "qemu-system-aarch64" 13 ) 14 15 func (v *MachineVM) addArchOptions(cmdOpts *setNewMachineCMDOpts) []string { 16 ovmfDir := getOvmfDir(cmdOpts.imageDir, v.Name) 17 opts := []string{ 18 "-accel", "hvf", 19 "-accel", "tcg", 20 "-cpu", "host", 21 "-M", "virt,highmem=on", 22 "-drive", "file=" + getEdk2CodeFd("edk2-aarch64-code.fd") + ",if=pflash,format=raw,readonly=on", 23 "-drive", "file=" + ovmfDir + ",if=pflash,format=raw"} 24 return opts 25 } 26 27 func (v *MachineVM) prepare() error { 28 ovmfDir := getOvmfDir(filepath.Dir(v.ImagePath.GetPath()), v.Name) 29 cmd := []string{"/bin/dd", "if=/dev/zero", "conv=sync", "bs=1m", "count=64", "of=" + ovmfDir} 30 return exec.Command(cmd[0], cmd[1:]...).Run() 31 } 32 33 func (v *MachineVM) archRemovalFiles() []string { 34 ovmDir := getOvmfDir(filepath.Dir(v.ImagePath.GetPath()), v.Name) 35 return []string{ovmDir} 36 } 37 38 func getOvmfDir(imagePath, vmName string) string { 39 return filepath.Join(imagePath, vmName+"_ovmf_vars.fd") 40 } 41 42 /* 43 * When QEmu is installed in a non-default location in the system 44 * we can use the qemu-system-* binary path to figure the install 45 * location for Qemu and use it to look for edk2-code-fd 46 */ 47 func getEdk2CodeFdPathFromQemuBinaryPath() string { 48 cfg, err := config.Default() 49 if err == nil { 50 execPath, err := cfg.FindHelperBinary(QemuCommand, true) 51 if err == nil { 52 return filepath.Clean(filepath.Join(filepath.Dir(execPath), "..", "share", "qemu")) 53 } 54 } 55 return "" 56 } 57 58 /* 59 * QEmu can be installed in multiple locations on MacOS, especially on 60 * Apple Silicon systems. A build from source will likely install it in 61 * /usr/local/bin, whereas Homebrew package management standard is to 62 * install in /opt/homebrew 63 */ 64 func getEdk2CodeFd(name string) string { 65 dirs := []string{ 66 getEdk2CodeFdPathFromQemuBinaryPath(), 67 "/opt/homebrew/opt/podman/libexec/share/qemu", 68 "/usr/local/share/qemu", 69 "/opt/homebrew/share/qemu", 70 } 71 for _, dir := range dirs { 72 fullpath := filepath.Join(dir, name) 73 if _, err := os.Stat(fullpath); err == nil { 74 return fullpath 75 } 76 } 77 return name 78 }