create mount directory
mkdir -p /data
installing the package btrfs
apt install btrfs-progs -y
verify version
mkfs.btrfs --version
spot the disk directory (/dev/vdx)
lsblk
format /dev/vdb as Btrfs with single metadata and data profile for avoiding default mirror raid1 redundancy overhead and waste
mkfs.btrfs -m single -d single /dev/vdb
multi disk raid0
mkfs.btrfs -m raid0 -d raid0 /dev/sda /dev/sdb /dev/sdc
Explanation:
- -m raid0: Sets the metadata to use RAID0 (striping)
- -d raid0: Sets the data to use RAID0 (striping)
- /dev/sda /dev/sdb /dev/sdc: The devices to include in the array
force format it by adding the -f flag if disk formatted in such as ext4 already
mkfs.btrfs -f -m single -d single /dev/vdb
check if it’s formatted correctly
btrfs filesystem show /dev/vdb
lsblk -f #option "-f", "--fs" output info about filesystems
mount and set compress rate zstd:3
mount -o compress=zstd:3 /dev/vdb /data
verify the mount done
btrfs filesystem df /data
show the disk uuid
lsblk -f
persistent mounting config
nano /etc/fstab
auto mount at reboot
UUID=<your-uuid> /data btrfs defaults,compress=zstd:1,ssd,ssd_spread,noatime,space_cache=v2,discard=async 0 0
Optimized Btrfs Mount Options for Desktop + PVE
UUID=<your-btrfs-uuid> /mnt/btrfs_raid0 btrfs defaults,compress=zstd:1,ssd,ssd_spread,noatime,space_cache=v2,commit=120,discard=async 0 0
- (You can keep commit=120 if you want, but I removed it here as 30 is often safer for a root partition.)
🔧 Option Breakdown
| Option | Purpose |
|---|---|
compress=zstd:1 |
Fast compression, minimal CPU overhead. For slightly better disk space, you can use zstd:3. |
ssd |
Optimizes Btrfs allocation patterns for SSDs. |
ssd_spread |
Reduces write amplification by spreading writes evenly across SSD blocks. |
noatime |
Disables updating file access times → reduces unnecessary writes. |
space_cache=v2 |
Speeds up free space allocation, faster mount times. |
commit=120 |
Flushes metadata every 120 seconds instead of default 30 → improves responsiveness, reduces I/O. |
discard=async |
Enables TRIM support for SSDs asynchronously → safer than synchronous TRIM. |
defaults |
Standard mount options (rw, suid, dev, exec, auto, nouser, async). |
“subvol” parameter for enabling snapshot, VM/LXC data & structured datasets, etc
UUID=<your-btrfs-uuid> /data btrfs defaults,compress=zstd,subvol=/ 0 0
verify the config correct
mount -a
check the btrfs mount status
lsblk -f
defragment
btrfs filesystem defrag -v -r -czstd /data
show the compress rate
btrfs filesystem du -s /mnt/btrfs_disk
output example
Total Exclusive Set shared Filename
~100M ~50M 0B /data/testfile
check space usage
btrfs filesystem usage /mnt/btrfs_disk
Check if subvolumes exist (if unsure):
sudo btrfs subvolume list /data
Create a subvolume for snapshot
sudo btrfs subvolume create /data/mydata
Take a snapshot snapshot of the entire /data filesystem
sudo btrfs subvolume snapshot /data/mydata /data/snapshots/mydata_$(date +%F)
To turn off automatic snapshots (if using snapper or btrbk), just disable their services:
sudo systemctl disable snapper-timeline.timer
sudo systemctl disable btrbk.timer
List snapshots:
sudo btrfs subvolume list /data
🔹 Snapshots for Backups & Rollbacks
Each VM (or LXC container) can have its own subvolume.
You can snapshot an individual VM/container without affecting others.
Rollback instantly if an update breaks the system.
🔸 Example Setup for VMs (Proxmox default path):
/data
├── vm-100-disk-0 (Subvolume for VM 100 disk)
/ ├── vm-101-disk-0 (Subvolume for VM 101 disk)
/ ├── snapshots (Store snapshots separately)
🔸 Example Setup for LXC Containers:
data
├── subvol-100-disk (Subvolume for LXC container 100)
/ ├── subvol-101-disk (Subvolume for LXC container 101)
/ ├── snapshots
📌 If you don’t use subvolumes, snapshots will include everything in /data, making it inefficient.
🔹 Database Optimization & Snapshots
Databases like MySQL, PostgreSQL, MariaDB change frequently.
If they reside in a subvolume, you can snapshot only the database without affecting logs, backups, or static files.
Faster backup & restore times.
🔸 Example Setup for Databases:
/data
├── mysql-data (Subvolume for MySQL database)
/ ├── pgsql-data (Subvolume for PostgreSQL)
/ ├── backups (Regular file storage)
🔹 Application Data Separation
For apps like Nextcloud, WordPress, or Docker volumes, use subvolumes to:
Snapshot app data separately from logs.
Efficient backups without large unnecessary files.
🔸 Example Setup for Nextcloud:
/data
├── nextcloud-data (Subvolume for Nextcloud files)
/ ├── nextcloud-config (Subvolume for config files)
/ ├── logs (Non-subvolume, log rotation enabled)
评论区