Skip to content

Commit 69af51d

Browse files
committed
feature/mdadm: workaround for the error in determining the RAID device in use
Sometimes on Fedora, bash may end up with the following error: /srv/features/mdadm/guess/device: line 46: /sys/devices/virtual/block/md127/uevent: Success In this line, the file is sourced from sysfs: MAJOR= MINOR= . "$SYSFS_PATH$1"/uevent As a workaround, we try to read the file in other ways. If that doesn't work, we make the rules for all raid devices. Signed-off-by: Alexey Gladkov <[email protected]>
1 parent 4146f87 commit 69af51d

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

features/mdadm/bin/generate-udev-rules

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/bash -efu
1+
#!/bin/bash -eu
22
# SPDX-License-Identifier: GPL-3.0-or-later
33

44
. sh-functions
@@ -9,6 +9,20 @@ if [ "${1-}" = dirs ]; then
99
mkdir ${verbose2-} -p -- "$DIR/etc/initrd/md"
1010
fi
1111

12+
if [ -z "${GENERATE_UDEV_RULES_FOR_MD_DEVICE-}" ]; then
13+
GENERATE_UDEV_RULES_FOR_MD_DEVICE=
14+
15+
# If the variable is not specified, we generate rules for all
16+
# raid devices.
17+
for path in /dev/dev/block/*/md; do
18+
if [ -d "$path" ]; then
19+
majmin="${path%/md}"
20+
majmin="${majmin##*/}"
21+
GENERATE_UDEV_RULES_FOR_MD_DEVICE="$GENERATE_UDEV_RULES_FOR_MD_DEVICE $majmin"
22+
fi
23+
done
24+
fi
25+
1226
for majmin in ${GENERATE_UDEV_RULES_FOR_MD_DEVICE-}; do
1327
verbose2 "Processing MD device $majmin..."
1428

features/mdadm/guess/device

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,18 @@ fi
4141

4242
guess_feature mdadm
4343

44-
MAJOR=
45-
MINOR=
46-
. "$SYSFS_PATH$1"/uevent
47-
48-
guess_variable GENERATE_UDEV_RULES_FOR_MD_DEVICE "$MAJOR:$MINOR"
44+
if [ -f "$SYSFS_PATH$1"/uevent ]; then
45+
MAJOR=
46+
MINOR=
47+
48+
# Sometimes on Fedora, bash may end the following command with an error:
49+
# /srv/features/mdadm/guess/device: line 46: /sys/devices/virtual/block/md127/uevent: Success
50+
#
51+
. "$SYSFS_PATH$1"/uevent || {
52+
MAJOR="$(sed -n -e 's,MAJOR=,,p' "$SYSFS_PATH$1"/uevent)"
53+
MINOR="$(sed -n -e 's,MINOR=,,p' "$SYSFS_PATH$1"/uevent)"
54+
} ||:
55+
56+
[ -z "$MAJOR" ] || [ -z "$MINOR" ] ||
57+
guess_variable GENERATE_UDEV_RULES_FOR_MD_DEVICE "$MAJOR:$MINOR"
58+
fi

0 commit comments

Comments
 (0)