tinyramfs/device-helper

38 lines
903 B
Plaintext
Raw Normal View History

2020-04-12 01:01:02 +05:30
#!/bin/sh -f
#
# create /dev/disk/by-* and /dev/mapper/* symlinks
create_symlink()
{
2020-05-13 22:12:30 +05:30
dir="$1"; sym="$2"
# remove double quotes
2020-04-12 01:01:02 +05:30
sym="${sym%\"}"
sym="${sym#\"}"
sym="${dir}/${sym}"
2020-04-12 01:01:02 +05:30
mkdir -p "$dir"
ln -s "../../${dev_name}" "$sym"
2020-04-12 01:01:02 +05:30
}
# int main()
{
[ "${dev_name=${DEVPATH##*/}}" ] || exit 1
2020-05-09 01:28:48 +05:30
exec > /dev/null 2>&1
# prevent race condition
while ! blkid "/dev/${dev_name}"; do sleep 1; done
2020-05-13 22:12:30 +05:30
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
2020-04-12 01:01:02 +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-04-12 01:01:02 +05:30
}
}