diff --git a/virtme/commands/run.py b/virtme/commands/run.py index 9919352..8210e6e 100644 --- a/virtme/commands/run.py +++ b/virtme/commands/run.py @@ -233,6 +233,11 @@ def make_parser() -> argparse.ArgumentParser: action="store_true", help='Avoid using the "microvm" QEMU architecture (only on x86_64)', ) + g.add_argument( + "--disable-kvm", + action="store_true", + help='Avoid using hardware virtualization / KVM', + ) g.add_argument( "--force-initramfs", action="store_true", @@ -720,7 +725,9 @@ def sanitize_disk_args(func: str, arg: str) -> Tuple[str, str]: return name, fn -def can_use_kvm(): +def can_use_kvm(args): + if args.disable_kvm: + return False if not os.path.exists("/dev/kvm"): return False try: @@ -733,7 +740,7 @@ def can_use_kvm(): def can_use_microvm(args): - return not args.disable_microvm and not args.numa and args.arch == "x86_64" and can_use_kvm() + return not args.disable_microvm and not args.numa and args.arch == "x86_64" and can_use_kvm(args) def has_read_acl(username, file_path): @@ -963,7 +970,7 @@ def do_it() -> int: kernelargs.append("virtme_rw_overlay%d=%s" % (i, d)) # Turn on KVM if available - kvm_ok = can_use_kvm() + kvm_ok = can_use_kvm(args) if is_native and kvm_ok: qemuargs.extend(["-machine", "accel=kvm:tcg"]) diff --git a/virtme_ng/run.py b/virtme_ng/run.py index 4672b38..c8fb912 100644 --- a/virtme_ng/run.py +++ b/virtme_ng/run.py @@ -235,6 +235,12 @@ def make_parser(): help='Avoid using the "microvm" QEMU architecture (only on x86_64)', ) + parser.add_argument( + "--disable-kvm", + action="store_true", + help='Avoid using hardware virtualization / KVM', + ) + parser.add_argument( "--cwd", action="store", @@ -855,6 +861,12 @@ def _get_virtme_disable_microvm(self, args): else: self.virtme_param["disable_microvm"] = "" + def _get_virtme_disable_kvm(self, args): + if args.disable_kvm: + self.virtme_param["disable_kvm"] = "--disable-kvm" + else: + self.virtme_param["disable_kvm"] = "" + def _get_virtme_9p(self, args): if args.force_9p: self.virtme_param["force_9p"] = "--force-9p" @@ -965,6 +977,7 @@ def run(self, args): self._get_virtme_disk(args) self._get_virtme_sound(args) self._get_virtme_disable_microvm(args) + self._get_virtme_disable_kvm(args) self._get_virtme_9p(args) self._get_virtme_initramfs(args) self._get_virtme_graphics(args) @@ -1000,6 +1013,7 @@ def run(self, args): + f'{self.virtme_param["disk"]} ' + f'{self.virtme_param["sound"]} ' + f'{self.virtme_param["disable_microvm"]} ' + + f'{self.virtme_param["disable_kvm"]} ' + f'{self.virtme_param["force_9p"]} ' + f'{self.virtme_param["force_initramfs"]} ' + f'{self.virtme_param["graphics"]} '