2020-04-11 22:31:02 +03:00
|
|
|
#!/bin/sh -f
|
|
|
|
#
|
2021-07-31 20:20:16 +03:00
|
|
|
# Load modules via $MODALIAS.
|
|
|
|
# Create /dev/disk/by-* and /dev/mapper/* symlinks.
|
2020-04-11 22:31:02 +03:00
|
|
|
|
|
|
|
create_symlink()
|
|
|
|
{
|
2021-07-31 20:20:16 +03:00
|
|
|
typ=$1; sym=$2
|
2020-05-13 19:42:30 +03:00
|
|
|
|
2021-07-31 20:20:16 +03:00
|
|
|
sym=${sym%\"}
|
|
|
|
sym=${sym#\"}
|
2021-05-11 12:49:29 +03:00
|
|
|
sym="/dev/disk/by-${typ}/${sym}"
|
2020-04-11 22:31:02 +03:00
|
|
|
|
2021-05-11 12:49:29 +03:00
|
|
|
mkdir -p "${sym%/*}"
|
2020-05-19 07:29:40 +03:00
|
|
|
ln -s "../../${dev_name}" "$sym"
|
2020-04-11 22:31:02 +03:00
|
|
|
}
|
|
|
|
|
2020-09-10 22:53:39 +03:00
|
|
|
exec > /dev/null 2>&1
|
2020-05-07 15:06:34 +03:00
|
|
|
|
2021-07-31 20:20:16 +03:00
|
|
|
[ "$MODALIAS" ] && modprobe "$MODALIAS"
|
|
|
|
[ "$SUBSYSTEM" = block ] && [ -b "/dev/${dev_name=${DEVPATH##*/}}" ] || exit 1
|
|
|
|
|
2020-09-10 22:53:39 +03:00
|
|
|
read -r dm_name < "/sys/block/${dev_name}/dm/name" && {
|
|
|
|
mkdir -p /dev/mapper
|
|
|
|
ln -sf "../${dev_name}" "/dev/mapper/${dm_name:?}"
|
|
|
|
}
|
2020-07-15 22:23:12 +03:00
|
|
|
|
2020-09-10 22:53:39 +03:00
|
|
|
command -v blkid || exit 0
|
2020-07-15 22:23:12 +03:00
|
|
|
|
2021-05-10 14:34:51 +03:00
|
|
|
# Race condition may occur if uevent arrives faster(isn't that a kernel bug!?)
|
|
|
|
# than the kernel initializes device. This prevents blkid to fetch data from
|
|
|
|
# device. To fix this, we simply waiting until blkid is succeeded.
|
2021-05-11 12:37:45 +03:00
|
|
|
while ! _blkid=$(blkid "/dev/${dev_name}"); do
|
2021-05-11 12:38:51 +03:00
|
|
|
if [ "$((count += 1))" = 10 ]; then
|
2021-05-10 11:24:59 +03:00
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
sleep 1
|
|
|
|
fi
|
|
|
|
done
|
2020-05-07 15:06:34 +03:00
|
|
|
|
2021-07-31 20:20:16 +03:00
|
|
|
for line in $_blkid; do case ${line%%=*} in
|
|
|
|
UUID) create_symlink uuid "${line#*=}" ;;
|
|
|
|
LABEL) create_symlink label "${line#*=}" ;;
|
|
|
|
PARTUUID) create_symlink partuuid "${line#*=}" ;;
|
2020-09-10 22:53:39 +03:00
|
|
|
esac; done
|