Skip to content

Instantly share code, notes, and snippets.

@pekeq
Last active March 21, 2025 14:07
Show Gist options
  • Save pekeq/9c5d415f8a5a41aca4117eeaad7ccde1 to your computer and use it in GitHub Desktop.
Save pekeq/9c5d415f8a5a41aca4117eeaad7ccde1 to your computer and use it in GitHub Desktop.
btrfs-balance
#!/bin/sh
mount | grep ' type btrfs ' | awk -F' ' '{print $3}' | while read dir
do
# Run "btrfs balance" on mounted btrfs with following formula:
# https://github.com/netdata/netdata/issues/3203#issuecomment-356026930
btrfs balance start -dusage=50 -dlimit=2 -musage=50 -mlimit=4 "${dir}"
# Trim unused blocks
fstrim --verbose "${dir}"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment