1
1
#! /bin/sh
2
2
3
+ echo " --> STARTING persistent-storage script with MDEV='${MDEV} ' ACTION='${ACTION} ' all params: $* " >&2
4
+
3
5
symlink_action () {
4
6
case " $ACTION " in
5
- add) ln -sf " $1 " " $2 " ;;
7
+ add)
8
+ echo " SYMLINK ADD: ln -sf '$1 ' '$2 '" >&2
9
+ ln -sf " $1 " " $2 "
10
+ ;;
6
11
remove) rm -f " $2 " ;;
7
12
esac
8
13
}
58
63
fi
59
64
60
65
model=$( sanitise_file " $SYSFS /class/block/$_check_dev /device/model" )
61
- name=$( sanitise_file " $SYSFS /class/block/$_check_dev /device/name" )
66
+ echo " INITIAL model: '${model} '" >&2
67
+ name=$( sanitise_file " $SYSFS /class/block/$_check_dev /device/name" ) # only used for mmcblk case
68
+ echo " INITIAL name: '${name} '" >&2
62
69
serial=$( sanitise_file " $SYSFS /class/block/$_check_dev /device/serial" )
70
+ echo " INITIAL serial: '${serial} '" >&2
63
71
# Special case where block devices have serials attached to the block itself, like virtio-blk
64
72
: ${serial:= $(sanitise_file " $SYSFS /class/block/$_check_dev /serial" )}
73
+ echo " DEVICE serial (after block-serial): '${serial} '" >&2
65
74
wwid=$( sanitise_file " $SYSFS /class/block/$_check_dev /wwid" )
75
+ echo " INITIAL wwid: '${wwid} '" >&2
66
76
: ${wwid:= $(sanitise_file " $SYSFS /class/block/$_check_dev /device/wwid" )}
77
+ echo " DEVICE wwid (from device-wwid): '${wwid} '" >&2
67
78
68
79
# Sets variables LABEL, PARTLABEL, PARTUUID, TYPE, UUID depending on
69
80
# blkid output (busybox blkid will not provide PARTLABEL or PARTUUID)
@@ -72,17 +83,79 @@ eval $(blkid /dev/$MDEV | cut -d: -f2-)
72
83
if [ -n " $wwid " ]; then
73
84
case " $MDEV " in
74
85
nvme* ) symlink_action ../../$MDEV disk/by-id/nvme-${wwid}${partsuffix} ;;
86
+ sd* ) symlink_action ../../$MDEV disk/by-id/scsi-${wwid}${partsuffix} ;;
87
+ sr* ) symlink_action ../../$MDEV disk/by-id/scsi-ro-${wwid}${partsuffix} ;;
88
+ vd* ) symlink_action ../../$MDEV disk/by-id/virtio-${wwid}${partsuffix} ;;
75
89
esac
76
90
case " $wwid " in
77
91
naa.* ) symlink_action ../../$MDEV disk/by-id/wwn-0x${wwid# naa.}${partsuffix} ;;
78
92
esac
79
93
fi
80
94
95
+ # if no model or no serial is available, lets parse the wwid and try to use it
96
+ if [ -n " ${serial} " ] && [ -n " ${model} " ]; then
97
+ echo " USING SYSFS model='${model} ' serial='${serial} '" >&2
98
+ else
99
+ echo " SYSFS model='${model} ' serial='${serial} ' insufficient, trying to parse from wwid" >&2
100
+ unset wwid_raw
101
+ if [ -f " $SYSFS /class/block/$_check_dev /wwid" ]; then
102
+ echo " FOUND WWID FILE: '$SYSFS /class/block/$_check_dev /wwid'" >&2
103
+ wwid_raw=" $( cat " $SYSFS /class/block/$_check_dev /wwid" ) "
104
+ elif [ -f " $SYSFS /class/block/$_check_dev /device/wwid" ]; then
105
+ echo " FOUND WWID FILE: '$SYSFS /class/block/$_check_dev /device/wwid'" >&2
106
+ wwid_raw=" $( cat " $SYSFS /class/block/$_check_dev /device/wwid" ) "
107
+ fi
108
+ echo " SYSFS parse model/serial from wwid_raw:'${wwid_raw} '" >&2
109
+ if [ -n " ${wwid_raw} " ]; then
110
+ wwid_raw=$( echo " ${wwid_raw} " | sed ' s/^ *//;s/ *$//' ) # Remove leading and trailing spaces
111
+ wwid_prefix=$( echo " ${wwid_raw} " | awk ' {print $1}' ) # Extract the wwid_prefix (first field)
112
+ rest=$( echo " ${wwid_raw} " | sed " s/^${wwid_prefix} *//" ) # Remove the wwid_prefix from the wwid string
113
+ wwid_serial=$( echo " ${rest} " | awk ' {print $NF}' ) # Extract the serial (last field)
114
+ rest=$( echo " ${rest} " | sed " s/ ${wwid_serial} $//" ) # Remove the serial from the rest of the string
115
+ wwid_model=$( echo " ${rest} " | tr ' ' ' _' ) # Replace any remaining spaces in the rest part with underscores
116
+ wwid_model=$( echo " ${wwid_model} " | sed ' s/__*/_/g' ) # Remove consecutive underscores
117
+ wwid_model=$( echo " ${wwid_model} " | sed ' s/^_//;s/_$//' ) # Remove leading and trailing underscores
118
+ wwid_prefix=$( echo " ${wwid_prefix} " | sed ' s/\./-/g' ) # Replace periods in the wwid_prefix with dashes
119
+ unset rest
120
+ echo " WWID parsing came up with wwid_prefix='${wwid_prefix} ' wwid_model='${wwid_model} ', wwid_serial='${wwid_serial} '" >&2
121
+ else
122
+ echo " WWID is empty or not found" >&2
123
+ fi
124
+
125
+ # if model is unset, replace it with the parsed wwid_model
126
+ if [ -z " ${model} " ]; then
127
+ echo " USING WWID model='${wwid_model} ' as model..." >&2
128
+ model=" ${wwid_model} "
129
+ fi
130
+
131
+ # if serial is unset, replace it with the parsed wwid_serial
132
+ if [ -z " ${serial} " ]; then
133
+ echo " USING WWID wwid_serial='${wwid_serial} ' as serial..." >&2
134
+ serial=" ${wwid_serial} "
135
+ fi
136
+
137
+ # if we still have no serial, just use the wwid as serial as fallback;
138
+ if [ -z " ${serial} " ]; then
139
+ echo " FALLBACK: USING WWID as serial='${wwid} '" >&2
140
+ serial=" ${wwid} "
141
+ fi
142
+
143
+ # rescue: if _still_ no serial set, set to hardcoded string 'noserial'.
144
+ if [ -z " ${serial} " ]; then
145
+ echo " FALLBACK: USING 'noserial' as serial..." >&2
146
+ serial=" noserial"
147
+ fi
148
+ fi
149
+
81
150
if [ -n " $serial " ]; then
151
+ echo " GOT SERIAL: serial='${serial} ' model='${model} '" >&2
82
152
if [ -n " $model " ]; then
153
+ echo " GOT MODEL: serial='${serial} ' model='${model} '" >&2
83
154
case " $MDEV " in
84
155
nvme* ) symlink_action ../../$MDEV disk/by-id/nvme-${model} _${serial}${partsuffix} ;;
156
+ sr* ) symlink_action ../../$MDEV disk/by-id/ata-ro-${model} _${serial}${partsuffix} ;;
85
157
sd* ) symlink_action ../../$MDEV disk/by-id/ata-${model} _${serial}${partsuffix} ;;
158
+ vd* ) symlink_action ../../$MDEV disk/by-id/virtio-${model} _${serial}${partsuffix} ;;
86
159
esac
87
160
fi
88
161
if [ -n " $name " ]; then
@@ -138,9 +211,12 @@ if [ "${MDEV#sd}" != "$MDEV" ]; then
138
211
case " $sysdev " in
139
212
* usb[0-9]* )
140
213
# require vfat for devices without partition
141
- if ! [ -e $SYSFS /block/$MDEV ] || [ TYPE= " vfat" ]; then
214
+ if ! [ -e $SYSFS /block/$MDEV ] || [ TYPE= " vfat" ]; then # @TODO: rpardini: upstream bug here? should be $TYPE
142
215
symlink_action $MDEV usbdisk
143
216
fi
144
217
;;
145
218
esac
146
219
fi
220
+
221
+ echo " --> FINISHED persistent-storage script with MDEV='${MDEV} ' ACTION='${ACTION} ' all params: $* " >&2
222
+ echo " " >&2
0 commit comments