From: Jacob Emmert-Aronson Date: Sat, 23 Jul 2022 04:34:58 +0000 (-0700) Subject: Allow running qemu as an unprivileged user X-Git-Tag: v14~99^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=569a4ebe560dcffced9429316eedb0acc37318f2;p=thirdparty%2Fmkosi.git Allow running qemu as an unprivileged user --- diff --git a/mkosi.md b/mkosi.md index b07effefe..d79135745 100644 --- a/mkosi.md +++ b/mkosi.md @@ -85,6 +85,9 @@ The following command line verbs are known: only supported on images that contain a boot loader, i.e. those built with `Bootable=yes` (see below). This command must be executed as `root` unless the image already exists and `-f` is not specified. + Some qemu arguments (such as those set by `Netdev=yes`) may also + prevent qemu from starting when this command is executed by a + non-root user. `ssh` diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 30269740a..56cceaa01 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -125,7 +125,7 @@ SomeIO = Union[BinaryIO, TextIO] PathString = Union[Path, str] MKOSI_COMMANDS_NEED_BUILD = (Verb.shell, Verb.boot, Verb.qemu, Verb.serve) -MKOSI_COMMANDS_SUDO = (Verb.build, Verb.clean, Verb.shell, Verb.boot, Verb.qemu, Verb.serve) +MKOSI_COMMANDS_SUDO = (Verb.build, Verb.clean, Verb.shell, Verb.boot, Verb.serve) MKOSI_COMMANDS_CMDLINE = (Verb.build, Verb.shell, Verb.boot, Verb.qemu, Verb.ssh) DRACUT_SYSTEMD_EXTRAS = [ @@ -6041,9 +6041,6 @@ def empty_directory(path: Path) -> None: def unlink_output(args: MkosiArgs) -> None: - if not args.force and args.verb != Verb.clean: - return - if not args.skip_final_phase: with complete_step("Removing output files…"): unlink_try_hard(args.output) @@ -8115,16 +8112,18 @@ def run_verb(raw: argparse.Namespace) -> None: if args.verb in MKOSI_COMMANDS_SUDO: check_root() - unlink_output(args) - if args.verb == Verb.build: + if args.verb == Verb.build and not args.force: check_output(args) + if needs_build(args) or args.verb == Verb.clean: + check_root() + unlink_output(args) + if args.verb == Verb.summary: print_summary(args) if needs_build(args): - check_root() check_native(args) init_namespace(args) manifest = build_stuff(args) diff --git a/mkosi/machine.py b/mkosi/machine.py index 3133f8b33..14e25e18e 100644 --- a/mkosi/machine.py +++ b/mkosi/machine.py @@ -15,7 +15,7 @@ from typing import Any, Iterator, Optional, Sequence, TextIO, Union import pexpect # type: ignore from . import ( - MKOSI_COMMANDS_SUDO, + MKOSI_COMMANDS_NEED_BUILD, CompletedProcess, build_stuff, check_native, @@ -106,7 +106,7 @@ class Machine: assert self._serial is not None or self.args.verb == Verb.shell def build(self) -> None: - if self.args.verb in MKOSI_COMMANDS_SUDO: + if self.args.verb in MKOSI_COMMANDS_NEED_BUILD + (Verb.build, Verb.clean): check_root() unlink_output(self.args)