Btrfs Auto Balancer (btrfs-auto-balancer)
Btrfs Auto Balancer is a Python utility that automates the balancing process for Btrfs filesystems. It dynamically adjusts usage thresholds while providing real-time status updates, ensuring efficient storage utilization and improved system performance on your Linux system. ⚙️💾
🧭 How it works
flowchart TD
A["btrfs-auto-balancer COUNTDOWN STEP"] --> B{"--drive_path given?"}
B -- yes --> D["take that mount point"]
B -- no --> C["findmnt -t btrfs"]
C --> C2{"any btrfs mount found?"}
C2 -- no --> X["No Btrfs filesystems found - exit 1"]
C2 -- yes --> D
D --> E{"countdown greater than 5?"}
E -- no --> Z["next mount, or exit 0"]
E -- yes --> F["btrfs balance start -dusage=N -musage=N"]
F --> G{"balance process still running?"}
G -- yes --> H["btrfs fi df + btrfs balance status, wait 2s"]
H --> G
G -- no --> I["countdown = countdown - STEP"]
I --> E
btrfs-auto-balancer 20 5 therefore runs three passes, at -dusage=20, 15 and 10, and stops before reaching the minimum of 5.
🎯 Purpose
Btrfs Auto Balancer simplifies Btrfs volume maintenance by automating the balance process. It dynamically decrements usage thresholds (for both data and metadata) and displays real-time status updates during balancing operations. Whether you're managing a single drive or all mounted Btrfs filesystems, this tool helps keep your system optimized.
🚀 Features
- Dynamic Balancing: Automatically decrements disk usage thresholds during balancing operations. 🔄
- Real-Time Monitoring: Continuously displays current Btrfs filesystem status and balance progress. 📊
- Multi-Drive Support: Balances a specific drive if provided, or processes all mounted Btrfs volumes if no drive is specified. 💻
- Flexible Parameters: Easily adjust initial thresholds and decrement steps to suit your system's needs. 🔧
🛠 Requirements
- Python 3.10+ 🐍
- Linux Operating System 🐧
findmntonPATH— discovers the mounted Btrfs filesystems (util-linux)btrfsonPATH— runs the balance and reports its status (btrfs-progs)- root privileges for the balance itself
If a required command is missing, the tool exits with code 127 and a one‑line error instead of a traceback.
📥 Installation
pip install btrfs-auto-balancer
pip is the single supported installation path.
The package installs two identical commands: btrfs-auto-balancer (primary) and btrfsauba (kept for older documentation and scripts).
🚀 Usage
Balancing a Specific Btrfs Drive
sudo btrfs-auto-balancer <countdown> <count_down_step> --drive_path <drive_path>
Balancing All Mounted Btrfs Drives
sudo btrfs-auto-balancer <countdown> <count_down_step>
Replace <countdown> with the initial usage threshold (for both data and metadata) and <count_down_step> with the decrement step for each balance iteration. Both must be greater than zero — a step of 0 would loop forever and is rejected.
Balancing stops once the threshold drops to 5 or below. btrfs-auto-balancer 20 5 therefore runs three passes, at -dusage=20, 15 and 10.
Exit codes
| Code | Meaning |
|---|---|
0 |
Finished. |
1 |
No Btrfs filesystem was found. |
2 |
Invalid command line arguments, including a countdown or step of zero or less. |
127 |
A required command is not installed. |
🧪 Development
make lint # ruff check + ruff format --check
make format # apply ruff format
make test # unit + integration tests
make test-unit
make test-integration
make test-e2e # install the package in a container and exercise the CLI
Tests run against the working tree — the Makefile puts src/ on PYTHONPATH, so no install is needed. The integration tests stub findmnt on PATH, so no real filesystem is ever touched.
📜 License
This project is licensed under the GNU Affero General Public License v3.0. See the LICENSE file for details.
👨💻 Author
Developed by Kevin Veen-Birkenbach
- Email: kevin@veen.world
- Website: https://www.veen.world/
Happy balancing! ⚖️💡
Metadata
Release files for btrfs-auto-balancer 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| btrfs_auto_balancer-1.0.0.tar.gz | 21.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| btrfs_auto_balancer-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 39.7 kB
Release files / btrfs_auto_balancer-1.0.0.tar.gz
| Download URL | btrfs_auto_balancer-1.0.0.tar.gz |
|---|---|
| Size | 21.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7afd7c7c7d79e0f381d7076785f58b9e6b00e9e0dfe92e3a999bc0f46400d30f
|
|
BLAKE2b-256 checksum How to use checksums |
958ab9758a576629714f930b32c3ba683e7ab83c2ff47a3a4172a3a982a3bf4a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Release files / btrfs_auto_balancer-1.0.0-py3-none-any.whl
| Download URL | btrfs_auto_balancer-1.0.0-py3-none-any.whl |
|---|---|
| Size | 18.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3f7380fd0c5fa1ce3bf770b19950e29552bff49da6173f8a361853416d8893bf
|
|
BLAKE2b-256 checksum How to use checksums |
0d048a2b0cf2fb3c270ed3f11f59c1583cee194b20525e1fdf2bbde1f69a1846
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|