How to enable scrub and balance timers?

Greetings Fedora community,

I recently installed Fedora 36 and had a few questions regarding btrs maintenance. I was using EndeavourOS Gnome before this and on my old Arch-based setup I used a package from the AUR called btrfsmaintenance that more or less ran on it’s own once installed. I see this package is also in the Fedora repos too which is nice, but reading about btrfsmaintenance on Fedora, it seems the consensus is better not to use it, but rather timers for scrubbing and balancing. I’m curious if anyone can tell me what exactly the commands I need to activate systemd timers for these two? Is it a good idea to use both or just one of them? I know fstrm timer is on by default and I do have an SSD in my Acer laptop. I have a very simple setup, just one SSD in my laptop.

Here’s my /etc/fstab details below if that’s helpful:

UUID=06fb8d29-d255-4b98-aa4f-a3fa0416ede9 /                       btrfs   subvol=root,compress=zstd:1 0 0
UUID=a5c65a7b-d274-4d97-9a5b-38aa8817829f /boot                   ext4    defaults        1 2
UUID=CC4E-4FA7          /boot/efi               vfat    umask=0077,shortname=winnt 0 2
UUID=06fb8d29-d255-4b98-aa4f-a3fa0416ede9 /home                   btrfs   subvol=home,compress=zstd:1 0 0

Appreciate any help!

3 Likes

I wonder about this as well.
Can anyone chime in?

There is no significant difference btrfsmaintenance on Arch and btrfsmaintenance on Fedora.

btrfsmaintenance also uses timers. However, it adds a bunch of convenient funcitionality so you don’t have to enable them one at a time for each filesystem and/or subvolume.

I can’t imagine why the “consensus” would be to not use btrfsmaintenance.

1 Like

I just wrote my own systemd service and timer. E.g.:

──────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: btrfs-scrub.service
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ [Unit]
   2   │ Description=Runs the btrfs scrub on the root mount point periodically
   3   │ 
   4   │ [Service]
   5   │ Type=simple
   6   │ ExecStart=/usr/sbin/btrfs scrub start -B /
───────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

───────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
       │ File: btrfs-scrub.timer
───────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
   1   │ [Unit]
   2   │ Description=Runs the btrfs scrub on the root mount point periodically
   3   │ 
   4   │ [Timer]
   5   │ OnCalendar=monthly
   6   │ AccuracySec=12h
   7   │ Persistent=true
   8   │ 
   9   │ [Install]
  10   │ WantedBy=timers.target
2 Likes

If you have multiple btrfs volumes, you can generalize the service file like:

#    /etc/systemd/system/btrfs-scrub@.service
[Unit]
Description=Btrfs scrub on %f
Requires=%i.mount
After=%i.mount

[Service]
Nice=19
IOSchedulingClass=idle
KillSignal=SIGINT
ExecStart=btrfs scrub start -B %f
# /etc/systemd/system/btrfs-scrub@.timer
[Unit]
Description=Monthly Btrfs scrub on %f

[Timer]
OnCalendar=monthly
AccuracySec=7d
RandomizedDelaySec=7d
Persistent=true

[Install]
WantedBy=timers.target

And then enable with (different disks mounted at /, /home and /mnt/backup):

# systemctl enable --now btrfs-scrub@-.timer
# systemctl enable --now btrfs-scrub@home.timer
# systemctl enable --now btrfs-scrub@mnt-backup.timer
2 Likes