btrfs
Btrfs Management
File System Management
| Command |
Description |
`mkfs.btrfs /dev/sdXsdX` |
Create a new Btrfs filesystem |
`mount /dev/sdX /mntmnt` |
Mount Btrfs filesystem |
`umount /mntmnt` |
Unmount filesystem |
`btrfs filesystem showshow` |
Show Btrfs filesystems |
`btrfs filesystem df /mntmnt` |
Show space usage |
`btrfs filesystem usage /mntmnt` |
Detailed space usage |
RAID Management
| Command |
Description |
`mkfs.btrfs -d raid1 -m raid1 /dev/sdb /dev/sdcsdc` |
Create RAID1 (mirror) |
`mkfs.btrfs -d raid0 -m raid0 /dev/sdb /dev/sdcsdc` |
Create RAID0 (striping) |
`mkfs.btrfs -d raid10 -m raid10 /dev/sdb /dev/sdc /dev/sdd /dev/sdesde` |
Create RAID10 |
`btrfs device add /dev/sdd /mntmnt` |
Add device to filesystem |
`btrfs device remove /dev/sdc /mntmnt` |
Remove device from filesystem |
`btrfs balance start -dconvert=raid1 -mconvert=raid1 /mntmnt` |
Convert existing FS to RAID1 |
`btrfs balance start /mntmnt` |
Rebalance data across devices |
`btrfs device stats /mntmnt` |
Show device stats |
Subvolume Management
| Command |
Description |
`btrfs subvolume create /mnt/datadata` |
Create subvolume |
`btrfs subvolume list /mntmnt` |
List subvolumes |
`btrfs subvolume delete /mnt/datadata` |
Delete subvolume |
`btrfs subvolume snapshot /mnt/data /mnt/data-snapsnap` |
Snapshot a subvolume |
`btrfs subvolume snapshot -r /mnt/data /mnt/data-roro` |
Create readonly snapshot |
Snapshots
| Command |
Description |
`btrfs subvolume snapshot /mnt/data /mnt/data-snapsnap` |
Create snapshot |
`btrfs subvolume delete /mnt/data-snapsnap` |
Delete snapshot |
`btrfs send /mnt/data-snap (pipe) btrfs receive /mnt/backupbackup` |
Send snapshot to another FS |
Scrub & Check
| Command |
Description |
`btrfs scrub start /mntmnt` |
Start scrub on mounted FS |
`btrfs scrub status /mntmnt` |
Show scrub status |
`btrfs scrub cancel /mntmnt` |
Cancel scrub |
`btrfs check /dev/sdXsdX` |
Check filesystem (offline) |
`btrfs rescue super-recover /dev/sdXsdX` |
Try to recover superblock |
Resize
| Command |
Description |
`btrfs filesystem resize +10G /mntmnt` |
Grow FS by 10G |
`btrfs filesystem resize -5G /mntmnt` |
Shrink FS by 5G |
`btrfs filesystem resize max /mntmnt` |
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=zstdzstd` |
Zapne kompresi (doporučené: zstd) |
`compress=lzolzo` |
Komprese LZO (rychlá, méně efektivní) |
`compress-force=zstdzstd` |
Vynutí kompresi všech dat |
autodefrag`autodefrag` |
Automatická defragmentace při zápisu |
ssd`ssd` |
Optimalizace pro SSD (obvykle se detekuje automaticky) |
ssd_spread`ssd_spread` |
Alternativní strategie zápisu na SSD |
`space_cache=v2v2` |
Rychlejší mount díky cache alokací (novější verze) |
`discard=asyncasync` |
Asynchronní TRIM pro SSD |
noatime`noatime` |
Nezapisuje access time (lepší výkon) |
nodatacow`nodatacow` |
Vypne Copy-on-Write pro daný mount/subvolume |
`subvol=<name>` |
Mount konkrétního subvolume |
`subvolid=<id>` |
Mount podle ID subvolume |
/dev/sdb /mnt btrfs defaults,compress=zstd,autodefrag,ssd,discard=async 0 0