tinyramfs/device-helper
2020-07-15 22:23:12 +03:00

37 lines
891 B
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"
}
# int main()
{
[ -b "/dev/${dev_name=${DEVPATH##*/}}" ] || exit 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
# prevent race condition
blkid "/dev/${dev_name}" || sleep 2
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
} > /dev/null 2>&1