#1631 Issue closed: replace all mount list commands with findmnt

Labels: cleanup, no-issue-activity

ProBackup-nl opened issue at 2017-12-07 19:41:

From man mount:

The listing.
    The listing mode is maintained for backward compatibility only.
    For more robust and customizable output use findmnt(8), especially in your scripts.
    Note that control characters in the mountpoint name are replaced with ?.

Also quite some grep filtering can be replaced with option -t a.k.a. --types.

That option even has a built-in exclusion system: no_fs_, for example findmnt -t notmpfs,noefivarfs

Or to inverse all fs matching, use option -it a.k.a. --invert --types, for example findmnt -it tmpfs,efivarfs.

Where for example

local excluded_fs_types="cgroup|fuse.*|nfsd"
# BUILD_DIR can be used in 'grep -vE "this|$BUILD_DIR|that"' because it is never empty (see usr/sbin/rear)
# because with any empty part 'grep  -vE "this||that"' would output nothing at all:
local excluded_other_stuff="/sys/|$BUILD_DIR|$USB_DEVICE_FILESYSTEM_LABEL"
# The trailing space in 'type ($excluded_fs_types) |' is intentional:
local mountpoints="$( mount | grep -vE "type ($excluded_fs_types) |$excluded_other_stuff" | awk '{print $3}' )"

becomes

local mountpoints="$( findmnt -runit cgroup,fuse.*,nfsd,efivarfs,securityfs,cgroup2,pstore,autofs,debugfs,configfs -o TARGET )"

To test the output:

findmnt -runit cgroup,fuse.*,nfsd,efivarfs,securityfs,cgroup2,pstore,autofs,debugfs,configfs -o TARGET,FSTYPE
/proc proc
/sys sysfs
/dev devtmpfs
/run tmpfs
/ btrfs
/dev/shm tmpfs
/dev/pts devpts
/sys/fs/cgroup tmpfs
/dev/hugepages hugetlbfs
/tmp tmpfs
/dev/mqueue mqueue
/boot vfat
/home btrfs
/mnt/sdb1 vfat

jsmeix commented at 2017-12-08 12:13:

I know about it and I would prefer we could use only 'findmnt'.

But I think for backward compatibility reasons we must use
the old 'mount' at least in some cases so that ReaR can
still work even on older Linux distributions, cf.
https://github.com/rear/rear/issues/1390

For same reason we use 'findmnt -m', see in particular
https://github.com/rear/rear/issues/882#issuecomment-226485825

github-actions commented at 2020-07-01 01:33:

Stale issue message


[Export of Github issue for rear/rear.]