-
Notifications
You must be signed in to change notification settings - Fork 24
/
diskConfig.sh
211 lines (177 loc) · 5.04 KB
/
diskConfig.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/bin/bash
function log()
{
message=$@
echo "$message"
echo "$message" >> /var/log/sapconfigcreate
}
function addtofstab()
{
log "addtofstab"
partPath=$1
mount=$2
local blkid=$(/sbin/blkid $partPath)
if [[ $blkid =~ UUID=\"(.{36})\" ]]
then
log "Adding fstab entry"
local uuid=${BASH_REMATCH[1]};
local mountCmd=""
log "adding fstab entry"
mountCmd="/dev/disk/by-uuid/$uuid $mount xfs defaults,nofail 0 2"
echo "$mountCmd" >> /etc/fstab
$(mount $partPath $mount)
else
log "no UUID found"
exit -1;
fi
log "addtofstab done"
}
function getdevicepath()
{
log "getdevicepath"
getdevicepathresult=""
local lun=$1
local readlinkOutput=$(readlink /dev/disk/azure/scsi1/lun$lun)
local scsiOutput=$(lsscsi)
if [[ $readlinkOutput =~ (sd[a-zA-Z]{1,2}) ]];
then
log "found device path using readlink"
getdevicepathresult="/dev/${BASH_REMATCH[1]}";
elif [[ $scsiOutput =~ \[5:0:0:$lun\][^\[]*(/dev/sd[a-zA-Z]{1,2}) ]];
then
log "found device path using lsscsi"
getdevicepathresult=${BASH_REMATCH[1]};
else
log "lsscsi output not as expected for $lun"
exit -1;
fi
log "getdevicepath done"
}
function createlvm()
{
log "createlvm"
local lunsA=(${1//,/ })
local vgName=$2
local lvName=$3
local mountPathA=(${4//,/ })
local sizeA=(${5//,/ })
local lunsCount=${#lunsA[@]}
local mountPathCount=${#mountPathA[@]}
local sizeCount=${#sizeA[@]}
log "count luns: $lunsCount paths: $mountPathCount sizes: $sizeCount"
if [[ $lunsCount -ge 1 ]]
then
log "createlvm - creating lvm"
local numRaidDevices=0
local raidDevices=""
log "num luns $lunsCount"
for ((i=0; i<lunsCount; i++))
do
log "trying to find device path"
local lun=${lunsA[$i]}
getdevicepath $lun
local devicePath=$getdevicepathresult;
if [ -n "$devicePath" ];
then
log " Device Path is $devicePath"
numRaidDevices=$((numRaidDevices + 1))
raidDevices="$raidDevices $devicePath "
else
log "no device path for LUN $lun"
exit -1;
fi
done
log "num: $numRaidDevices paths: '$raidDevices'"
log "pvcreate $raidDevices"
$(pvcreate $raidDevices)
log "vgcreate $vgName $raidDevices"
$(vgcreate $vgName $raidDevices)
for ((j=0; j<mountPathCount; j++))
do
local mountPathLoc=${mountPathA[$j]}
local sizeLoc=${sizeA[$j]}
local lvNameLoc="$lvName-$j"
if [ $mountPathLoc == "/hana/data" ];
then
# https://docs.microsoft.com/en-us/azure/virtual-machines/workloads/sap/hana-vm-operations-storage
log "lvcreate --extents $sizeLoc%VG --stripes $numRaidDevices --stripesize 256k --name $lvNameLoc $vgName"
$(lvcreate --extents $sizeLoc%VG --stripes $numRaidDevices --stripesize 256k --name $lvNameLoc $vgName)
else
$(lvcreate --extents $sizeLoc%VG --stripes $numRaidDevices --stripesize 64k --name $lvNameLoc $vgName)
log "lvcreate --extents $sizeLoc%VG --stripes $numRaidDevices --stripesize 64k --name $lvNameLoc $vgName"
fi
$(mkfs -t xfs /dev/$vgName/$lvNameLoc)
$(mkdir -p $mountPathLoc)
log "addtofstab /dev/$vgName/$lvNameLoc $mountPathLoc"
addtofstab /dev/$vgName/$lvNameLoc $mountPathLoc
done
else
log "createlvm - creating single disk"
local lun=${lunsA[0]}
local mountPathLoc=${mountPathA[0]}
getdevicepath $lun;
local devicePath=$getdevicepathresult;
if [ -n "$devicePath" ];
then
log " Device Path is $devicePath"
# http://superuser.com/questions/332252/creating-and-formating-a-partition-using-a-bash-script
$(echo -e "n\np\n1\n\n\nw" | fdisk $devicePath) > /dev/null
local partPath="$devicePath""1"
$(mkfs -t xfs $partPath) > /dev/null
$(mkdir -p $mountPathLoc)
addtofstab $partPath $mountPathLoc
else
log "no device path for LUN $lun"
exit -1;
fi
fi
log "createlvm done"
}
log $@
luns=""
names=""
paths=""
sizes=""
while true;
do
case "$1" in
"-luns") luns=$2;shift 2;log "found luns"
;;
"-names") names=$2;shift 2;log "found names"
;;
"-paths") paths=$2;shift 2;log "found paths"
;;
"-sizes") sizes=$2;shift 2;log "found sizes"
;;
*) log "unknown parameter $1";shift 1;
;;
esac
if [[ -z "$1" ]];
then
break;
fi
done
lunsSplit=(${luns//#/ })
namesSplit=(${names//#/ })
pathsSplit=(${paths//#/ })
sizesSplit=(${sizes//#/ })
lunsCount=${#lunsSplit[@]}
namesCount=${#namesSplit[@]}
pathsCount=${#pathsSplit[@]}
sizesCount=${#sizesSplit[@]}
log "count luns: $lunsCount names: $namesCount paths: $pathsCount sizes: $sizesCount"
if [[ $lunsCount -eq $namesCount && $namesCount -eq $pathsCount && $pathsCount -eq $sizesCount ]]
then
for ((ipart=0; ipart<lunsCount; ipart++))
do
lun=${lunsSplit[$ipart]}
name=${namesSplit[$ipart]}
path=${pathsSplit[$ipart]}
size=${sizesSplit[$ipart]}
log "creating disk with $lun $name $path $size"
createlvm $lun "vg-$name" "lv-$name" "$path" "$size";
done
else
log "count not equal"
fi
exit