from mkosi.kmod import gen_required_kernel_modules, process_kernel_modules
from mkosi.log import complete_step, die, log_step
from mkosi.manifest import Manifest
-from mkosi.mounts import mount_overlay, mount_passwd, mount_tools
+from mkosi.mounts import mount_overlay, mount_passwd, mount_usr
from mkosi.pager import page
from mkosi.qemu import copy_ephemeral, run_qemu, run_ssh
from mkosi.run import become_root, bwrap, chroot_cmd, init_mount_namespace, run
continue
with complete_step(f"Building {config.preset or 'default'} image"),\
- mount_tools(config),\
+ mount_usr(config.tools_tree),\
prepend_to_environ_path(config):
# Create these as the invoking user to make sure they're owned by the user running mkosi.
# We want to drop privileges after mounting the last tools tree, but to unmount it we still need
# privileges. To avoid a permission error, let's not unmount the final tools tree, since we'll exit
# right after (and we're in a mount namespace so the /usr mount disappears when we exit)
- with mount_tools(last, umount=False), mount_passwd(name, uid, gid, umount=False):
+ with mount_usr(last.tools_tree, umount=False), mount_passwd(name, uid, gid, umount=False):
# After mounting the last tools tree, if we're not going to execute systemd-nspawn, we don't need to
# be (fake) root anymore, so switch user to the invoking user.
from pathlib import Path
from typing import Optional, TypeVar
-from mkosi.config import GenericVersion, MkosiConfig
+from mkosi.config import GenericVersion
from mkosi.log import complete_step
from mkosi.run import run
from mkosi.types import PathString
@contextlib.contextmanager
-def mount_tools(config: MkosiConfig, umount: bool = True) -> Iterator[None]:
- if not config.tools_tree:
+def mount_usr(tree: Optional[Path], umount: bool = True) -> Iterator[None]:
+ if not tree:
yield
return
- # If a tools tree is specified, we should ignore any local modifications made to PATH as any of those
- # binaries might not work anymore when /usr is replaced wholesale. We also make sure that both /usr/bin
- # and /usr/sbin/ are searched so that e.g. if the host is Arch and the root is Debian we don't ignore the
+ # If we replace /usr, we should ignore any local modifications made to PATH as any of those binaries
+ # might not work anymore when /usr is replaced wholesale. We also make sure that both /usr/bin and
+ # /usr/sbin/ are searched so that e.g. if the host is Arch and the root is Debian we don't ignore the
# binaries from /usr/sbin in the Debian root.
old = os.environ["PATH"]
os.environ["PATH"] = "/usr/bin:/usr/sbin"
# If we mounted over /usr, trying to use umount will fail with "target is busy", because umount is
# being called from /usr, which we're trying to unmount. To work around this issue, we do a lazy
# unmount.
- with mount(what=config.tools_tree / "usr", where=Path("/usr"), operation="--bind", read_only=True, umount=umount, lazy=True):
+ with mount(what=tree / "usr", where=Path("/usr"), operation="--bind", read_only=True, umount=umount, lazy=True):
yield
finally:
os.environ["PATH"] = old