On btrfs, VM images are generally recommended to be made nocow as
cow (copy-on-write) and random writes don't play well together. Let's
take this into account in copy_ephemeral() and make the ephemeral
copy nocow as well if the source is nocow.
def copy() -> None:
if config.output_format == OutputFormat.directory:
become_root()
+ elif config.output_format in (OutputFormat.disk, OutputFormat.esp):
+ attr = run(
+ ["lsattr", "-l", src],
+ sandbox=config.sandbox(binary="lsattr", mounts=[Mount(src, src, ro=True)]),
+ stdout=subprocess.PIPE,
+ ).stdout
+
+ if "No_COW" in attr:
+ tmp.touch()
+ run(
+ ["chattr", "+C", tmp],
+ sandbox=config.sandbox(binary="chattr", mounts=[Mount(tmp, tmp)]),
+ )
copy_tree(
src, tmp,