more aramo/jammy updates
[automated-distro-installer] / fai / config / distro-install-common / devbyid
1 #!/bin/bash
2
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
5
6 short_dev=$1
7
8 # devices are identified by model+serial num
9 # and for ssd/hdd: wwn, and for nvme: eui.
10 # model+serial gives me more info, so use that.
11 shopt -s extglob
12 for id in /dev/disk/by-id/!(nvme-eui*|wwn*); do
13 [[ -e $id ]] || break # if we matched nothing
14 if [[ $(readlink -f $id) == "$short_dev" ]]; then
15 printf '%s\n' "$id"
16 exit
17 fi
18 done
19 # a vm may not have a by-id link.
20 printf '%s\n' "$short_dev"