-
Notifications
You must be signed in to change notification settings - Fork 3
/
colo_lvm_osds.sh
executable file
·128 lines (104 loc) · 2.85 KB
/
colo_lvm_osds.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
#!/bin/bash
#
# colo_lvm_osds.sh
#
# by Michael J. Kidd ([email protected])
# Version 1.0, 2018-09-27, Initial Release
#
usage() {
cat <<EOF
Usage:
$0 <journalsize> <devpath> [<devpath>...]
Where:
<journalsize> The desired size of the journal in Gigabytes
Example, for 10 GB: 10
<devpath> The device path of the new co-located OSD
Multiple can be specified as space separated list
Example: /dev/sdb /dev/sdc
Examples:
$0 10 /dev/sdb /dev/sdc
EOF
exit 1
}
errorout() {
cat <<EOF
ERROR! Something went wrong.
$1
EOF
exit $2
}
if [ $# -lt 2 ]; then
echo "Error: Too few arguments"
echo
usage
fi
if [ $(echo $1 | grep -c ^[0-9]*$) -ne 1 ]; then
echo "Error: $1 is not an integer."
echo
usage
fi
devlist=()
for((devidx=2;devidx<=$#;devidx++)) {
if [ ! -e ${!devidx} ]; then
echo "Error: ${!devidx} does not exist, skipping..."
continue
fi
if [ ! -b ${!devidx} ]; then
echo "Error: ${!devidx} is not a block device, skipping..."
continue
fi
devlist+=(${!devidx})
}
if [ ${#devlist[@]} -eq 0 ]; then
echo "Error: None of the specified devices exist. Exiting."
echo
usage
fi
prep_device() {
devpath=$1
devtype=$2
sgdisk -Z $devpath
RETVAL=$?
if [ $RETVAL -ne 0 ]; then
errorout "sgdisk failed to zap ${devpath} with error code $RETVAL" $RETVAL
fi
sgdisk -n 0:0:0 -t 8300 -c 0:"Ceph $2 LVM" $devpath
RETVAL=$?
if [ $RETVAL -ne 0 ]; then
errorout "sgdisk failed to create the necessary partition on ${devpath} with error code $RETVAL" $RETVAL
fi
pvcreate ${devpath}1 -y
RETVAL=$?
if [ $RETVAL -ne 0 ]; then
errorout "pvcreate failed to create the Physical Volume on ${devpath} with error code $RETVAL" $RETVAL
fi
vgcreate ceph-$(basename $devpath) ${devpath}1 -y
RETVAL=$?
if [ $RETVAL -ne 0 ]; then
errorout "vgcreate failed to create the Volume Group ceph-$(basename $devpath) with error code $RETVAL" $RETVAL
fi
}
for devpath in "${devlist[@]}"; do
prep_device $devpath Collocated
journalExtents=$((($1*1024)/4))
lvcreate -l $journalExtents -n journal ceph-$(basename $devpath) ${devpath}1 -y
RETVAL=$?
if [ $RETVAL -ne 0 ]; then
errorout "lvcreate failed to create the Logical Volume ceph-$(basename $devpath)/journal with error code $RETVAL" $RETVAL
fi
lvcreate -l 100%FREE -n data ceph-$(basename $devpath) ${devpath}1 -y
RETVAL=$?
if [ $RETVAL -ne 0 ]; then
errorout "lvcreate failed to create the Logical Volume ceph-$(basename $devpath)/data with error code $RETVAL" $RETVAL
fi
done
cat <<EOF
Creation Complete!
Please add the following to the 'lvm_volumes:' section of /usr/share/ceph-ansible/group_vars/osds.yml
EOF
for devpath in "${devlist[@]}"; do
cat <<EOF
- data: ceph-$(basename $devpath)/data
journal: ceph-$(basename $devpath)/journal
EOF
done