From 61fb76f19da7afc00fdec4fa265f474f417fe0d5 Mon Sep 17 00:00:00 2001 From: Harald Sitter Date: Wed, 6 Nov 2024 18:08:16 +0100 Subject: [PATCH] fully balance before shrink when looking at a heatmap of the partition it's still not quite ideal, when I manually shrink it I get a better block layout, so let's try to balance the blocks before shrinking. if nothing else it should mean less relocation during shrinking --- btrfs-send-receive.sh | 3 +++ btrfs-shrink.py | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/btrfs-send-receive.sh b/btrfs-send-receive.sh index b93e47d..2e21803 100755 --- a/btrfs-send-receive.sh +++ b/btrfs-send-receive.sh @@ -57,6 +57,9 @@ btrfs filesystem usage . duperemove -dr . > /dev/null btrfs subvolume sync . btrfs filesystem sync . +btrfs balance start --full-balance --enqueue . +btrfs subvolume sync . +btrfs filesystem sync . ## And to finish things off we shrink the filesystem to the minimum size. $OUTPUT_DIR/btrfs-shrink.py ## Sync changes to disk. diff --git a/btrfs-shrink.py b/btrfs-shrink.py index 6b4f32e..b8b8085 100755 --- a/btrfs-shrink.py +++ b/btrfs-shrink.py @@ -8,6 +8,11 @@ # portion but leave a bit of a buffer behind. Then we keep resizing until the # resize starts failing. +# TODO we can produce an even more squeezed image by deriving a complete partition +# from the initial partition. https://btrfs.readthedocs.io/en/latest/Seeding-device.html +# It essentially transfers the data from the seed device with nary a fragmentation. +# Requires juggling loop devices though, and the gains are in the sub 500MiB range. + import json import os import math