From 3b9ba32efbcb350e1340fda91566b2c7b1782ecc Mon Sep 17 00:00:00 2001 From: Daan De Meyer Date: Tue, 23 Jul 2024 22:36:55 +0200 Subject: [PATCH] If the image is nocow, make the ephemeral copy nocow as well 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. --- mkosi/qemu.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/mkosi/qemu.py b/mkosi/qemu.py index e62db3f41..b6d3bb036 100644 --- a/mkosi/qemu.py +++ b/mkosi/qemu.py @@ -533,6 +533,19 @@ def copy_ephemeral(config: Config, src: Path) -> Iterator[Path]: 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, -- 2.47.3