[elbe-devel] [PATCH 2/3] elbepack: init: qemu: autodetect KVM availability
Thomas Weißschuh
thomas.weissschuh at linutronix.de
Thu May 16 12:14:29 CEST 2024
Not all environments have KVM available, but want to run ELBE
nevertheless. While it may be slow, it's better than nothing.
Signed-off-by: Thomas Weißschuh <thomas.weissschuh at linutronix.de>
---
elbepack/init/Makefile.mako | 18 +++++++++---------
elbepack/xmldefaults.py | 1 -
2 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/elbepack/init/Makefile.mako b/elbepack/init/Makefile.mako
index a05edbffbb5d..fd635e50838d 100644
--- a/elbepack/init/Makefile.mako
+++ b/elbepack/init/Makefile.mako
@@ -5,18 +5,25 @@
<%
import multiprocessing
+import os
+import subprocess
from elbepack.filesystem import size_to_int
max_cpus = int(prj.text('max-cpus', default=defs, key='max-cpus'))
memory = size_to_int(prj.text('mem', default=defs, key='mem')) // 1024 // 1024
+interpreter = prj.text('interpreter', default=defs, key='interpreter')
+use_kvm = os.path.exists('/dev/kvm') and b'kvm' in subprocess.check_output([interpreter, '-accel', 'help'])
%>
MEMSIZE?=${memory}
SMP?=$$((`nproc` > ${max_cpus} ? ${max_cpus} : `nproc`))
-INTERPRETER?=${prj.text('interpreter', default=defs, key='interpreter')}
+INTERPRETER?=${interpreter}
% if defs["interpreter-args"] is not None:
INTERPRETER-ARGS= ${" ".join(defs["interpreter-args"])}
% endif
+% if use_kvm:
+INTERPRETER-ARGS+= -accel kvm -cpu host
+% endif
MACHINE?=pc
CONSOLE?=ttyS0,115200n1
@@ -82,13 +89,9 @@ $(BASE): $(INITRD)
-m $(MEMSIZE) \
-smp $(SMP) \
-usb \
- -cpu host \
|| ( echo; \
echo "------------------------------------------------------------------"; \
- echo "kvm failed to start"; \
- echo "This is most likely the case, because /dev/kvm is not available."; \
- echo "To use KVM inside a VMWARE or other VM instance,"; \
- echo "nested KVM needs to be supported"; \
+ echo "VM failed to start"; \
echo "------------------------------------------------------------------"; \
echo; \
false \
@@ -111,7 +114,6 @@ run:
-drive file=$(INITVM),if=$(HD_TYPE),bus=1,unit=0 \
-no-reboot \
-netdev user,ipv4,id=user.0${fwd} \
- -cpu host \
-m $(MEMSIZE) \
-usb \
-smp $(SMP)
@@ -124,7 +126,6 @@ run-con:
-drive file=$(INITVM),if=$(HD_TYPE),bus=1,unit=0 \
-no-reboot \
-netdev user,ipv4,id=user.0${fwd} \
- -cpu host \
-m $(MEMSIZE) \
-usb \
-nographic \
@@ -142,7 +143,6 @@ run_qemu:
-drive file=$(INITVM),if=$(HD_TYPE),bus=1,unit=0 \
-no-reboot \
-netdev user,ipv4=on,id=user.0,hostfwd=tcp::7587-:7588${fwd} \
- -cpu host \
-m $(MEMSIZE) \
-usb \
-smp $(SMP)
diff --git a/elbepack/xmldefaults.py b/elbepack/xmldefaults.py
index 393535737ef8..dc43081c1fc7 100644
--- a/elbepack/xmldefaults.py
+++ b/elbepack/xmldefaults.py
@@ -128,7 +128,6 @@ ppc64el_defaults = {
amd64_defaults = {
'arch': 'amd64',
'interpreter': 'qemu-system-x86_64',
- 'interpreter-args': ['-accel', 'kvm'],
'console': 'ttyS0,115200n1',
'machine': 'pc',
'nicmodel': 'virtio',
--
2.45.0
More information about the elbe-devel
mailing list