html
When working with Btrfs filesystems, quota management is handled through qgroups (quota groups). Unlike traditional filesystems where quotas are set per user/group, Btrfs implements quotas at the subvolume level using this hierarchical grouping system.
Here are the essential commands you'll need:
# Enable quotas (required before first use)
sudo btrfs quota enable /path
# Set a quota limit (e.g., 21GB for subvolume)
sudo btrfs qgroup limit 21G /path/to/subvolume
# Show current usage
sudo btrfs qgroup show -re /path
While btrfs qgroup show
displays usage statistics, it doesn't explicitly show the configured limit. To view both usage and limits:
# The most comprehensive view:
sudo btrfs qgroup show -reF /path
# Sample output format:
# Qgroupid Referenced Max referenced Exclusive Max exclusive
# -------- ---------- -------------- --------- -------------
# 0/5 15.00GiB 21.00GiB 14.50GiB 20.00GiB
For scripting purposes, you might prefer these approaches:
# JSON output for parsing (Btrfs v5.6+)
sudo btrfs qgroup show -pcre --raw /path | jq
# Filter specific qgroup info
sudo btrfs qgroup show -re /path | awk '/0\/[0-9]+/ {print "Limit:", $4}'
Remember these technical details:
- Quotas must be enabled for the filesystem before use
- All values are shown in binary units (1GiB = 1024^3 bytes)
- The
Max referenced
column shows your configured limit - Quotas apply to the entire subvolume, including snapshots
Here's how I typically manage quotas in production:
# 1. Enable quotas if not already active
if ! btrfs quota show /mnt/data &> /dev/null; then
sudo btrfs quota enable /mnt/data
fi
# 2. Set a 50GB limit for a project subvolume
sudo btrfs qgroup limit 50G /mnt/data/projects/webapp
# 3. Verify the configuration
sudo btrfs qgroup show -reF /mnt/data/projects/webapp | head -n 3
# 4. Set up monitoring (cron job example)
*/30 * * * * /usr/bin/btrfs qgroup show -re /mnt/data | mail -s "Btrfs Quota Report" admin@example.com
When working with Btrfs filesystems, quota management is handled through qgroups (quota groups). While setting quotas is straightforward, retrieving the configured limits requires specific commands that aren't always well-documented.
To view both usage and limits for a subvolume, use:
btrfs qgroup show -re /path/to/subvolume
The -r
flag shows recursive information, while -e
displays only the exclusive amounts (space used solely by this subvolume).
For a comprehensive view of all qgroups and their limits:
btrfs qgroup show -pcre --raw /mount/point
This command breaks down the output with:
-p
: Path information-c
: Shows child-parent relationships-r
: Recursive display-e
: Exclusive usage--raw
: Displays numbers in bytes
Let's examine a real-world scenario:
# Set quota limit (21GB)
sudo btrfs qgroup limit 21G /mnt/data/subvol1
# Check current status
sudo btrfs qgroup show -re /mnt/data/subvol1
Sample output would display:
qgroupid rfer excl max_rfer max_excl
-------- ---- ---- -------- --------
0/256 2147483648 0 22548578304 0
The key columns to note:
max_rfer
: Referenced limit (total including shared blocks)max_excl
: Exclusive limit (only unique blocks)- Values are in bytes by default (use
--human-readable
for friendly units)
For script processing, use JSON format:
btrfs qgroup show -re --raw /path | jq .
This requires jq
installed and provides machine-readable output for automation.
For regular monitoring, consider setting up a cron job:
*/30 * * * * root btrfs qgroup show -re /mnt/data > /var/log/btrfs_quota.log
Combine with tools like inotifywait
for real-time notifications when approaching limits.