The btrfs balance command is a command-line utility in Linux that is used to balance the data in a btrfs file system. btrfs balance is a utility that is included in the btrfs-progs package, which is a collection of tools and libraries for managing btrfs file systems.
Btrfs is a copy-on-write (CoW) file system that is included in the Linux kernel and is known for its advanced features and capabilities, such as snapshotting, incremental backups, and more. One of the key features of btrfs is the ability to balance the data stored on the file system, which refers to the process of distributing the data evenly across all available devices and disks.
The btrfs balance command allows you to perform this process manually, in order to optimize the performance and efficiency of the file system. btrfs balance can be used to balance data across different devices or disks, or to balance data within a single device or disk.
To use btrfs balance, you will need to have the btrfs-progs package installed on your Linux system. btrfs-progs is usually available as a package in the repositories of popular Linux distributions, and you can install it using the package manager for your specific distribution.
btrfs balance Command Examples
1. Show the status of a running or paused balance operation:
# btrfs balance status /path/to/btrfs_filesystem
2. Balance all block groups (slow; rewrites all blocks in filesystem):
# btrfs balance start /path/to/btrfs_filesystem
3. Balance data block groups which are less than 15% utilized, running the operation in the background:
# btrfs balance start --bg -dusage=15 /path/to/btrfs_filesystem
4. Balance a max of 10 metadata chunks with less than 20% utilization and at least 1 chunk on a given device devid (see btrfs filesystem show):
# btrfs balance start -musage=20,limit=10,devid=devid /path/to/btrfs_filesystem
5. Convert data blocks to the raid6 and metadata to raid1c3 (see mkfs.btrfs(8) for profiles):
# btrfs balance start -dconvert=raid6 -mconvert=raid1c3 /path/to/btrfs_filesystem
6. Convert data blocks to raid1, skipping already converted chunks (e.g. after a previous cancelled conversion operation):
# sudo btrfs balance start -dconvert=raid1,soft path/to/btrfs_filesystem
7. Cancel, pause, or resume a running or paused balance operation:
# btrfs balance [cancel|pause|resume] /path/to/btrfs_filesystem