diff --git a/virtme/commands/run.py b/virtme/commands/run.py index 8cecb07..29a86fe 100644 --- a/virtme/commands/run.py +++ b/virtme/commands/run.py @@ -98,6 +98,8 @@ def make_parser() -> argparse.ArgumentParser: help='Use the specified busybox binary.') g = parser.add_argument_group(title='Virtualizer settings') + g.add_argument('--qemu-bin', action='store', default=None, + help="Use specified QEMU binary.") g.add_argument('-q', '--qemu-opt', action='append', default=[], help="Add a single QEMU argument. Use this when --qemu-opts's greedy behavior is problematic.'") g.add_argument('--qemu-opts', action='store', nargs=argparse.REMAINDER, @@ -285,7 +287,7 @@ def do_it() -> int: arch = architectures.get(args.arch) is_native = (args.arch == uname.machine) - qemu = qemu_helpers.Qemu(arch.qemuname) + qemu = qemu_helpers.Qemu(args.qemu_bin, arch.qemuname) qemu.probe() need_initramfs = args.force_initramfs or qemu.cannot_overmount_virtfs diff --git a/virtme/qemu_helpers.py b/virtme/qemu_helpers.py index 96ed693..76a597c 100644 --- a/virtme/qemu_helpers.py +++ b/virtme/qemu_helpers.py @@ -15,14 +15,20 @@ class Qemu(object): qemubin: str version: Optional[str] - def __init__(self, arch) -> None: + def __init__(self, qemubin, arch) -> None: self.arch = arch - qemubin = shutil.which('qemu-system-%s' % arch) - if qemubin is None and arch == os.uname().machine: - qemubin = shutil.which('qemu-kvm') - if qemubin is None: - raise ValueError('cannot find qemu for %s' % arch) + if not qemubin: + qemubin = shutil.which('qemu-system-%s' % arch) + if qemubin is None and arch == os.uname().machine: + qemubin = shutil.which('qemu-kvm') + if qemubin is None: + raise ValueError('cannot find qemu for %s' % arch) + else: + if not os.path.isfile(qemubin): + raise ValueError('specified qemu binary "%s" does not exist' % qemubin) + if not os.access(qemubin, os.X_OK): + raise ValueError('specified qemu binary "%s" is not executable' % qemubin) self.qemubin = qemubin self.version = None