From: Michael A Cassaniti Date: Mon, 18 Jul 2022 01:26:28 +0000 (+1000) Subject: Fixed running prepare and post-install scripts when UsrOnly is in use X-Git-Tag: v14~126 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a033168428ab39ea2a696f232f26649a9a294167;p=thirdparty%2Fmkosi.git Fixed running prepare and post-install scripts when UsrOnly is in use Includes moving root_home() to backend --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 1f3b93957..7eb9326d7 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -89,6 +89,7 @@ from .backend import ( nspawn_version, patch_file, path_relative_to_cwd, + root_home, run, run_workspace_command, set_umask, @@ -1776,20 +1777,6 @@ def prepare_tree_root(args: MkosiArgs, root: Path) -> None: btrfs_subvol_create(root) -def root_home(args: MkosiArgs, root: Path) -> Path: - - # If UsrOnly= is turned on the /root/ directory (i.e. the root - # user's home directory) is not persistent (after all everything - # outside of /usr/ is not around). In that case let's mount it in - # from an external place, so that we can have persistency. It is - # after all where we place our build sources and suchlike. - - if args.usr_only: - return workspace(root) / "home-root" - - return root / "root" - - def prepare_tree(args: MkosiArgs, root: Path, do_run_build_script: bool, cached: bool) -> None: if cached: # Reuse machine-id from cached image. diff --git a/mkosi/backend.py b/mkosi/backend.py index 831aa2a24..2c0605353 100644 --- a/mkosi/backend.py +++ b/mkosi/backend.py @@ -675,6 +675,9 @@ def run_workspace_command( stdout = subprocess.PIPE nspawn += ["--console=pipe"] + if args.usr_only: + nspawn += [f"--bind={root_home(args, root)}:/root"] + if args.nspawn_keep_unit: nspawn += ["--keep-unit"] @@ -686,6 +689,20 @@ def run_workspace_command( die(f"Workspace command {shell_join(cmd)} returned non-zero exit code {e.returncode}.") +def root_home(args: MkosiArgs, root: Path) -> Path: + + # If UsrOnly= is turned on the /root/ directory (i.e. the root + # user's home directory) is not persistent (after all everything + # outside of /usr/ is not around). In that case let's mount it in + # from an external place, so that we can have persistency. It is + # after all where we place our build sources and suchlike. + + if args.usr_only: + return workspace(root) / "home-root" + + return root / "root" + + @contextlib.contextmanager def do_delay_interrupt() -> Iterator[None]: # CTRL+C is sent to the entire process group. We delay its handling in mkosi itself so the subprocess can