btrfs
Here’s a clean Markdown version of your document:
# Btrfs Management
## File System Management
|
| Command |
|Description |
Description
|
|---------|-------------|
|
`mkfs.btrfs /dev/sdX`sdX |
| Create a new Btrfs filesystem |
|
|
`mount /dev/sdX /mnt`mnt |
| Mount Btrfs filesystem |
|
|
`umount /mnt`mnt |
| Unmount filesystem |
|
|
`btrfs filesystem show`show |
| Show Btrfs filesystems |
|
|
`btrfs filesystem df /mnt`mnt |
| Show space usage |
|
|
`btrfs filesystem usage /mnt`mnt |
| Detailed space usage |
|
---
##
RAID Management
|
| Command |
|Description |
Description
|
|---------|-------------|
|
`mkfs.btrfs -d raid1 -m raid1 /dev/sdb /dev/sdc`sdc |
| Create RAID1 (mirror) |
|
|
`mkfs.btrfs -d raid0 -m raid0 /dev/sdb /dev/sdc`sdc |
| Create RAID0 (striping) |
|
|
`mkfs.btrfs -d raid10 -m raid10 /dev/sdb /dev/sdc /dev/sdd /dev/sde`sde |
| Create RAID10 |
|
|
`btrfs device add /dev/sdd /mnt`mnt |
| Add device to filesystem |
|
|
`btrfs device remove /dev/sdc /mnt`mnt |
| Remove device from filesystem |
|
|
`btrfs balance start -dconvert=raid1 -mconvert=raid1 /mnt`mnt |
| Convert existing FS to RAID1 |
|
|
`btrfs balance start /mnt`mnt |
| Rebalance data across devices |
|
|
`btrfs device stats /mnt`mnt |
| Show device stats |
|
---
##
Subvolume Management
|
| Command |
|Description |
Description
|
|---------|-------------|
|
`btrfs subvolume create /mnt/data`data |
| Create subvolume |
|
|
`btrfs subvolume list /mnt`mnt |
| List subvolumes |
|
|
`btrfs subvolume delete /mnt/data`data |
| Delete subvolume |
|
|
`btrfs subvolume snapshot /mnt/data /mnt/data-snap`snap |
| Snapshot a subvolume |
|
|
`btrfs subvolume snapshot -r /mnt/data /mnt/data-ro`ro |
| Create readonly snapshot |
|
---
##
Snapshots
|
| Command |
|Description |
Description
|
|---------|-------------|
|
`btrfs subvolume snapshot /mnt/data /mnt/data-snap`snap |
| Create snapshot |
|
|
`btrfs subvolume delete /mnt/data-snap`snap |
| Delete snapshot |
|
|
| `btrfs send /mnt/data-snap |
| btrfs receive /mnt/backup` |
|
Send
snapshot
to
another FS |
---
## Scrub & Check
|
| Command |
|Description |
Description
|
|---------|-------------|
|
`btrfs scrub start /mnt`mnt |
| Start scrub on mounted FS |
|
|
`btrfs scrub status /mnt`mnt |
| Show scrub status |
|
|
`btrfs scrub cancel /mnt`mnt |
| Cancel scrub |
|
|
`btrfs check /dev/sdX`sdX |
| Check filesystem (offline) |
|
|
`btrfs rescue super-recover /dev/sdX`sdX |
| Try to recover superblock |
|
---
##
Resize
|
| Command |
|Description |
Description
|
|---------|-------------|
|
`btrfs filesystem resize +10G /mnt`mnt |
| Grow FS by 10G |
|
|
`btrfs filesystem resize -5G /mnt`mnt |
| Shrink FS by 5G |
|
|
`btrfs filesystem resize max /mnt`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