Skip to content

Instantly share code, notes, and snippets.

@wido
Last active January 30, 2018 12:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wido/4a8539b49956fcaaae8db3ae0658102b to your computer and use it in GitHub Desktop.
Save wido/4a8539b49956fcaaae8db3ae0658102b to your computer and use it in GitHub Desktop.
Stop, umount and wipe all Ceph OSDs on a system
#!/bin/bash
set -e
systemctl stop ceph-osd.target
for ID in $(df -P|grep "/var/lib/ceph/osd"|awk '{print $6}'|cut -d '-' -f 2); do
DEVICE=$(df -P /var/lib/ceph/osd/ceph-$ID|awk '{print $1}'|tail -1|sed 's/.$//'|cut -d '/' -f 3)
ROTATIONAL=$(cat /sys/block/$DEVICE/queue/rotational)
echo "Stopping osd.$ID"
systemctl stop ceph-osd@$ID
umount /var/lib/ceph/osd/ceph-$ID
if [ "$ROTATIONAL" -eq 0 ]; then
echo "Issuing a blkdiscard for $DEVICE"
blkdiscard /dev/$DEVICE
else
echo "Zapping device $DEVICE"
ceph-disk zap /dev/$DEVICE
fi
blockdev --rereadpt /dev/$DEVICE
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment