btrfsmaintenance
btrfsmaintenance copied to clipboard
Mountpoint "auto" can fail for read-only mounts
I encountered one issue while using the option to automatically process all mountpoints BTRFS_SCRUB_MOUNTPOINTS="auto"
The script returns a single mountpoint for each filesystem
MNT=$(findmnt --types btrfs --first-only --noheadings --output "TARGET" --source "$DEVICE")
https://github.com/kdave/btrfsmaintenance/blob/b1e70f6c99797def13c1d302a603e18cce701a8d/btrfsmaintenance-functions#L25C10-L25C84
This fails if there are both read-only and read-write mounts and findmnt returns a ro mountpoint
In order to fix it I think it would be sufficient to add --options rw
MNT=$(findmnt --types btrfs --first-only --options rw --noheadings --output "TARGET" --source "$DEVICE")
Example output from Fedora IoT on BTRFS filesystem with /sysroot mounted as ro
[root@pi ~]# findmnt --types btrfs --noheadings --output "TARGET" --source "/dev/sda1"
/sysroot
/
/etc
/usr
/sysroot/ostree/deploy/fedora-iot/var
/var
/var/mnt/ssd
[root@pi ~]# findmnt --types btrfs --first-only --noheadings --output "TARGET" --source "/dev/sda1"
/sysroot
[root@pi ~]# findmnt --types btrfs --first-only --options rw --noheadings --output "TARGET" --source "/dev/sda1"
/
[root@pi ~]# journalctl -b0 -u btrfs-scrub.service
Jul 08 03:09:39 pi btrfs-scrub.sh[1283]: Running scrub on /sysroot
Jul 08 03:09:39 pi btrfs-scrub.sh[1283]: RAID level is not 5 or 6, parallel device scrubbing
Jul 08 03:09:39 pi btrfs-scrub.sh[1283]: ERROR: scrubbing /sysroot failed for device id 1: ret=-1, errno=30 (Read-only>
Jul 08 03:09:39 pi btrfs-scrub.sh[1283]: Starting scrub on devid 1
Jul 08 03:09:39 pi btrfs-scrub.sh[1283]: Scrub device /dev/sda1 (id 1) canceled
Jul 08 03:09:39 pi btrfs-scrub.sh[1283]: Scrub started: Mon Jul 8 03:09:39 2024
Jul 08 03:09:39 pi btrfs-scrub.sh[1283]: Status: aborted
Jul 08 03:09:39 pi btrfs-scrub.sh[1283]: Duration: 0:00:00
Jul 08 03:09:39 pi btrfs-scrub.sh[1283]: Total to scrub: 0.00B
Jul 08 03:09:39 pi btrfs-scrub.sh[1283]: Rate: 0.00B/s
Jul 08 03:09:39 pi btrfs-scrub.sh[1283]: Error summary: no errors found
The keyword "auto" also adds btrfs filesystems on loop devices, which is not a good idea.
As a workaround I have added an extra variable BTRFS_ALL to /etc/default/btrfsmaintenance :
# all rw-mounted btrfs filesystems (but skip loop devices)
# see also: lsblk -n -o NAME,FSTYPE,MOUNTPOINT
BTRFS_ALL=$(perl -wne '
next if m:^/dev/loop:;
$b{$1} ||= $2 if /^(\S+) (\S+) btrfs rw,/;
END { print join(":",sort values %b) if %b }
' /proc/mounts)
So I can use:
BTRFS_SCRUB_MOUNTPOINTS="$BTRFS_ALL"
This also happened to me.
Looking at scrub as an example:
https://github.com/kdave/btrfsmaintenance/blob/beb9e2d166cbd856297fe8d28e89e8b36961a723/btrfs-scrub.sh#L58-L61
Maybe the early exit is not as good?
It means that any filesystems later in the order will not get scrubbed at all. Maybe it would be better to save the error (one_fs_failed=1) and at the end return that one?