Skip to content

Instantly share code, notes, and snippets.

@TyeolRik
Last active June 24, 2024 00:43
Show Gist options
  • Save TyeolRik/f2dad77db44d394d71a61f67287b210b to your computer and use it in GitHub Desktop.
Save TyeolRik/f2dad77db44d394d71a61f67287b210b to your computer and use it in GitHub Desktop.
Remove Ceph OSD forcefully
#!/bin/bash
# This is really dangerous command.
# Please be CAREFUL
TARGET_OSD_ID="$1" # 6
TARGET_HOST_NAME=$(ceph orch ps --daemon_type osd --format json| jq -r '.[] | select(.daemon_id == '\""$TARGET_OSD_ID"\"') | .hostname')
TARGET_DAEMON_NAME=$(ceph orch ps --daemon_type osd --format json | jq -r '.[] | select(.daemon_id == '\""$TARGET_OSD_ID"\"') | .daemon_name')
TARGET_OSD_DEV_PATH=$(ceph device ls-by-host "${TARGET_HOST_NAME}" --format json | jq -r '.[] | select(.daemons[] | contains('\""${TARGET_DAEMON_NAME}"\"')) | .location[] | .dev')
# ceph orch ls --service_type osd --format json | jq -c '.[] | select(.spec.data_devices.paths != null) | select(.spec.data_devices.paths[] | contains('\"${TARGET_OSD_DEV_PATH}\"')) | select(.placement.hosts != null) | select(.placement.hosts[] | contains('\"${TARGET_HOST_NAME}\"'))'
SERVICE_NAME=$(ceph orch ls --service_type osd --format json | jq -c '.[] | select(.spec.data_devices.paths != null) | select(.spec.data_devices.paths[] | contains('\""${TARGET_OSD_DEV_PATH}"\"')) | select(.placement.hosts != null) | select(.placement.hosts[] | contains('\""${TARGET_HOST_NAME}"\"'))' | jq -r '.service_name')
ceph orch rm "${SERVICE_NAME}" --force
ceph osd down "$TARGET_OSD_ID"
ceph osd purge "$TARGET_OSD_ID" --force --yes-i-really-mean-it
ceph orch daemon rm "${TARGET_DAEMON_NAME}" --force
@TyeolRik
Copy link
Author

TyeolRik commented Dec 20, 2023

# zap disk
sgdisk --zap-all "/dev/${TARGET_OSD_DEV_PATH}"
dd if=/dev/zero of=/dev/"${TARGET_OSD_DEV_PATH}" bs=1M count=100 oflag=direct,dsync

# Remove at lsblk
ls /dev/mapper/ceph-* | xargs -I% -- dmsetup remove %
rm -rf /dev/ceph-*

ceph- 부분은 적절하게 잘 해서 삭제할 것.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment