Skip to content

Enable monthly btrfs scrub on root - #5583

Open
peteonrails wants to merge 2 commits into
basecamp:masterfrom
peteonrails:add-btrfs-scrub-timer
Open

Enable monthly btrfs scrub on root#5583
peteonrails wants to merge 2 commits into
basecamp:masterfrom
peteonrails:add-btrfs-scrub-timer

Conversation

@peteonrails

@peteonrails peteonrails commented May 5, 2026

Copy link
Copy Markdown
Contributor

Summary

btrfs scrub is used to scrub a mounted btrfs filesystem, which will read all data and metadata blocks from all devices and verify checksums, and automatically repair corrupted blocks if there’s a correct copy available.

The recommended interval for a btrfs scrub is monthly, although more frequent scrubbing is OK.

The / and /home btrfs volumes silently go unscrubbed by deafult in Omarchy out-of-the-box. btrfs-progs ships the btrfs-scrub@.timer template: this PR enables it so that it runs on / and by extention, on the subvolume /home' at the recommended interval.

Why this matters

Scrub is btrfs's only way to detect and repair silent bitrot. Without periodic scrubs, data corruption can propagate into snapshots and backups before the user notices. This fix will cause omarchy to scan for filesystem data integrity problems. And in the case where auto-repair is not possible, it gives the user a chance to restore the file from a snapshot before they are pruned by snapper.

On single disk systems, BTRFS by default stores 2 metadata copies: when file corruption is detected, it is sometimes possible to repair by the scrub. On dual-drive systems with a mirrored volume, the scrub operation will be able to recover corrupted data from the known-good copy.

I kept 30 days for the scrub thinking that the 5th snapshot is likely to be more than 30 days old, so if a scrub fails and someone needs to recover a file from a snapshot, it's likely to be present. With the recent pace of releases, this might be too long an interval - but we can tune it if needed.

What this changes

These changes are limited to enabling what `btrfs-progs` already ships:

  • install/config/btrfs-scrub.sh (new) — gates on findmnt / being btrfs, calls chrootable_systemctl_enable btrfs-scrub@-.timer. The - is systemd-escape for /.
  • install/config/all.sh — one new `run_logged` line.
  • migrations/1777962247.sh (new) — enables the timer on existing systems on the next `omarchy-update`. Idempotent.

Test Evidence

Migration will activate the timer:

screenshot-2026-05-08_00-31-21

Timer invokes the service unit, which kicks off a scrub:

screenshot-2026-05-08_00-33-52

Scrub completes pretty quickly on a 30GB partition. Low load background task.

screenshot-2026-05-08_00-35-17

Btrfs systems silently go unscrubbed because nothing in stock omarchy
enables the timer. `btrfs-progs` already ships the `btrfs-scrub@.timer`
template (monthly, Persistent=true, idle I/O priority) — we just need
to enable the instance for "/".

Why this matters: scrub is btrfs's only way to detect (and repair, when
duplicate metadata or raid1+ data exists) silent bitrot. Without periodic
scrubs, corruption can propagate into snapshots and backups before any
user notices.

install/config/btrfs-scrub.sh: enables `btrfs-scrub@-.timer` on systems
where root is btrfs. Skips otherwise. Wired into install/config/all.sh.

migrations/1777962247.sh: enables the timer on existing systems via the
update path. Idempotent (systemctl enable --now is safe to repeat).
@peteonrails
peteonrails marked this pull request as ready for review May 8, 2026 04:39
Copilot AI review requested due to automatic review settings May 8, 2026 04:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enables the upstream btrfs-progs systemd scrub timer instance for / so Btrfs installations perform periodic filesystem scrubs (integrity checks/repairs) by default, and rolls the change out to existing installs via a migration.

Changes:

  • Add an installer config step to enable btrfs-scrub@-.timer when / is Btrfs.
  • Add a migration to enable the same timer on already-installed systems.
  • Wire the new config step into the installer’s config pipeline.

Tip

If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
migrations/1777962247.sh Enables btrfs-scrub@-.timer on existing systems during omarchy-update migrations.
install/config/btrfs-scrub.sh Enables the Btrfs scrub timer during fresh installs when / is Btrfs.
install/config/all.sh Adds the new Btrfs scrub config script to the installer run list.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread migrations/1777962247.sh
if [[ $(findmnt -no FSTYPE / 2>/dev/null) != "btrfs" ]]; then
exit 0
fi

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 8, 2026 14:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

Comment thread migrations/1777962247.sh
@@ -0,0 +1,12 @@
echo "Enable monthly btrfs scrub on root (uses btrfs-progs's btrfs-scrub@.timer)"

if [[ $(findmnt -no FSTYPE / 2>/dev/null) != "btrfs" ]]; then
if [[ $(findmnt -no FSTYPE / 2>/dev/null) != "btrfs" ]]; then
exit 0
fi

#
# No-op if root isn't btrfs (e.g. someone is using ext4).

if [[ $(findmnt -no FSTYPE / 2>/dev/null) != "btrfs" ]]; then
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants