From ad734333a67e4e2e912e0c079e7533c3119ae684 Mon Sep 17 00:00:00 2001 From: Harald Sitter Date: Wed, 6 Nov 2024 15:31:28 +0100 Subject: [PATCH] use smarter logic for shrinking the btrfs size is only approximate and depending on how big a number it is the 512M buffer may not be enough --- btrfs-shrink.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/btrfs-shrink.py b/btrfs-shrink.py index 06fda14..6b4f32e 100755 --- a/btrfs-shrink.py +++ b/btrfs-shrink.py @@ -10,6 +10,7 @@ import json import os +import math import subprocess from subprocess import check_output @@ -21,8 +22,8 @@ size = 0 for block_group in df: size += block_group["total"] -# Give 512MiB of buffer space. We'll shrink from there in smaller steps. -size += 512 * 1024 * 1024 +# Give 10% buffer space. We'll shrink from there in smaller steps. +size = max(512 * 1024 * 1024, math.ceil(size * 1.1)) subprocess.run(["btrfs", "filesystem", "resize", str(size), "."], check=True)