Enable monthly btrfs scrub on root - #5583
Open
peteonrails wants to merge 2 commits into
Open
Conversation
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).
Contributor
There was a problem hiding this comment.
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@-.timerwhen/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.
| 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>
| @@ -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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-progsships thebtrfs-scrub@.timertemplate: 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 onfindmnt /being btrfs, callschrootable_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:
Timer invokes the service unit, which kicks off a scrub:
Scrub completes pretty quickly on a 30GB partition. Low load background task.