You are not logged in.

#1 2022-11-16 23:12:35

jimmyg
Member
Registered: 2022-06-14
Posts: 41

[SOLVED]Question about btrfs-scrub@.timer

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

#2 2022-11-17 00:08:59

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,422

Re: [SOLVED]Question about btrfs-scrub@.timer

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)

Online

#3 2022-11-17 01:07:41

jimmyg
Member
Registered: 2022-06-14
Posts: 41

Re: [SOLVED]Question about btrfs-scrub@.timer

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

#4 2022-11-17 02:10:32

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,422

Re: [SOLVED]Question about btrfs-scrub@.timer

That's the way I'm interpreting things yes.

Online

#5 2022-11-17 11:28:59

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: [SOLVED]Question about btrfs-scrub@.timer

`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

Online

#6 2022-11-17 16:01:38

jimmyg
Member
Registered: 2022-06-14
Posts: 41

Re: [SOLVED]Question about btrfs-scrub@.timer

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

#7 2022-11-17 16:34:41

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,422

Re: [SOLVED]Question about btrfs-scrub@.timer

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)

Online

#8 2022-11-17 16:53:52

jimmyg
Member
Registered: 2022-06-14
Posts: 41

Re: [SOLVED]Question about btrfs-scrub@.timer

wow thats extremely useful. It immediately showed me ConditionPathIsMountPoint=/dev/nvme0n1p2 failed which tells me what I needed. ty so much.

Offline

Board footer

Powered by FluxBB