Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mountpoint "auto" can fail for read-only mounts #123

Open
unterkomplex opened this issue Jul 8, 2024 · 1 comment
Open

Mountpoint "auto" can fail for read-only mounts #123

unterkomplex opened this issue Jul 8, 2024 · 1 comment

Comments

@unterkomplex
Copy link

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

@Framsfex
Copy link

Framsfex commented Sep 16, 2024

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants