Btrfs (B-tree filesystem) is a modern filesystem developed to address the expanding storage needs and capabilities of today's hardware. It offers advanced features like snapshots, dynamic inode allocation, integrated device management, RAID, and compression. At its core, Btrfs employs Copy on Write (CoW) for data integrity and efficiency, making it an attractive choice for systems that demand high reliability and performance.
mkfs.btrfs -L <label> /dev/sdX
btrfs filesystem resize <size or max> <mount_point>
btrfs filesystem resize <-size or min> <mount_point>
btrfs property set <file/dir> compression <type>
btrfs property set <subvolume> ro <true/false>
chattr +C <file/dir>
btrfs subvolume snapshot <source_subvolume> <destination_snapshot>
btrfs subvolume delete <snapshot_path>
btrfs subvolume create /path/@
btrfs subvolume delete /path/@
Enable quotas and manage limits using:
btrfs quota enable <mount_point>
btrfs qgroup limit <size> <mount_point or qgroup_id>
btrfs qgroup show -r <mount_point or qgroup_id>
btrfs balance start -dconvert=raid1 -mconvert=raid1 <mount_point> --background
btrfs balance status <mount_point>
Option | Description | Default Status |
---|---|---|
ro |
Mount the filesystem in read-only mode. | Disabled |
noacl |
Disable Access Control Lists (ACLs). | Disabled |
autodefrag |
Enable automatic defragmentation of files. | Disabled |
compress=zstd |
Enable transparent compression of data using zstd (recommended). | Disabled |
compress=lzo |
Enable transparent compression of data using LZO. | Disabled |
compress=zlib |
Enable transparent compression of data using zlib. | Disabled |
nocompress |
Disable compression. | Disabled |
discard=async |
Enable asynchronous TRIM/discard support for SSDs (recommended). | Enabled (Since Linux kernel 6.2) |
discard=sync |
Enable synchronous TRIM/discard support for SSDs. | Disabled |
nodiscard |
Disable automatic discard/TRIM operations. | Disabled |
nodatacow |
Disable copy-on-write (CoW) for data. (not recommended) | Disabled |
nospace_cache |
Disable space cache. | Disabled |
ssd |
Optimize mount options for solid-state drives. | Auto-detected |
space_cache=v2 |
Enable version 2 of the space cache for improved performance. | Enabled |
commit=<sec> |
Set the interval for automatic commit operations in seconds. | 30 seconds |
degraded |
Allow mounting a filesystem in degraded mode. | Disabled |
noatime |
Disable updating the access time for files. | Disabled |
subvol=<subvol_path> |
Mount a specific subvolume by its path. | Not applicable |
subvolid=<subvol_id> |
Mount a specific subvolume by its ID. | Not applicable |
nodatacow
: Not recommended for general use as it disables CoW.nospace_cache
: Disabling the space cache can degrade performance.noautodefrag
: Consider the impact on performance for HDDs or certain workloads.btrfs subvolume create /path/to/db_subvolume
chattr +C /path/to/database
btrfs balance start <mount_point> --background
btrfs filesystem usage <mount_point>