btrfs
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 (pipe) 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:
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 |
descritpion |
| btrfs qgroup show -re /mnt/btrfs\_volume |
shows limits of the volume |
| btrfs qgroup limit 3T /mnt/btrfs\_subvolume |
sets limit for this subvolume |
| Option |
Description |
| `compress=zstd` |
Zapne kompresi (doporučené: zstd) |
| `compress=lzo` |
Komprese LZO (rychlá, méně efektivní) |
| `compress-force=zstd` |
Vynutí kompresi všech dat |
| `autodefrag` |
Automatická defragmentace při zápisu |
| `ssd` |
Optimalizace pro SSD (obvykle se detekuje automaticky) |
| `ssd_spread` |
Alternativní strategie zápisu na SSD |
| `space_cache=v2` |
Rychlejší mount díky cache alokací (novější verze) |
| `discard=async` |
Asynchronní TRIM pro SSD |
| `noatime` |
Nezapisuje access time (lepší výkon) |
| `nodatacow` |
Vypne Copy-on-Write pro daný mount/subvolume |
| `subvol=` |
Mount konkrétního subvolume |
| `subvolid=` |
Mount podle ID subvolume |
/dev/sdb /mnt btrfs defaults,compress=zstd,autodefrag,ssd,discard=async 0 0