mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-21 10:09:07 +00:00
Merge pull request #2110 from ijc/qemu-kvm-control
qemu: Add -enable-kvm to force (attempted) use (or not) of KVM
This commit is contained in:
commit
6fb1ab285e
@ -37,6 +37,11 @@ type QemuConfig struct {
|
|||||||
PublishedPorts []string
|
PublishedPorts []string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func haveKVM() bool {
|
||||||
|
_, err := os.Stat("/dev/kvm")
|
||||||
|
return !os.IsNotExist(err)
|
||||||
|
}
|
||||||
|
|
||||||
func runQemu(args []string) {
|
func runQemu(args []string) {
|
||||||
invoked := filepath.Base(os.Args[0])
|
invoked := filepath.Base(os.Args[0])
|
||||||
flags := flag.NewFlagSet("qemu", flag.ExitOnError)
|
flags := flag.NewFlagSet("qemu", flag.ExitOnError)
|
||||||
@ -68,6 +73,7 @@ func runQemu(args []string) {
|
|||||||
fw := flags.String("fw", "/usr/share/ovmf/bios.bin", "Path to OVMF firmware for UEFI boot")
|
fw := flags.String("fw", "/usr/share/ovmf/bios.bin", "Path to OVMF firmware for UEFI boot")
|
||||||
|
|
||||||
// VM configuration
|
// VM configuration
|
||||||
|
enableKVM := flags.Bool("kvm", haveKVM(), "Enable KVM acceleration")
|
||||||
arch := flags.String("arch", "x86_64", "Type of architecture to use, e.g. x86_64, aarch64")
|
arch := flags.String("arch", "x86_64", "Type of architecture to use, e.g. x86_64, aarch64")
|
||||||
cpus := flags.String("cpus", "1", "Number of CPUs")
|
cpus := flags.String("cpus", "1", "Number of CPUs")
|
||||||
mem := flags.String("mem", "1024", "Amount of memory in MB")
|
mem := flags.String("mem", "1024", "Amount of memory in MB")
|
||||||
@ -185,6 +191,7 @@ func runQemu(args []string) {
|
|||||||
Arch: *arch,
|
Arch: *arch,
|
||||||
CPUs: *cpus,
|
CPUs: *cpus,
|
||||||
Memory: *mem,
|
Memory: *mem,
|
||||||
|
KVM: *enableKVM,
|
||||||
Containerized: *qemuContainerized,
|
Containerized: *qemuContainerized,
|
||||||
PublishedPorts: publishFlags,
|
PublishedPorts: publishFlags,
|
||||||
}
|
}
|
||||||
@ -343,14 +350,11 @@ func buildQemuCmdline(config QemuConfig) (QemuConfig, []string) {
|
|||||||
qemuArgs = append(qemuArgs, "-smp", config.CPUs)
|
qemuArgs = append(qemuArgs, "-smp", config.CPUs)
|
||||||
qemuArgs = append(qemuArgs, "-m", config.Memory)
|
qemuArgs = append(qemuArgs, "-m", config.Memory)
|
||||||
|
|
||||||
// Look for kvm device and enable for qemu if it exists
|
if config.KVM {
|
||||||
var err error
|
|
||||||
if _, err = os.Stat("/dev/kvm"); os.IsNotExist(err) {
|
|
||||||
qemuArgs = append(qemuArgs, "-machine", "q35")
|
|
||||||
} else {
|
|
||||||
config.KVM = true
|
|
||||||
qemuArgs = append(qemuArgs, "-enable-kvm")
|
qemuArgs = append(qemuArgs, "-enable-kvm")
|
||||||
qemuArgs = append(qemuArgs, "-machine", "q35,accel=kvm:tcg")
|
qemuArgs = append(qemuArgs, "-machine", "q35,accel=kvm:tcg")
|
||||||
|
} else {
|
||||||
|
qemuArgs = append(qemuArgs, "-machine", "q35")
|
||||||
}
|
}
|
||||||
|
|
||||||
for i, d := range config.Disks {
|
for i, d := range config.Disks {
|
||||||
|
Loading…
Reference in New Issue
Block a user