Btrfs RAID-1 uneven disk size usually stems from metadata allocation imbalances or partial device failures rather than a fundamental flaw in the filesystem itself. This guide explains how to diagnose the discrepancy using
btrfs fi usage, identify which devices are holding excess data, and execute the necessary rebalance operations to restore an even distribution across your storage pool.
Understanding Btrfs RAID-1 Allocation Behavior
Unlike traditional block-level RAID, Btrfs operates at the file system level, managing data and metadata separately. In a RAID-1 configuration, every piece of data is duplicated on two different devices. However, the allocator does not always distribute these copies perfectly evenly, especially when files are created, deleted, or modified rapidly. Metadata, which tracks the structure of the filesystem, often accumulates on one device if that device was added later or if it had more free space during initial allocation.
This behavior can lead to a situation where one drive shows significantly higher utilization than its partner, even though both contain identical data sets. The "unevenness" is rarely a corruption issue but rather a reflection of how the btrfs allocator has historically placed chunks. Understanding this distinction is crucial before attempting any fixes, as unnecessary interventions can sometimes worsen the imbalance by forcing reallocations that prioritize speed over perfect symmetry.
Diagnosing the Imbalance with Diagnostic Commands
The first step in troubleshooting is to quantify the disparity. You must run the
btrfs fi usage command with verbose output to see the breakdown per device. This command reveals not just total used space, but specifically how much data and metadata reside on each individual disk within the RAID-1 set.
btrfs fi usage /mount/point
Look for the section labeled "Device:" followed by the device identifier (e.g.,
/dev/sdb). Pay close attention to the "Used" column versus the "Total" column. If you see a significant difference in the "Data" or "Metadata" usage between two otherwise identical drives, you have confirmed the imbalance. For example, one drive might show 90% usage while the other shows 60%, despite both holding the same logical files. This diagnostic step confirms whether the issue is purely spatial or if there are underlying health issues affecting one of the drives.
If the imbalance is severe, check the health status of the drives using
btrfs device stats. This command checks for read errors or I/O faults that might prevent the filesystem from writing new data to the less utilized drive, effectively forcing all new writes onto the healthier or faster drive.
Evaluating Options for Replacing Failed Home NAS Array: BTRFS RAID Configuration and Replacement Ability provides further context on how hardware health impacts allocation decisions in similar setups.
Interpreting the Output
When reviewing the output, distinguish between "Global Reserve" and actual user data. Btrfs reserves space for snapshots and future growth, which can skew perception. Focus on the "Data" and "Metadata" lines under each device. If the difference exceeds 10-15%, a manual intervention is typically required to correct the distribution.
Executing a Balanced Rebalance
To resolve the uneven distribution, you must trigger a rebalance operation. This process tells the btrfs allocator to move chunks of data and metadata around so that they are spread more evenly across all available devices in the RAID-1 set. It is important to note that a rebalance is an intensive operation that reads and writes every byte of data on the filesystem. Ensure you have adequate power stability and backups before proceeding.
Initiate the rebalance with the following command:
btrfs balance start /mount/point
This command will scan the entire filesystem and redistribute data. Depending on the size of your array, this could take several hours. During this time, the system remains usable, but performance may degrade slightly due to increased I/O activity. You can monitor the progress by running:
btrfs balance status /mount/point
If the standard rebalance does not fully resolve the issue, you may need to specify filters to target specific types of chunks. For instance, if metadata is the primary culprit, you can use:
btrfs balance start -mconvert=raid1 /mount/point
This forces all metadata chunks to be converted back to RAID-1, ensuring they are duplicated evenly. Similarly, for data chunks, use
-dconvert=raid1. Always verify the results after the operation completes by running
btrfs fi usage again to confirm that the utilization percentages are now closely aligned.
Speeding up BTRFS metadata storage on a RAID1C3 volume with an SSD discusses related optimization strategies that might influence how metadata is initially allocated, which can help prevent future imbalances.
Preventing Future Imbalances
Once the rebalance is complete, adopt practices that minimize future skewing. Avoid adding new devices to an existing active array unless absolutely necessary, as this often triggers immediate allocation bias toward the new, empty device. If you must add space, consider replacing old drives with larger ones individually rather than adding a third drive to a two-drive setup, which changes the RAID profile entirely.
Regularly monitoring disk usage via cron jobs or monitoring tools like Prometheus with node-exporter can alert you to gradual drifts in utilization. Additionally, keeping your kernel and btrfs-progs packages updated ensures you benefit from the latest allocator improvements, which have become significantly smarter in recent years about maintaining even distributions.
Frequently Asked Questions
Does a rebalance delete my data?
No, a btrfs rebalance does not delete data; it simply moves existing chunks to different physical locations on the disks. However, because it involves reading and writing massive amounts of data, a power failure during the process can corrupt the filesystem, making backups essential.
Why is one drive still fuller after rebalancing?
If the imbalance persists, it may be due to a hidden allocation error or a drive with bad sectors that the allocator avoids. Check the drive health with
btrfs device stats and look for I/O errors that might be preventing writes to that specific disk.
Can I rebalance without stopping services?
Yes, btrfs allows online balancing, meaning you can run the command while the system is mounted and in use. However, background services will experience higher latency and slower disk speeds during the operation, so scheduling it during low-traffic periods is recommended.
What is the difference between RAID-1 and RAID1C3?
RAID-1 duplicates data twice (two copies total), while RAID1C3 creates three copies. C3 offers higher redundancy but uses more disk space. The rebalance commands differ slightly depending on which profile your volume is currently using, so verify your current profile with
btrfs filesystem show.
Is it safe to ignore small differences in disk usage?
Minor variations (under 5%) are normal and do not require action. These fluctuations often occur due to temporary file creation and deletion patterns. Only intervene if the difference is substantial and stable over time, indicating a persistent allocation bias.