3 # input eg: /dev/sda1 or /dev/sda
4 # output: /dev/disk/by-id/model+serial, or if no link exists, the same as input
7 if [[ ! -e $short_dev ]]; then
8 echo "devbyid: error: argument=$short_dev does not exist"
12 # devices are identified by model+serial num
13 # and for ssd/hdd: wwn, and for nvme: eui.
14 # model+serial gives me more info, so use that.
16 for id
in /dev
/disk
/by-id
/!(nvme-eui
*|wwn
*); do
17 [[ -e $id ]] ||
break # if we matched nothing
18 if [[ $
(readlink
-f $id) == "$short_dev" ]]; then
23 # a vm may not have a by-id link.
24 printf '%s\n' "$short_dev"