From: Daan De Meyer Date: Tue, 12 Apr 2022 11:58:58 +0000 (+0200) Subject: Add --qemu-kvm option X-Git-Tag: v13~50^2~10 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f1d87c852ed8dc6d748edec456ff039d8e39f34d;p=thirdparty%2Fmkosi.git Add --qemu-kvm option Allows running without KVM acceleration on machines that support KVM. Useful when trying to reproduce CI issues where KVM is not supported. --- diff --git a/NEWS.md b/NEWS.md index 8054657f7..247b99d78 100644 --- a/NEWS.md +++ b/NEWS.md @@ -15,6 +15,7 @@ mkosi won't automatically build new unified kernel images anymore when a kernel is updated or installed. To keep this behavior, you can install the kernel-install script manually via a skeleton tree. The original script can be found [here](https://github.com/systemd/mkosi/blob/3798eb0c2ebcdf7dac207a559a3cb5a65cdb77b0/mkosi/resources/dracut_unified_kernel_install.sh). +- Added QemuKvm option to configure whether to use KVM or not when running `mkosi qemu`. ## v12 diff --git a/mkosi.md b/mkosi.md index 0ad3f43be..9e54317d8 100644 --- a/mkosi.md +++ b/mkosi.md @@ -1095,6 +1095,12 @@ a machine ID. : When used with the `qemu` verb, this options sets `qemu`'s `-m` argument which controls the amount of guest's RAM. Defaults to `1G`. +`QemuKvm=`, `--qemu-kvm=` + +: When used with the `qemu` verb, this option specifies whether QEMU + should use KVM acceleration. Defaults to yes if the host machine + supports KVM acceleration, no otherwise. + `NspawnKeepUnit=`, `--nspawn-keep-unit` : When used, this option instructs underlying calls of systemd-nspawn to diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 96cded114..3e343e471 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -5624,6 +5624,8 @@ def create_parser() -> ArgumentParserMkosi: group.add_argument("--qemu-headless", action=BooleanAction, help="Configure image for qemu's -nographic mode") group.add_argument("--qemu-smp", help="Configure guest's SMP settings", metavar="SMP", default="2") group.add_argument("--qemu-mem", help="Configure guest's RAM size", metavar="MEM", default="1G") + group.add_argument("--qemu-kvm", action=BooleanAction, help="Configure whether to use KVM or not", + default=qemu_check_kvm_support()) group.add_argument( "--nspawn-keep-unit", action=BooleanAction, @@ -6638,6 +6640,9 @@ def load_args(args: argparse.Namespace) -> MkosiArgs: if args.base_image is not None: args.base_packages = False + if args.qemu_kvm and not qemu_check_kvm_support(): + die("Sorry, the host machine does not support KVM acceleration.") + return MkosiArgs(**vars(args)) @@ -7636,8 +7641,7 @@ def qemu_check_kvm_support() -> bool: @contextlib.contextmanager def run_qemu_cmdline(args: MkosiArgs) -> Iterator[List[str]]: - has_kvm = qemu_check_kvm_support() - accel = "kvm" if has_kvm else "tcg" + accel = "kvm" if args.qemu_kvm else "tcg" firmware, fw_supports_sb = find_qemu_firmware() @@ -7655,7 +7659,7 @@ def run_qemu_cmdline(args: MkosiArgs) -> Iterator[List[str]]: "virtio-rng-pci,rng=rng0,id=rng-device0", ] - if has_kvm: + if args.qemu_kvm: cmdline += ["-cpu", "host"] if args.qemu_headless: diff --git a/mkosi/backend.py b/mkosi/backend.py index 36c856f99..d424a2717 100644 --- a/mkosi/backend.py +++ b/mkosi/backend.py @@ -516,6 +516,7 @@ class MkosiArgs: qemu_headless: bool qemu_smp: str qemu_mem: str + qemu_kvm: bool # systemd-nspawn specific options nspawn_keep_unit: bool diff --git a/tests/test_config_parser.py b/tests/test_config_parser.py index 7f8e1bd56..ee1b01a0d 100644 --- a/tests/test_config_parser.py +++ b/tests/test_config_parser.py @@ -132,6 +132,7 @@ class MkosiConfig: "qemu_headless": False, "qemu_smp": "2", "qemu_mem": "1G", + "qemu_kvm": mkosi.qemu_check_kvm_support(), "nspawn_keep_unit": False, "netdev": False, "ephemeral": False,