#!/bin/bash [[ $UID -ne 0 ]] && exec sudo "$0" trap 'echo -e "\nInterrupted!"; exit 1' INT TERM die() { cat << EOF +----------------------+ | There were errors! | +----------------------+ EOF exit 1 } mapfile -t mountpoints < <( findmnt --types btrfs --nofsroot --noheading --output SOURCE | sort -u | while IFS= read -r device; do findmnt --source "$device" --output TARGET --noheading | head -1 done ) for mount in "${mountpoints[@]}"; do echo "=== Working on '$mount':" #for x in 0 1 5 10 20 30; do for x in 5; do echo "* Metadata balancing, usage=$x..." btrfs balance start -musage="$x" "$mount" || die done #for x in 0 1 5 10 20 30 40 50; do for x in 5 10; do echo "* Data balancing, usage=$x..." btrfs balance start -dusage="$x" "$mount" || die done done