tinyramfs/device-helper

46 lines
1003 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()
{
sym="$1"
sym="${sym%\"}"
sym="${sym#\"}"
sym="${dir}/${sym}"
2020-04-12 01:01:02 +05:30
mkdir -p "$dir"
ln -s "/dev/${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
# avoid race condition
2020-05-09 01:28:48 +05:30
while [ ! -e "/dev/${dev_name}" ]; do sleep 1; done
for line in $(blkid "/dev/${dev_name}"); do case "${line%%=*}" in
UUID)
dir=/dev/disk/by-uuid
create_symlink "${line##*=}"
;;
LABEL)
dir=/dev/disk/by-label
create_symlink "${line##*=}"
;;
PARTUUID)
dir=/dev/disk/by-partuuid
create_symlink "${line##*=}"
;;
esac; done
2020-04-12 01:01:02 +05:30
[ -e "/sys/block/${dev_name}/dm/name" ] && {
mkdir -p /dev/mapper
read -r dm_name < "/sys/block/${dev_name}/dm/name"
ln -s "/dev/${dev_name}" "/dev/mapper/${dm_name}"
2020-04-12 01:01:02 +05:30
}
}