2
2
3
3
symlink_action () {
4
4
case " $ACTION " in
5
- add) ln -sf " $1 " " $2 " ;;
6
- remove) rm -f " $2 " ;;
5
+ add) ln -sf " $1 " " $2 " ;;
6
+ remove) rm -f " $2 " ;;
7
7
esac
8
8
}
9
9
10
10
sanitise_file () {
11
- sed -E -e ' s/^\s+//' -e ' s/\s+$//' -e ' s/ /_/g' " $@ " 2> /dev/null
11
+ sed -E -e ' s/^\s+//' -e ' s/\s+$//' -e ' s/ /_/g' " $@ " 2> /dev/null
12
12
}
13
13
14
14
sanitise_string () {
@@ -25,32 +25,31 @@ blkid_encode_string() {
25
25
26
26
# cdrom symlink
27
27
case " $MDEV " in
28
- sr* | xvd* )
29
- caps=" $( cat $SYSFS /block/$MDEV /capability 2> /dev/null) "
30
- if [ $(( 0 x${caps:- 0} & 8 )) -gt 0 ] || [ " $( cat $SYSFS /block/$MDEV /removable 2> /dev/null) " = " 1" ]; then
28
+ sr* | xvd* )
29
+ caps=" $( cat $SYSFS /block/$MDEV /capability 2> /dev/null) "
30
+ if [ $(( 0 x${caps:- 0} & 8 )) -gt 0 ] || [ " $( cat $SYSFS /block/$MDEV /removable 2> /dev/null) " = " 1" ]; then
31
31
symlink_action $MDEV cdrom
32
32
fi
33
+ ;;
33
34
esac
34
35
35
-
36
36
# /dev/block symlinks
37
37
mkdir -p block
38
38
if [ -f " $SYSFS /class/block/$MDEV /dev" ]; then
39
39
maj_min=$( sanitise_file " $SYSFS /class/block/$MDEV /dev" )
40
40
symlink_action ../$MDEV block/${maj_min}
41
41
fi
42
42
43
-
44
43
# by-id symlinks
45
44
mkdir -p disk/by-id
46
45
47
46
if [ -f " $SYSFS /class/block/$MDEV /partition" ]; then
48
47
# This is a partition of a device, find out its parent device
49
48
_parent_dev=" $( basename $( ${SBINDIR:-/ usr/ bin} /readlink -f " $SYSFS /class/block/$MDEV /.." ) ) "
50
49
51
- partition=$( cat $SYSFS /class/block/$MDEV /partition 2> /dev/null)
50
+ partition=$( cat $SYSFS /class/block/$MDEV /partition 2> /dev/null)
52
51
case " $partition " in
53
- [0-9]* ) partsuffix=" -part$partition " ;;
52
+ [0-9]* ) partsuffix=" -part$partition " ;;
54
53
esac
55
54
# Get name, model, serial, wwid from parent device of the partition
56
55
_check_dev=" $_parent_dev "
@@ -72,29 +71,29 @@ eval $(blkid /dev/$MDEV | cut -d: -f2-)
72
71
73
72
if [ -n " $wwid " ]; then
74
73
case " $MDEV " in
75
- nvme* ) symlink_action ../../$MDEV disk/by-id/nvme-${wwid}${partsuffix} ;;
74
+ nvme* ) symlink_action ../../$MDEV disk/by-id/nvme-${wwid}${partsuffix} ;;
76
75
esac
77
76
case " $wwid " in
78
- naa.* ) symlink_action ../../$MDEV disk/by-id/wwn-0x${wwid# naa.}${partsuffix} ;;
77
+ naa.* ) symlink_action ../../$MDEV disk/by-id/wwn-0x${wwid# naa.}${partsuffix} ;;
79
78
esac
80
79
fi
81
80
82
81
if [ -n " $serial " ]; then
83
82
if [ -n " $model " ]; then
84
83
case " $MDEV " in
85
- nvme* ) symlink_action ../../$MDEV disk/by-id/nvme-${model} _${serial}${partsuffix} ;;
86
- sd* ) symlink_action ../../$MDEV disk/by-id/ata-${model} _${serial}${partsuffix} ;;
84
+ nvme* ) symlink_action ../../$MDEV disk/by-id/nvme-${model} _${serial}${partsuffix} ;;
85
+ sd* ) symlink_action ../../$MDEV disk/by-id/ata-${model} _${serial}${partsuffix} ;;
87
86
esac
88
87
fi
89
88
if [ -n " $name " ]; then
90
89
case " $MDEV " in
91
- mmcblk* ) symlink_action ../../$MDEV disk/by-id/mmc-${name} _${serial}${partsuffix} ;;
90
+ mmcblk* ) symlink_action ../../$MDEV disk/by-id/mmc-${name} _${serial}${partsuffix} ;;
92
91
esac
93
92
fi
94
93
95
94
# virtio-blk
96
95
case " $MDEV " in
97
- vd* ) symlink_action ../../$MDEV disk/by-id/virtio-${serial}${partsuffix} ;;
96
+ vd* ) symlink_action ../../$MDEV disk/by-id/virtio-${serial}${partsuffix} ;;
98
97
esac
99
98
fi
100
99
@@ -117,13 +116,13 @@ if [ -n "$UUID" ]; then
117
116
fi
118
117
119
118
# nvme EBS storage symlinks
120
- if [ " ${MDEV# nvme} " != " $MDEV " ] && [ " $model " = " Amazon_Elastic_Block_Store" ] && command -v nvme > /dev/null; then
119
+ if [ " ${MDEV# nvme} " != " $MDEV " ] && [ " $model " = " Amazon_Elastic_Block_Store" ] && command -v nvme > /dev/null; then
121
120
n=30
122
121
while [ $n -gt 0 ]; do
123
- ebs_alias=$( nvme id-ctrl -b /dev/$_check_dev \
124
- | dd bs=32 skip=96 count=1 2> /dev/null \
125
- | sed -nre ' /^(\/dev\/)?(s|xv)d[a-z]{1,2} /p' \
126
- | tr -d ' ' )
122
+ ebs_alias=$( nvme id-ctrl -b /dev/$_check_dev |
123
+ dd bs=32 skip=96 count=1 2> /dev/null |
124
+ sed -nre ' /^(\/dev\/)?(s|xv)d[a-z]{1,2} /p' |
125
+ tr -d ' ' )
127
126
if [ -n " $ebs_alias " ]; then
128
127
symlink_action " $MDEV " ${ebs_alias#/ dev/ } $partition
129
128
break
@@ -145,4 +144,3 @@ if [ "${MDEV#sd}" != "$MDEV" ]; then
145
144
;;
146
145
esac
147
146
fi
148
-
0 commit comments