Fedora uses the BTRFS (b-tree filesystem) by default since quite a while.
BTRFS has a lot of nice features (even though less than BCacheFS, but that can not be recommended for use yet).
But did you know that you need to do some of these manually?
1. Scrub
- Detect and repair corruption
While mostly useful when using RAID, where the process can detect corrupted data and restore it from a disk with the same contents, this can also be useful on a single disk.
Here it can detect “bit rot”, and restore files using checksums and metadata.
The impact is pretty low, as it only changes files if they are corrupt.
run0
btrfs scrub start -Bd /
btrfs scrub status /
I am not sure if this works on read-only subvolumes
To set this up as an automatic systemd service:
run0 tee /etc/systemd/system/btrfs-scrub.service <<EOF
[Unit]
Description=Btrfs scrub on /
ConditionPathIsMountPoint=/
[Service]
ExecStart=/usr/bin/btrfs scrub start -Bd /
Nice=10
IOSchedulingClass=idle
EOF
run0 tee /etc/systemd/system/btrfs-scrub.timer <<EOF
[Unit]
Description=Run Btrfs scrub every 3 days
[Timer]
OnCalendar=*-*-*/3 00:00:00
Persistent=true
[Install]
WantedBy=timers.target
EOF
systemctl enable --now btrfs-scrub.timer
This will check the disk for corruptions every 3 days, while taking low priority (Nice=10
) and not running when the disk is in use (IOSchedulingClass=idle
)
Check the status of the service:
systemctl status btrfs-scrub.service
2. Balance
- Redistribute data, optimize space
- read the docs before using it
BTRFS has native RAID support, which allows distributing load onto multiple storage devices.
This can be used for performance, reliability, or to increase the amount of storage by using 2 drives for one filesystem (yes that works!).
balance
is only useful when you have multiple disks with unevenly allocated (used) space, and especially if a disk is nearly full.
btrfs filesystem df /
Displays the stats you need. Example output that shows a lot of unused Data
and Metadata
:
Data, single: total=80GiB, used=30GiB
Metadata, DUP: total=10GiB, used=2GiB
System, DUP: total=32MiB, used=16KiB
Balancing the filesystem takes a lot of performance. If there is a powerloss during the process, data could be in the wrong place, while metadata normally isn’t. Still, ensure that your PC is under little load and has continuous power
run0 btrfs balance start --full-balance /
To be less invasive, you can only balance chunks with under 50% usage:
run0 btrfs balance start -dusage=50 /
3. Defragment
- Reduce fragmentation, speed up access
Fragmentation is an issue on HDDs, where data would be stored under many different sections of the drive. To speed up performance, you can use this tool.
It is not recommended on SSDs, as there is no such fragmentation and the extra writes on the SSD reduce the lifespan
run0 btrfs filesystem defragment -r /