2 # This file is part of Ian Kelling's automated-distro-installer
3 # Copyright (C) 2024 Ian Kelling
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 # input eg: /dev/sda1 or /dev/sda
20 # output: /dev/disk/by-id/model+serial, or if no link exists, the same as input
23 if [[ ! -e $short_dev ]]; then
24 echo "devbyid: error: argument=$short_dev does not exist"
28 # devices are identified by model+serial num
29 # and for ssd/hdd: wwn, and for nvme: eui.
30 # model+serial gives me more info, so use that.
32 for id
in /dev
/disk
/by-id
/!(nvme-eui
*|wwn
*); do
33 [[ -e $id ]] ||
break # if we matched nothing
34 if [[ $
(readlink
-f $id) == "$short_dev" ]]; then
39 # a vm may not have a by-id link.
40 printf '%s\n' "$short_dev"