2020-04-12 01:01:02 +05:30
|
|
|
#!/bin/sh -f
|
|
|
|
#
|
2021-07-31 22:50:16 +05:30
|
|
|
# Load modules via $MODALIAS.
|
|
|
|
# Create /dev/disk/by-* and /dev/mapper/* symlinks.
|
2020-04-12 01:01:02 +05:30
|
|
|
|
|
|
|
create_symlink()
|
|
|
|
{
|
2021-07-31 22:50:16 +05:30
|
|
|
typ=$1; sym=$2
|
2020-05-13 22:12:30 +05:30
|
|
|
|
2021-07-31 22:50:16 +05:30
|
|
|
sym=${sym%\"}
|
|
|
|
sym=${sym#\"}
|
2021-05-11 15:19:29 +05:30
|
|
|
sym="/dev/disk/by-${typ}/${sym}"
|
2020-04-12 01:01:02 +05:30
|
|
|
|
2021-05-11 15:19:29 +05:30
|
|
|
mkdir -p "${sym%/*}"
|
2020-05-19 09:59:40 +05:30
|
|
|
ln -s "../../${dev_name}" "$sym"
|
2020-04-12 01:01:02 +05:30
|
|
|
}
|
|
|
|
|
2020-09-11 01:23:39 +05:30
|
|
|
exec > /dev/null 2>&1
|
2021-08-04 22:45:07 +05:30
|
|
|
dev_name=${DEVPATH##*/}
|
2020-05-07 17:36:34 +05:30
|
|
|
|
2021-07-31 22:50:16 +05:30
|
|
|
[ "$MODALIAS" ] && modprobe "$MODALIAS"
|
2021-08-04 22:45:07 +05:30
|
|
|
[ "$SUBSYSTEM" = block ] && [ -b "/dev/${dev_name}" ] || exit 1
|
2021-07-31 22:50:16 +05:30
|
|
|
|
2020-09-11 01:23:39 +05:30
|
|
|
read -r dm_name < "/sys/block/${dev_name}/dm/name" && {
|
|
|
|
mkdir -p /dev/mapper
|
|
|
|
ln -sf "../${dev_name}" "/dev/mapper/${dm_name:?}"
|
|
|
|
}
|
2020-07-16 00:53:12 +05:30
|
|
|
|
2020-09-11 01:23:39 +05:30
|
|
|
command -v blkid || exit 0
|
2020-07-16 00:53:12 +05:30
|
|
|
|
2021-05-10 17:04:51 +05:30
|
|
|
# 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 15:07:45 +05:30
|
|
|
while ! _blkid=$(blkid "/dev/${dev_name}"); do
|
2021-05-11 15:08:51 +05:30
|
|
|
if [ "$((count += 1))" = 10 ]; then
|
2021-05-10 13:54:59 +05:30
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
sleep 1
|
|
|
|
fi
|
|
|
|
done
|
2020-05-07 17:36:34 +05:30
|
|
|
|
2021-07-31 22:50:16 +05:30
|
|
|
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-11 01:23:39 +05:30
|
|
|
esac; done
|