Filesystem Management

Creating & Mounting

# Create a BTRFS filesystem
$ mkfs.btrfs /dev/sda1

# Create with specific features
$ mkfs.btrfs -L mylabel -m raid1 /dev/sda1 /dev/sdb1

# Mount with specific options
$ mount -o compress=zstd /dev/sda1 /mnt

Basic Operations

# Show filesystem info
$ btrfs filesystem show
$ btrfs filesystem df /mount/point
$ btrfs filesystem usage /mount/point

# Enable/disable features
$ btrfs filesystem defrag /mount/point
$ btrfs balance start /mount/point
$ btrfs scrub start /mount/point

Subvolume Operations

Managing Subvolumes

# Create subvolume
$ btrfs subvolume create /path/to/subvol

# List subvolumes
$ btrfs subvolume list /mount/point

# Delete subvolume
$ btrfs subvolume delete /path/to/subvol

# Set default subvolume
$ btrfs subvolume set-default <id> /mount/point

Snapshot Operations

# Create snapshot
$ btrfs subvolume snapshot /source /dest

# Create read-only snapshot
$ btrfs subvolume snapshot -r /source /dest

# Send/receive snapshots
$ btrfs send /subvol1 | btrfs receive /path
$ btrfs send -p /snap1 /snap2 | btrfs receive /path

RAID & Device Management

Device Operations

# Add device
$ btrfs device add /dev/sdb1 /mount/point

# Remove device
$ btrfs device remove /dev/sdb1 /mount/point

# Replace device
$ btrfs replace start /dev/sdb1 /dev/sdc1 /mount/point

RAID Management

# Convert RAID levels
$ btrfs balance start -dconvert=raid1 -mconvert=raid1 /mount/point

# Check RAID status
$ btrfs device stats /mount/point

# Resize filesystem
$ btrfs filesystem resize +10G /mount/point

Advanced Features

Compression Settings

# Enable compression
$ btrfs filesystem defrag -r -v -czstd /mount/point

# Change compression algorithm
$ mount -o remount,compress=zstd /mount/point

# Check compression ratio
$ compsize /mount/point

Quota Management

# Enable quotas
$ btrfs quota enable /mount/point

# Set quota limits
$ btrfs qgroup limit 10G /path/to/subvol

# Show quota status
$ btrfs qgroup show /mount/point

Maintenance & Recovery

System Maintenance

# Check filesystem
$ btrfs check /dev/sda1

# Repair filesystem
$ btrfs check --repair /dev/sda1

# Balance status
$ btrfs balance status /mount/point

# Cancel operations
$ btrfs balance cancel /mount/point

Recovery Operations

# Rescue corrupted filesystem
$ btrfs rescue zero-log /dev/sda1

# Recover superblock
$ btrfs rescue super-recover /dev/sda1

# Check metadata consistency
$ btrfs check --check-data-csum /dev/sda1

Property Management

Setting Properties

# Set compression
$ btrfs property set /path compression zstd

# Enable COW
$ btrfs property set /path compression compression

Getting Properties

# List properties
$ btrfs property list /path

# Get specific property
$ btrfs property get /path compression

References

  • Based on BTRFS version 5.15
  • For more details: man btrfs
0 Comments for this cheatsheet. Write yours!