Tweaked qemu launch for non KVM hosts for development

This commit is contained in:
Ben Duncan
2025-11-15 11:15:03 +00:00
parent 42b3ba7fa1
commit bacd1f3ba2
3 changed files with 27 additions and 11 deletions
+2
View File
@@ -64,3 +64,5 @@ require (
golang.org/x/time v0.12.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
replace github.com/mulgadc/viperblock => ../viperblock
replace github.com/mulgadc/predastore => ../predastore
+4 -4
View File
@@ -1198,11 +1198,11 @@ func (d *Daemon) StartInstance(instance *vm.VM) error {
Name: instance.ID,
Daemonize: true,
PIDFile: pidFile,
EnableKVM: true,
NoGraphic: false,
MachineType: "ubuntu",
EnableKVM: true, // If available, if kvm fails, will use cpu max
NoGraphic: true,
MachineType: "q35",
Serial: "pty",
CPUType: "host",
CPUType: "host", // If available, if kvm fails, will use cpu max
Memory: int(instanceType.MemoryGB) * 1024,
CPUCount: instanceType.VCPUs,
Architecture: instanceType.Architecture,
+21 -7
View File
@@ -4,6 +4,7 @@ import (
"crypto/rand"
"fmt"
"log/slog"
"os"
"os/exec"
"strconv"
"strings"
@@ -115,12 +116,29 @@ func (cfg *Config) Execute() (*exec.Cmd, error) {
args = append(args, "-qmp", fmt.Sprintf("unix:%s,server,nowait", cfg.QMPSocket))
}
if cfg.EnableKVM {
args = append(args, "-enable-kvm")
// Validate native kvm support
_, err := os.Stat("/dev/kvm")
if err != nil {
slog.Warn("Native KVM support not detected on host. Check permissions and host")
//slog.Warn("Setting -cpu max, `host` CPU type unavailable")
// Use qemu defaults
//args = append(args, "-cpu", "max")
} else {
if cfg.EnableKVM {
args = append(args, "-enable-kvm")
}
if cfg.CPUType != "" {
args = append(args, "-cpu", cfg.CPUType)
}
}
if cfg.NoGraphic {
args = append(args, "-nographic")
args = append(args, "-display none")
}
if cfg.MachineType != "" {
@@ -131,10 +149,6 @@ func (cfg *Config) Execute() (*exec.Cmd, error) {
args = append(args, "-serial", cfg.Serial)
}
if cfg.CPUType != "" {
args = append(args, "-cpu", cfg.CPUType)
}
if cfg.CPUCount > 0 {
args = append(args, "-smp", strconv.Itoa(cfg.CPUCount))
} else {