You are not logged in.
Hi there
I'm looking to set up a btrfs-scrub timer using systemd and I am just looking for some clarification.
I have 1 nvme device with 2 partitions - an efi partition and a second partition for my arch installation. The btrfs partition has 7 subvolumes and each of these has its own mountpoint, all pretty standard.
So I read the wiki page https://wiki.archlinux.org/title/btrfs#Scrub. It explains I need to set up a btrfs-scrub@.timer for each mountpoint so does this mean I must create 7x btrfs-scrub@.timers for each of these? The thing is i've read elsewhere that when btrfs scrub is started it will scrub the entire device regardless of my subvolumes and their mountpoints.
I did read another interesting article https://www.ordinatechnic.com/distribut … -rollbacks. It focuses on an Arch installation using btrfs but towards the end it explains a way of using systemd btrfs-scrub timers which I thought might work well for me.
As with the Arch wiki article it uses systemd-escape to find the names of the unit files and then uses this to make a single btrfs-scrub timer using the uuid or device name, so for example I could just use
sudo systemd-escape --template=btrfs-scrub@.timer --path /dev/nvme0n1p2
then
sudo systemctl enable btrfs-scrub@dev-nvme0n1p2.timer
Should I do it this way or should I make scrub timers for each mount point, I'm a bit unsure.
Thanks for any help you can give.
Last edited by jimmyg (2022-11-18 12:31:36)
Offline
According to the link that's linked as an expansion in that wiki section and the upstream docs, a btrfs scrub does indeed cover the entire filesystem so should only be ran once on a given file system. So there should not be a need for a scrub for each subvolume.
For the question whether you need to create multiple timer units if that were something you'd need to do, then no you do not since the @ signifies a templated service, so the "multiple timers/services" will implicitly be created by passing an instance variable (the string after the @) to the service unit, note the blue box in: https://wiki.archlinux.org/title/Systemd#Using_units
Last edited by V1del (2022-11-17 00:10:26)
Offline
Hi and thanks for your reply, that has helped a lot.
So if i make a timer unit using this command
sudo systemctl enable btrfs-scrub@dev-nvme0n1p2.timer
that should be all I need?
Offline
That's the way I'm interpreting things yes.
Offline
`btrfs scrub start` should accept a device (but the man page says it has to be mounted anyway). It looks like that wouldn't work with this timer/service combo with these conditions:
ConditionPathIsMountPoint=%f
RequiresMountsFor=%f
Offline
Hi thx for ur reply
I have my top-level mounted as:
UUID=1fbf4b28-0d0c-468b-a96e-fe5a77e7eae8 /btrfs btrfs rw,noatime,nodiratime,compress-force=zstd:1,discard=async,space_cache=v2,subvol=/ 0 0
perhaps I should use its mountpoint for the timer unit:
sudo systemctl enable btrfs-scrub@btrfs.timer
rather than using the device path?
Offline
That will from the service's logistics certainly work better, but you could just test whether one or the other would lead to a trigger by either trying to start the service and checking the output or what you should also be able to do is
systemd-analyze condition ConditionPathIsMountPoint=/btrfs ConditionPathIsMountPoint=/dev/nvme0n1p2
(... I'd provide the output of that myself, but all linuxes I currently have access to don't yet have a new enough systemd)
Last edited by V1del (2022-11-17 16:36:58)
Offline
wow thats extremely useful. It immediately showed me ConditionPathIsMountPoint=/dev/nvme0n1p2 failed which tells me what I needed. ty so much.
Offline