45 lines
1.2 KiB
Bash
Executable File
45 lines
1.2 KiB
Bash
Executable File
#!/bin/sh -f
|
|
#
|
|
# create /dev/disk/by-* and /dev/mapper/* symlinks
|
|
|
|
create_symlink()
|
|
{
|
|
dir="$1"; sym="$2"
|
|
|
|
sym="${sym%\"}"
|
|
sym="${sym#\"}"
|
|
sym="${dir}/${sym}"
|
|
|
|
mkdir -p "$dir"
|
|
ln -s "../../${dev_name}" "$sym"
|
|
}
|
|
|
|
# DEVPATH is part of uevent which is exported to environment by device manager.
|
|
[ -b "/dev/${dev_name=${DEVPATH##*/}}" ] || exit 1
|
|
|
|
exec > /dev/null 2>&1
|
|
|
|
read -r dm_name < "/sys/block/${dev_name}/dm/name" && {
|
|
mkdir -p /dev/mapper
|
|
ln -sf "../${dev_name}" "/dev/mapper/${dm_name:?}"
|
|
}
|
|
|
|
command -v blkid || exit 0
|
|
|
|
# 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.
|
|
while ! _blkid=$(blkid "/dev/${dev_name}"); do
|
|
if [ "$((count += 1))" = 10 ]; then
|
|
exit 1
|
|
else
|
|
sleep 1
|
|
fi
|
|
done
|
|
|
|
for line in $_blkid; do case "${line%%=*}" in
|
|
UUID) create_symlink /dev/disk/by-uuid "${line##*=}" ;;
|
|
LABEL) create_symlink /dev/disk/by-label "${line##*=}" ;;
|
|
PARTUUID) create_symlink /dev/disk/by-partuuid "${line##*=}" ;;
|
|
esac; done
|