btrfs
Here’s a clean Markdown version of your document:
# Btrfs Management
## File System Management
| Command | Description |
|---------|-------------|
| `mkfs.btrfs /dev/sdX` | Create a new Btrfs filesystem |
| `mount /dev/sdX /mnt` | Mount Btrfs filesystem |
| `umount /mnt` | Unmount filesystem |
| `btrfs filesystem show` | Show Btrfs filesystems |
| `btrfs filesystem df /mnt` | Show space usage |
| `btrfs filesystem usage /mnt` | Detailed space usage |
---
## RAID Management
| Command | Description |
|---------|-------------|
| `mkfs.btrfs -d raid1 -m raid1 /dev/sdb /dev/sdc` | Create RAID1 (mirror) |
| `mkfs.btrfs -d raid0 -m raid0 /dev/sdb /dev/sdc` | Create RAID0 (striping) |
| `mkfs.btrfs -d raid10 -m raid10 /dev/sdb /dev/sdc /dev/sdd /dev/sde` | Create RAID10 |
| `btrfs device add /dev/sdd /mnt` | Add device to filesystem |
| `btrfs device remove /dev/sdc /mnt` | Remove device from filesystem |
| `btrfs balance start -dconvert=raid1 -mconvert=raid1 /mnt` | Convert existing FS to RAID1 |
| `btrfs balance start /mnt` | Rebalance data across devices |
| `btrfs device stats /mnt` | Show device stats |
---
## Subvolume Management
| Command | Description |
|---------|-------------|
| `btrfs subvolume create /mnt/data` | Create subvolume |
| `btrfs subvolume list /mnt` | List subvolumes |
| `btrfs subvolume delete /mnt/data` | Delete subvolume |
| `btrfs subvolume snapshot /mnt/data /mnt/data-snap` | Snapshot a subvolume |
| `btrfs subvolume snapshot -r /mnt/data /mnt/data-ro` | Create readonly snapshot |
---
## Snapshots
| Command | Description |
|---------|-------------|
| `btrfs subvolume snapshot /mnt/data /mnt/data-snap` | Create snapshot |
| `btrfs subvolume delete /mnt/data-snap` | Delete snapshot |
| `btrfs send /mnt/data-snap | btrfs receive /mnt/backup` | Send snapshot to another FS |
---
## Scrub & Check
| Command | Description |
|---------|-------------|
| `btrfs scrub start /mnt` | Start scrub on mounted FS |
| `btrfs scrub status /mnt` | Show scrub status |
| `btrfs scrub cancel /mnt` | Cancel scrub |
| `btrfs check /dev/sdX` | Check filesystem (offline) |
| `btrfs rescue super-recover /dev/sdX` | Try to recover superblock |
---
## Resize
| Command | Description |
|---------|-------------|
| `btrfs filesystem resize +10G /mnt` | Grow FS by 10G |
| `btrfs filesystem resize -5G /mnt` | Shrink FS by 5G |
| `btrfs filesystem resize max /mnt` | Use full device size |
---
## Example Workflows
### Create RAID1 (mirror) with 2 disks
```bash
mkfs.btrfs -d raid1 -m raid1 /dev/sdb /dev/sdc
mount /dev/sdb /mnt
Add new disk to pool and rebalance into RAID1
btrfs device add /dev/sdd /mnt
btrfs balance start -dconvert=raid1 -mconvert=raid1 /mnt
Create snapshot and restore
btrfs subvolume snapshot /mnt/data /mnt/data-snap
btrfs subvolume delete /mnt/data
btrfs subvolume snapshot /mnt/data-snap /mnt/data
Qgroups
| Command | Description |
|---|---|
btrfs qgroup show -re /mnt/btrfs_volume |
Shows limits of the volume |
btrfs qgroup limit 3T /mnt/btrfs_subvolume |
Sets limit for this subvolume |
Mount Options
| Option | Description |
|---|---|
compress=zstd |
Enable compression (recommended: zstd) |
compress=lzo |
LZO compression (fast, less efficient) |
compress-force=zstd |
Force compression for all data |
autodefrag |
Auto defragmentation on write |
ssd |
Optimize for SSD (usually auto-detected) |
ssd_spread |
Alternative SSD write strategy |
space_cache=v2 |
Faster mount via allocation cache |
discard=async |
Asynchronous TRIM for SSD |
noatime |
Disable access time updates |
nodatacow |
Disable Copy-on-Write |
subvol= |
Mount specific subvolume |
subvolid= |
Mount by subvolume ID |
Example fstab entry:
/dev/sdb /mnt btrfs defaults,compress=zstd,autodefrag,ssd,discard=async 0 0