84 lines
2.2 KiB
Bash
84 lines
2.2 KiB
Bash
|
|
#!/usr/bin/env bash
|
||
|
|
set -o errexit
|
||
|
|
set -o nounset
|
||
|
|
set -o pipefail
|
||
|
|
|
||
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||
|
|
# shellcheck source=00_env.sh
|
||
|
|
. "$SCRIPT_DIR/00_env.sh"
|
||
|
|
|
||
|
|
EXCLUDE_MOUNTED=false
|
||
|
|
EXCLUDE_EXISTING_NSD=false
|
||
|
|
|
||
|
|
usage() {
|
||
|
|
printf 'Usage: %s [--exclude-mounted] [--exclude-existing-nsd]\n' "$(basename "$0")"
|
||
|
|
}
|
||
|
|
|
||
|
|
while [[ "$#" -gt 0 ]]; do
|
||
|
|
case "$1" in
|
||
|
|
--exclude-mounted)
|
||
|
|
EXCLUDE_MOUNTED=true
|
||
|
|
shift
|
||
|
|
;;
|
||
|
|
--exclude-existing-nsd)
|
||
|
|
EXCLUDE_EXISTING_NSD=true
|
||
|
|
shift
|
||
|
|
;;
|
||
|
|
-h|--help)
|
||
|
|
usage
|
||
|
|
exit 0
|
||
|
|
;;
|
||
|
|
*)
|
||
|
|
critical "Unknown argument: $1"
|
||
|
|
usage
|
||
|
|
exit 2
|
||
|
|
;;
|
||
|
|
esac
|
||
|
|
done
|
||
|
|
|
||
|
|
for cmd in lsblk findmnt; do
|
||
|
|
require_cmd "$cmd" || exit 2
|
||
|
|
done
|
||
|
|
|
||
|
|
warning "Candidate devices are not automatically safe. Confirm every device with the storage and cluster teams before use."
|
||
|
|
|
||
|
|
existing_gpfs_devices=""
|
||
|
|
if [[ "$EXCLUDE_EXISTING_NSD" == "true" ]]; then
|
||
|
|
if command -v mmlsnsd >/dev/null 2>&1; then
|
||
|
|
existing_gpfs_devices="$(mmlsnsd 2>/dev/null || true)"
|
||
|
|
elif command -v mmlsdisk >/dev/null 2>&1; then
|
||
|
|
existing_gpfs_devices="$(mmlsdisk all 2>/dev/null || true)"
|
||
|
|
else
|
||
|
|
warning "mmlsnsd and mmlsdisk are unavailable; cannot exclude existing GPFS devices"
|
||
|
|
fi
|
||
|
|
fi
|
||
|
|
|
||
|
|
section "Block device inventory"
|
||
|
|
lsblk -dpno NAME,TYPE,SIZE,MODEL,SERIAL,MOUNTPOINT 2>&1 | tee -a "$LOG_FILE"
|
||
|
|
|
||
|
|
section "Candidate devices"
|
||
|
|
found=0
|
||
|
|
while read -r name type size model serial mountpoint; do
|
||
|
|
[[ "$type" == "disk" ]] || continue
|
||
|
|
|
||
|
|
if [[ "$EXCLUDE_MOUNTED" == "true" ]]; then
|
||
|
|
if [[ -n "${mountpoint:-}" ]] || findmnt -rn --source "$name" >/dev/null 2>&1; then
|
||
|
|
continue
|
||
|
|
fi
|
||
|
|
fi
|
||
|
|
|
||
|
|
if [[ "$EXCLUDE_EXISTING_NSD" == "true" ]] && [[ -n "$existing_gpfs_devices" ]]; then
|
||
|
|
if printf '%s\n' "$existing_gpfs_devices" | grep -Fq "$name"; then
|
||
|
|
continue
|
||
|
|
fi
|
||
|
|
fi
|
||
|
|
|
||
|
|
printf 'OK: candidate=%s size=%s model=%s serial=%s mountpoint=%s\n' \
|
||
|
|
"$name" "${size:-unknown}" "${model:-unknown}" "${serial:-unknown}" "${mountpoint:-none}" | tee -a "$LOG_FILE"
|
||
|
|
found=1
|
||
|
|
done < <(lsblk -dpno NAME,TYPE,SIZE,MODEL,SERIAL,MOUNTPOINT)
|
||
|
|
|
||
|
|
if [[ "$found" -eq 0 ]]; then
|
||
|
|
warning "No candidate devices found with the selected filters"
|
||
|
|
fi
|