39 lines
949 B
Bash
Executable File
39 lines
949 B
Bash
Executable File
#!/bin/sh -f
|
|
#
|
|
# create /dev/disk/by-* and /dev/mapper/* symlinks
|
|
|
|
create_symlink()
|
|
{
|
|
dir="$1"; sym="$2"
|
|
|
|
# remove double quotes
|
|
sym="${sym%\"}"
|
|
sym="${sym#\"}"
|
|
sym="${dir}/${sym}"
|
|
|
|
mkdir -p "$dir"
|
|
ln -s "/dev/${dev_name}" "$sym"
|
|
}
|
|
|
|
# int main()
|
|
{
|
|
[ "${dev_name=${DEVPATH##*/}}" ] || exit 1
|
|
|
|
exec > /dev/null 2>&1
|
|
|
|
# avoid race condition
|
|
while ! blkid "/dev/${dev_name}"; do sleep 1; done
|
|
|
|
for line in $(blkid "/dev/${dev_name}"); 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
|
|
|
|
[ -e "/sys/block/${dev_name}/dm/name" ] && {
|
|
mkdir -p /dev/mapper
|
|
read -r dm_name < "/sys/block/${dev_name}/dm/name"
|
|
ln -sf "/dev/${dev_name}" "/dev/mapper/${dm_name}"
|
|
}
|
|
}
|