From 2a5473eb22cd65a0bd1dbf9faf991d9ebfb9fd19 Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Sat, 23 May 2026 22:30:32 +0200 Subject: [PATCH] f-28: qemu: execute with uefi vars Signed-off-by: GnomeZworc --- internal/qemu/start_linux.go | 39 ++++++++++++++++++++++++++++++++---- internal/qemu/start_other.go | 5 +++++ 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/internal/qemu/start_linux.go b/internal/qemu/start_linux.go index 6119278..3f40e73 100644 --- a/internal/qemu/start_linux.go +++ b/internal/qemu/start_linux.go @@ -4,7 +4,9 @@ package qemu import ( "fmt" + "os" "os/exec" + "path/filepath" ) type Config struct { @@ -14,6 +16,11 @@ type Config struct { VolumePath string Memory int CPUs int + UEFICodePath string + UEFIVarsPath string + SerialDir string + MonitorDir string + QMPDir string } func Start(cfg Config) error { @@ -27,20 +34,44 @@ func Start(cfg Config) error { cpus = 1 } - cmd := exec.Command("qemu-system-x86_64", + for _, dir := range []string{cfg.SerialDir, cfg.MonitorDir, cfg.QMPDir} { + if dir != "" { + if err := os.MkdirAll(dir, 0755); err != nil { + return fmt.Errorf("mkdir %s: %w", dir, err) + } + } + } + + serialSock := filepath.Join(cfg.SerialDir, cfg.Name+".sock") + monitorSock := filepath.Join(cfg.MonitorDir, cfg.Name+".sock") + qmpSock := filepath.Join(cfg.QMPDir, cfg.Name+".sock") + + args := []string{ "-enable-kvm", "-cpu", "host", "-m", fmt.Sprintf("%d", memory), "-smp", fmt.Sprintf("%d", cpus), - "-serial", fmt.Sprintf("unix:/tmp/%s.sock,server,nowait", cfg.Name), - "-monitor", fmt.Sprintf("unix:/tmp/%s.mon-sock,server,nowait", cfg.Name), - "-qmp", fmt.Sprintf("unix:/tmp/%s.qmp-sock,server,nowait", cfg.Name), + "-serial", fmt.Sprintf("unix:%s,server,nowait", serialSock), + "-monitor", fmt.Sprintf("unix:%s,server,nowait", monitorSock), + "-qmp", fmt.Sprintf("unix:%s,server,nowait", qmpSock), "-display", "none", + } + + if cfg.UEFICodePath != "" && cfg.UEFIVarsPath != "" { + args = append(args, + "-drive", fmt.Sprintf("if=pflash,format=raw,readonly=on,file=%s", cfg.UEFICodePath), + "-drive", fmt.Sprintf("if=pflash,format=raw,file=%s", cfg.UEFIVarsPath), + ) + } + + args = append(args, "-drive", fmt.Sprintf("file=%s,if=virtio", cfg.VolumePath), "-netdev", fmt.Sprintf("tap,id=net0,ifname=tap%d,script=no,downscript=no", cfg.TapID), "-device", fmt.Sprintf("virtio-net-pci,netdev=net0,mac=%s", cfg.Mac), "-daemonize", ) + + cmd := exec.Command("qemu-system-x86_64", args...) if err := cmd.Run(); err != nil { return fmt.Errorf("qemu-system-x86_64: %w", err) } diff --git a/internal/qemu/start_other.go b/internal/qemu/start_other.go index 782a7ee..c9c9192 100644 --- a/internal/qemu/start_other.go +++ b/internal/qemu/start_other.go @@ -7,6 +7,11 @@ import "errors" type Config struct { Name, Mac, VolumePath string TapID, Memory, CPUs int + UEFICodePath string + UEFIVarsPath string + SerialDir string + MonitorDir string + QMPDir string } func Start(_ Config) error {