Also find system default udev rules in /usr/lib/udev/rules.d (!116)

When blanking of udev rules was first tested [1][2] and added [3] all
the distributions at the time (CentOS 6, Debian 6, Fedora 19,
openSUSE 12.2, Ubuntu 12.04 LTS) stored the system default rules in
directory /lib/udev/rules.d.  Now most distributions (CentOS Stream 9,
Debian 11, Fedora 38, Ubuntu 22.04 LTS, openSUSE Leap 15.4) store the
system default rules in directory /usr/lib/udev/rules.d.  Most of these
distributions have a merged /usr file system [4][5] so /lib is a symlink
to /usr/lib and the system default rules can still found using the
original directory.  But openSUSE 15.4 doesn't have a merged /usr so the
gparted shell wrapper doesn't find the system default rules in directory
/usr/lib/udev/rules.d and doesn't prevent auto starting of Linux
Software RAID arrays and bcache devices during a storage probe.

An extra consideration is that Alpine Linux 3.17 doesn't have a merged
/usr file system, but has both /lib/udev/rules.d and
/usr/lib/udev/rules.d directories with different rules files.  Therefore
fix this by checking for system default udev rules in both directories.

[1] Bug 709640 - Linux Swap Suspend and Software RAID partitions not
    recognised, comment 7
    https://bugzilla.gnome.org/show_bug.cgi?id=709640#c7
[2] Bug 709640 - Linux Swap Suspend and Software RAID partitions not
    recognised, comment 12
    https://bugzilla.gnome.org/show_bug.cgi?id=709640#c12
[3] a255abf343
    Prevent GParted starting stopped Linux Software RAID arrays (#709640)
[4] The Case for the /usr Merge
    http://0pointer.de/blog/projects/the-usr-merge
[5] The Case for the /usr Merge
    https://www.freedesktop.org/wiki/Software/systemd/TheCaseForTheUsrMerge/

Closes !116 - Systemd mount masking and udev rule location updates
This commit is contained in:
Mike Fleetwood 2023-08-06 11:34:07 +01:00 committed by Curtis Gedak
parent 852816be70
commit 0ecb45e7b1
1 changed files with 9 additions and 5 deletions

View File

@ -183,8 +183,9 @@ fi
# start Linux Software RAID array members and Bcache devices. # start Linux Software RAID array members and Bcache devices.
# #
# Udev stores volatile / temporary runtime rules in directory /run/udev/rules.d. # Udev stores volatile / temporary runtime rules in directory /run/udev/rules.d.
# Volatile / temporary rules are used to override default rules from # Volatile / temporary rules are used to override system default rules from
# /lib/udev/rules.d. (Permanent local administrative rules in directory # /lib/udev/rules.d and/or /usr/lib/udev/rules.d (depending on udev
# configuration). (Permanent local administrative rules in directory
# /etc/udev/rules.d override all others). See udev(7) manual page for details. # /etc/udev/rules.d override all others). See udev(7) manual page for details.
# #
# Default udev rules containing mdadm to incrementally start array members are # Default udev rules containing mdadm to incrementally start array members are
@ -194,9 +195,12 @@ fi
UDEV_TEMP_RULES='' # List of temporary override rules files. UDEV_TEMP_RULES='' # List of temporary override rules files.
if test -d /run/udev; then if test -d /run/udev; then
test ! -d /run/udev/rules.d && mkdir /run/udev/rules.d test ! -d /run/udev/rules.d && mkdir /run/udev/rules.d
udev_mdadm_rules=`egrep -l '^[^#].*mdadm (-I|--incremental)' /lib/udev/rules.d/*.rules 2> /dev/null` UDEV_TEMP_RULES=`for udev_default_rules_dir in /lib/udev/rules.d /usr/lib/udev/rules.d
udev_bcache_rules=`ls /lib/udev/rules.d/*bcache*.rules 2> /dev/null` do
UDEV_TEMP_RULES=`echo $udev_mdadm_rules $udev_bcache_rules | sed 's,/lib/udev,/run/udev,g'` test -d $udev_default_rules_dir || continue
egrep -l '^[^#].*mdadm (-I|--incremental)' $udev_default_rules_dir/*.rules 2> /dev/null
ls $udev_default_rules_dir/*bcache*.rules 2> /dev/null
done | sed 's,.*/lib/udev,/run/udev,g' | sort -u`
fi fi
for rule in $UDEV_TEMP_RULES; do for rule in $UDEV_TEMP_RULES; do
touch "$rule" touch "$rule"