hwe kernel to fix btrfs-send bug
[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 wwn. model+serial gives me more info, so use that.
10 shopt -s extglob
11 for id in /dev/disk/by-id/!(wwn*); do
12 [[ -e $id ]] || break # if we matched nothing
13 if [[ $(readlink -f $id) == "$short_dev" ]]; then
14 printf '%s\n' "$id"
15 exit
16 fi
17 done
18 # a vm may not have a by-id link.
19 printf '%s\n' "$short_dev"