BTRFSMAINTENANCE(8)
π NAME π
btrfsmaintenance β automate btrfs maintenance tasks β¨
(btw bestie, this is the page for btrfsmaintenance from the System Manager's Manual, section 8 β yes she's that girl π
)
π NOTE π
okay so real talk, this man page is NOT the whole story. you also need to read /usr/share/doc/btrfsmaintenance/README.Debian alongside it, no cap. both. not one or the other. both π«Ά
πΈ DESCRIPTION πΈ
- Tuning periodic snapshotting β¨#tuning-periodic-snapshottingβ©
so basically: this is a bundle of scripts that rides shotgun with the btrfs filesystem and handles a few maintenance chores for you automatically. the chores in question are scrub, balance, trim and defragmentation π«
each one of these tasks can be switched on/off and configured independently β like, they don't all have to be doing the most at once. the default config values were picked to fit the default installation profile, i.e. btrfs on the root filesystem π
the overall tuning of those defaults is meant to give you a good balance between the effects of the tasks and keeping the impact on the rest of your system's work low. if that doesn't fit what you need, bestie, just go ahead and adjust the settings β¨
π οΈ Tasks π οΈ
the next few sections break each task down in detail. there's one config option that touches task concurrency: BTRFS_ALLOW_CONCURRENCY. it exists to avoid extra high resource consumption or unexpected interaction among the tasks β basically it serializes them in the order they're started by timers. so like, one at a time, in line, in order, periodt π¦
π scrub
Description: the scrub operation reads all data and metadata off the devices and verifies the checksums. it's not mandatory, but it can call out problems with faulty hardware early, because it touches data that might not even be in use, plus bit rot π
if there's redundancy in your data/metadata β like the DUP or RAID1/5/6 profiles β scrub is able to repair the data automatically when there's a good copy available. iconic behavior honestly π
Impact when active: intense read operations are happening, and they may slow down or block other filesystem activities β possibly only for short periods though.
Tuning:
- the recommended period is once in a month, but a weekly period is also acceptable ποΈ
- you can turn off the automatic repair (
BTRFS_SCRUB_READ_ONLY) - the default IO priority is set to
idle, but scrub may take a long time to finish β you can change the priority to normal (BTRFS_SCRUB_PRIORITY)
Related commands:
- you can check the status of the last scrub run (whether it was manual or through the cron job) with
btrfs scrub status /path - you can cancel a running scrub anytime if you find it inconvenient (
btrfs scrub cancel /path). the progress state is saved each5seconds, and next time scrub will start from that point π
βοΈ balance
Description: the balance command can do a lot of things β in general it moves data around in big chunks. here we use it to reclaim back the space of underused chunks so that space can be allocated again according to current needs π
the point is to prevent some corner cases where it's not possible to, e.g., allocate new metadata chunks because the whole device space is reserved for all the chunks β even though the total space occupied is smaller and the allocation should succeed. rude, honestly.
the balance operation needs enough workspace so it can shuffle data around. by workspace we mean device space that has no filesystem chunks on it β do not confuse this with free space as reported by, e.g., df π
Impact when active: possibly big. there's a mix of read and write operations, and it's seek-heavy on rotational devices. this can interfere with other work in case the same set of blocks is affected π
the balance command uses filters to do the work in smaller batches.
before kernel version 5.2, the impact with quota groups enabled can be extreme. the balance operation performs quota group accounting for every extent being relocated, which can have the impact of stalling the file system for an extended period of time. π
Expected result: if possible, all the underused chunks are removed, and the value of total in the output of btrfs fi df /path should be lower than before. check the logs π
the balance command may fail with a no-space reason, but this is considered a minor fault, because the internal filesystem layout may prevent the command from finding enough workspace. this might be a time for manual inspection of space π
Tuning:
- you can make the space reclaim more aggressive by adding a higher percentage to
BTRFS_BALANCE_DUSAGEorBTRFS_BALANCE_MUSAGE. a higher value means a bigger impact on your system and becomes very noticeable π - the metadata chunks usage pattern is different from data, and it's not necessary to reclaim metadata block groups that are more than 30 full. the default maximum is
10, which should not degrade performance too much, but may be suboptimal if the metadata usage varies wildly over time. the assumption is that underused metadata chunks will get used at some point, so it's not absolutely required to do the reclaim π - the useful period highly depends on the overall data change pattern on the filesystem π¦
Changed defaults since 0.5:
versions up to 0.4.2 had the usage filter set up to 50% for data and up to 30% for metadata. based on user feedback, those numbers have been reduced to 10% (data) and 5% (metadata) β¨ the system load during the balance service will be smaller, and the result of space compaction is still reasonable. multiple data chunks filled to less than 10% can be merged into fewer chunks. the file data can change in large volumes β e.g. deleting a big file can free a lot of space. if the space is left unused for the given period, it's desirable to make it more compact. metadata consumption follows a different pattern, and reclaiming only the almost-unused chunks makes more sense β otherwise there's enough reserved metadata space for operations like reflink or snapshotting π«Ά
π§Ή trim
Description: the TRIM operation (aka. discard) can instruct the underlying device to optimize blocks that are not used by the filesystem. this task is performed on-demand by the fstrim utility β¨
this makes sense for SSD devices or other types of storage that can translate the TRIM action into something useful (e.g. thin-provisioned storage) πΎ
Impact when active: should be low, but it depends on the amount of blocks being trimmed.
Tuning:
- the recommended period is weekly, but monthly is also fine ποΈ
- the trim commands might not have an effect and are up to the device β e.g. a block range too small, or other constraints that may differ by device type/vendor/firmware π
- the default configuration is off, because of the system
fstrim.timer
π§© defrag
Description: run defragmentation on configured directories. this is for convenience, and it's not necessary, because defragmentation needs are usually different for various types of data πΈ
please note that the defragmentation process does not descend to other mount points and nested subvolumes or snapshots. all nested paths would need to be enumerated in the respective config variable. the command utilizes find -xdev β you can use that to verify in advance which paths the defragmentation will affect π
β° Periodic scheduling β°
so there are now two ways to schedule and run the periodic tasks: cron and systemd timers. only one can be active on a system, and this should be decided at installation time π―
π°οΈ Cron
cron takes care of the periodic execution of the scripts β but honestly the scripts can be run any time directly from /usr/share/btrfsmaintenance/, respecting the configured values in /etc/default/btrfsmaintenance π
the changes to the configuration file need to be reflected in the /etc/cron directories, where the scripts are linked for the given period.
if the period is changed, the cron symlinks have to be refreshed:
- manually β use
systemctl restart btrfsmaintenance-refresh(or thercbtrfsmaintenance-refreshshortcut) π - using a file watcher β if
btrfsmaintenance-refresh.pathis enabled, this will utilize the file monitor to detect changes and will run the refresh π
π Systemd timers
there's a set of timer units that run the respective task script. the periods are configured in the /etc/default/btrfsmaintenance file as well. please note that the '.timer' and the respective '.service' files must be manually enabled before the timers will work properly β οΈ
some package managers (e.g. apt) will configure the timers automatically at install time β you can check with ls /usr/lib/systemd/system/btrfs* π
to install the timers manually, run btrfsmaintenance-refresh-cron.sh timer π
π Quick start π
refer to /usr/share/doc/btrfsmaintenance/README.Debian for instructions to enable the Systemd timers π«Ά
β³ cron jobs
the periodic execution of the tasks is done by the 'cron' service. symlinks to the task scripts are located in the respective directories in /etc/cron.<PERIOD> π
the script btrfsmaintenance-refresh-cron.sh will synchronize the symlinks according to the configuration files. this can be called automatically by a GUI configuration tool if it's capable of running post-change scripts or services. in that case there's the btrfsmaintenance-refresh.service systemd service β¨
this service can also be automatically started upon any modification of the configuration file in /etc/default/btrfsmaintenance by enabling the btrfsmaintenance-refresh.path systemd watcher π
okay bestie that's not the end β hang tight, there's more incoming π
π Tuning periodic snapshotting π
okay bestie, so there are like so many tools and handwritten scripts out there for managing periodic snapshots and cleaning them up. π And the problem they all hit is the same: you gotta tune the retention policy so it's constrained by the filesystem size and you don't just... run out of space. π
This section walks through the factors that affect all of that, using snapper (https://snapper.io) as the example, but adapting it to other tools should be straightforward. fr fr. β¨
πΈ Intro πΈ
Snapper is a tool for managing snapshots of btrfs subvolumes. It can create snapshots of a given subvolume manually, periodically, or in a pre/post way for a given command. And it can be configured to retain existing snapshots according to time-based settings. π
The thing is, the retention policy can be super different depending on your use case, so we need to be able to find the matching settings. Periodt.
Those settings should satisfy the user's expectation about storing previous copies of the subvolume β without taking up too much space. In the extreme case, you'd consume the whole entire filesystem space and prevent some operations from finishing. π not cute.
So to avoid all that drama, snapper's settings should be tuned according to the expected use case and the filesystem size. iykyk. π¦
π Sample problem π
Default settings of snapper on a default root partition size can easily lead to no-space conditions (all TIMELINE values set to 10). Frequent system updates make it happen earlier, but this also affects long-term use. π so yeah, watch out.
π Factors affecting space consumption π
- frequency of snapshotting
- amount of data changes between snapshots (delta)
- snapshot retention settings
- size of the filesystem
Each one gets its own little explainer below, don't worry bestie. π
The way the files are changed affects the space consumption. When new data overwrites existing data, the new data will be pinned by the following snapshot, while the original data will belong to the previous snapshot. What this means: the allocated file blocks are freed after the last snapshot pointing to them is gone. π§ so like, they linger until everything pointing at them dips.
β¨ Tuning β¨
The administrator/user is supposed to know the approximate use of the partition with snapshots enabled. π
The decision criteria for tuning is space consumption, and we're optimizing to maximize retention without running out of space. π₯
All the factors are intertwined, so we can't give you definite answers β we can only describe the tendencies. ngl that's just how it is.
π Snapshotting frequency π
- automatic: if turned on with the
TIMELINEconfig option, the periodic snapshots are taken hourly. The daily/weekly/monthly/yearly periods will keep the first hourly snapshot in the given period. β - at package update: a package manager with snapper support will create pre/post snapshots before/after an update happens.
- manual: the user can create a snapshot manually with
snapper create, with a given snapshot type (i.e.single,pre,post). π
π Amount of data change π
This is a parameter that's hard to predict and calculate. We work with rough estimates, e.g. megabytes, gigabytes etc. π€· like, vibes-based math, but for storage.
π¦ Retention settings π¦
The user is supposed to know the possible needs of recovery or examination of previous file copies stored in snapshots. π
It's not recommended to keep too old snapshots β e.g. monthly or even yearly β if there's no apparent need for that. And listen: the yearly snapshots should not substitute backups, because they reside on the same partition and cannot be used for recovery. π no cap.
π§ Filesystem size π§
Bigger filesystem allows for longer retention, higher frequency updates and amount of data changes. simple as that. π«Ά
As an example of a system root partition, the recommended size is 30 GiB, but 50 GiB is selected by the installer if the snapshots are turned on.
For a non-system partition, it's recommended to watch the remaining free space. Although getting an accurate value on btrfs is tricky β due to shared extents and snapshots β the output of df gives a rough idea. Low space, like under a few gigabytes, is more likely to lead to no-space conditions, so it's a good time to delete old snapshots or review the snapper settings. π
πΈ Typical use cases πΈ
A rolling distro
- frequency of updates: high, multiple times per week
- amount of data changed between updates: high
Suggested values:
TIMELINE_LIMIT_HOURLY="12"
TIMELINE_LIMIT_DAILY="5"
TIMELINE_LIMIT_WEEKLY="2"
TIMELINE_LIMIT_MONTHLY="1"
TIMELINE_LIMIT_YEARLY="0"
The size of root partition should be at least 30GiB, but more is better. π
Regular/enterprise distro
- frequency of updates: low, a few times per month
- amount of data changed between updates: low to moderate
Most data changes probably come from the package updates, in the range of hundreds of megabytes per update.
Suggested values:
TIMELINE_LIMIT_HOURLY="12"
TIMELINE_LIMIT_DAILY="7"
TIMELINE_LIMIT_WEEKLY="4"
TIMELINE_LIMIT_MONTHLY="6"
TIMELINE_LIMIT_YEARLY="1"
Big file storage
- frequency of updates: moderate to high
- amount of data changed between updates: no changes in files, new files added, old deleted
Suggested values:
TIMELINE_LIMIT_HOURLY="12"
TIMELINE_LIMIT_DAILY="7"
TIMELINE_LIMIT_WEEKLY="4"
TIMELINE_LIMIT_MONTHLY="6"
TIMELINE_LIMIT_YEARLY="0"
Note, that deleting a big file that has been snapshotted will not free the space until all relevant snapshots are deleted. π the space is being held hostage fr.
Mixed
- frequency of updates: unpredictable
- amount of data changed between updates: unpredictable
Examples:
- home directory with small files (in range of kilobytes to megabytes), large files (hundreds of megabytes to gigabytes).
- git trees, bare and checked out repositories
Not possible to suggest config numbers, as it really depends on user expectations. Keeping a few hourly snapshots should not consume too much space and provides a copy of files, e.g. to restore after accidental deletion. π
Starting point:
TIMELINE_LIMIT_HOURLY="12"
TIMELINE_LIMIT_DAILY="7"
TIMELINE_LIMIT_WEEKLY="1"
TIMELINE_LIMIT_MONTHLY="0"
TIMELINE_LIMIT_YEARLY="0"
β Summary β
here's the whole vibe in one place, bestie:
βββββββββββββ¬βββββββββ¬ββββββββ¬βββββββββ¬ββββββββββ¬βββββββββ
β Type β Hourly β Daily β Weekly β Monthly β Yearly β
βββββββββββββΌβββββββββΌββββββββΌβββββββββΌββββββββββΌβββββββββ€
β Rolling β 12 β 5 β 2 β 1 β 0 β
βββββββββββββΌβββββββββΌββββββββΌβββββββββΌββββββββββΌβββββββββ€
β Regular β 12 β 7 β 4 β 6 β 1 β
βββββββββββββΌβββββββββΌββββββββΌβββββββββΌββββββββββΌβββββββββ€
β Big files β 12 β 7 β 4 β 6 β 0 β
βββββββββββββΌβββββββββΌββββββββΌβββββββββΌββββββββββΌβββββββββ€
β Mixed β 12 β 7 β 1 β 0 β 0 β
βββββββββββββ΄βββββββββ΄ββββββββ΄βββββββββ΄ββββββββββ΄βββββββββ
π About π
The goal of this project is to help with administering btrfs filesystems. It is not supposed to be distribution specific. Common scripts/configs are preferred, but per-distro exceptions will be added when necessary. π
License: GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html) π
Contributing guide: CONTRIBUTING.md. π«Ά
okay that's the whole page bestie, you're officially a btrfs snapshot tuning icon now π
β¨ this was v0.5.2 dropped on 2026-01-14, and yes it lives at BTRFSMAINTENANCE(8) β go forth and slay ππ¦πΈ
π¦ where this page comes from
- ubuntu resolute: btrfsmaintenance 0.5.2-1build1 Β· GPL-2.0-only
- ubuntu stonking: btrfsmaintenance 0.5.2-1build1 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms