f-28: qemu: execute with uefi vars
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
ec613996a0
commit
2a5473eb22
2 changed files with 40 additions and 4 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue