From 5f624dba91274fdb2266009ba91eb4a0fefdeb16 Mon Sep 17 00:00:00 2001 From: Adrian Vladu Date: Mon, 1 Jul 2024 15:30:08 +0300 Subject: [PATCH] build_image: btrfs: minimize allocation Rebalance the /usr btrfs allocation to the maximum possible, in order to increase the chance of having the btrfs `Free (statfs, df)` similar to `Free (estimated)`. Note that /usr is also a zstd compressed btrfs partition, so the output of `df` free size and the actual free size after a file write for example, will be very different, because the data in that file write has a compression rate only definable after the file sync. Unfortunately, there is no determinism in the btrfs file system case, because even if you could in theory pre-compress with zstd the file before, and have an idea about the size to be used, you still cannot really predict also the metadata size for that file write. See: https://github.com/flatcar/Flatcar/issues/1473 Signed-off-by: Adrian Vladu --- build_library/disk_util | 1 + 1 file changed, 1 insertion(+) diff --git a/build_library/disk_util b/build_library/disk_util index f94317e3c1d..2f6427a1e8a 100755 --- a/build_library/disk_util +++ b/build_library/disk_util @@ -661,6 +661,7 @@ def ReadWriteSubvol(options, partition, disable_rw): btrfs_mount = tempfile.mkdtemp() Sudo(['mount', '-t', 'btrfs', loop_dev, btrfs_mount]) try: + Sudo(['btrfs', 'balance', 'start', '-dusage=0', '-musage=0', btrfs_mount]) Sudo(['btrfs', 'property', 'set', '-ts', btrfs_mount, 'ro', 'true' if disable_rw else 'false']) finally: Sudo(['umount', btrfs_mount])