[ceph] add tool to locate the block device

This commit is contained in:
Nico Schottelius 2023-06-10 13:58:21 +02:00
parent f2df5e8c48
commit 20ed1abc37
1 changed files with 43 additions and 0 deletions

43
ceph/find-osd-device.sh Executable file
View File

@ -0,0 +1,43 @@
#!/bin/sh
# Locate which block device corresponds to the OSD
# Nico Schottelius, 2023-06-10
if [ $# -ne 1 ]; then
echo $0 osdnum
echo f.i. $0 99
exit 1
fi
osdid=$1; shift
osd_path=/var/lib/ceph/osd/ceph-${osdid}
mountpath=$(mount | grep "on ${osd_path} ")
if [ -z ${mountpath} ]; then
echo "Nothing mounted on ${osd_path}, are you on the right host?"
exit 1
fi
blockdev=$(readlink -f ${mountpath}/block)
# Is directly referring to sdX? print and exit
if echo $blockdev | grep -q ^/dev/sd; then
echo $blockdev
exit 0
fi
# try the non-recursive variant, resulting in finding pv/vg
blockdev=$(readlink ${mountpath}/block)
lvm_vg=$(echo $blockdev | awk -F/ '{ print $3 }')
pv_name=$(pvdisplay | grep -B1 $lvm_vg | awk '/PV Name/ { print $3 }')
if [ "$pv_name" ]; then
echo $pv_name
exit 0
fi
echo "Cannot determine block device for osd.${osdid}" >&2
exit 1