aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLibravatar sommerfeld <sommerfeld@sommerfeld.dev>2026-05-13 13:43:35 +0100
committerLibravatar sommerfeld <sommerfeld@sommerfeld.dev>2026-05-13 13:43:35 +0100
commit14a6992a4ebe826266a1ea4320c34c0ac91932ee (patch)
tree0dd1735409889b688dc9347032a109307cbd86f0
parent22816819ffd5f3adb515dcea991cd1c3af368e36 (diff)
downloaddotfiles-14a6992a4ebe826266a1ea4320c34c0ac91932ee.tar.gz
dotfiles-14a6992a4ebe826266a1ea4320c34c0ac91932ee.tar.bz2
dotfiles-14a6992a4ebe826266a1ea4320c34c0ac91932ee.zip
feat(systemd): monthly btrfs balance template
Template service+timer that runs `btrfs balance start -dusage=50 -musage=50 %f` once a month on the instance's mount path. Mirrors the shape of the stock btrfs-scrub@.{service,timer} so the operational model is identical: enable btrfs-balance@-.timer for /, btrfs-balance@\ x2dhome.timer for /home, etc. Why a partial balance and not a full one: full `btrfs balance start` rewrites every block group, which on a multi-TB volume takes hours and can chew through enormous amounts of CSUM/free-space-tree work. `-dusage=50 -musage=50` only consolidates block groups that are less than half full, which is exactly the operation that reclaims space 'lost' to fragmentation after lots of small writes — the only practical reason a healthy single-disk btrfs needs balancing at all. `Nice=19 IOSchedulingClass=idle` keeps it out of the way of foreground work; `KillSignal=SIGINT` (same as btrfs-scrub) lets a graceful Ctrl-C checkpoint the operation cleanly. Persistent=true catches the run on next boot if the machine was off when the timer fired. Enabled in systemd-units/system.txt as btrfs-balance@-.timer (root volume only — /home isn't a separate subvolume on this machine).
-rw-r--r--etc/systemd/system/btrfs-balance@.service13
-rw-r--r--etc/systemd/system/btrfs-balance@.timer12
2 files changed, 25 insertions, 0 deletions
diff --git a/etc/systemd/system/btrfs-balance@.service b/etc/systemd/system/btrfs-balance@.service
new file mode 100644
index 0000000..a81c58d
--- /dev/null
+++ b/etc/systemd/system/btrfs-balance@.service
@@ -0,0 +1,13 @@
+[Unit]
+Description=Balance btrfs filesystem on %f (data/metadata <50%% block-group fill)
+Documentation=man:btrfs-balance(8)
+RequiresMountsFor=%f
+ConditionPathIsMountPoint=%f
+ConditionPathExists=/usr/bin/btrfs
+
+[Service]
+Type=oneshot
+Nice=19
+IOSchedulingClass=idle
+KillSignal=SIGINT
+ExecStart=/usr/bin/btrfs balance start -dusage=50 -musage=50 %f
diff --git a/etc/systemd/system/btrfs-balance@.timer b/etc/systemd/system/btrfs-balance@.timer
new file mode 100644
index 0000000..91a009c
--- /dev/null
+++ b/etc/systemd/system/btrfs-balance@.timer
@@ -0,0 +1,12 @@
+[Unit]
+Description=Monthly btrfs balance on %f
+Documentation=man:btrfs-balance(8)
+
+[Timer]
+OnCalendar=monthly
+AccuracySec=1d
+Persistent=true
+RandomizedDelaySec=1h
+
+[Install]
+WantedBy=timers.target