"--dev", root / "dev",
# Make sure /etc/machine-id is not overwritten by any package manager post install scripts.
"--ro-bind-try", root / "etc/machine-id", root / "etc/machine-id",
+ # Nudge gpg to create its sockets in /run by making sure /run/user/0 exists.
+ "--dir", root / "run/user/0",
*finalize_passwd_mounts(root),
"sh", "-c",
f"chmod 1777 {root / 'tmp'} {root / 'var/tmp'} {root / 'dev/shm'} && "
from mkosi.sandbox import SandboxProtocol, nosandbox
from mkosi.types import PathString
from mkosi.util import flatten
+from mkosi.versioncomp import GenericVersion
def statfs(path: Path, *, sandbox: SandboxProtocol = nosandbox) -> str:
return path.is_dir() and statfs(path, sandbox=sandbox) == "btrfs" and path.stat().st_ino == 256
+def cp_version() -> GenericVersion:
+ return GenericVersion(run(["cp", "--version"], stdout=subprocess.PIPE).stdout.splitlines()[0].split()[3])
+
+
def make_tree(
path: Path,
*,
"--dereference" if dereference else "--no-dereference",
f"--preserve=mode,links{',timestamps,ownership,xattr' if preserve else ''}",
"--reflink=auto",
+ "--copy-contents",
src, dst,
]
+ if cp_version() >= "9.5":
+ copy += ["--keep-directory-symlink"]
+
options: list[PathString] = ["--ro-bind", src, src, "--bind", dst.parent, dst.parent]
# If the source and destination are both directories, we want to merge the source directory with the