Created
January 10, 2022 15:41
-
-
Save ilmarkerm/93dcec2ee44f415467e7e43254e7e8bb to your computer and use it in GitHub Desktop.
Remove multipath LUN from Linux without reboot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script for removing multipathed LUNs from Linux hosts without a reboot | |
# 2022 Ilmar Kerm | |
if [ $# -eq 0 ]; then | |
echo "Usage: remove_lun.sh lunid" | |
echo "Example: remove_lun.sh 36005076810818379800000000000000c" | |
exit 1 | |
fi | |
# Find DM device name | |
lunid="$1" | |
dmdev=$(multipath -ll "$lunid" | grep "$lunid" | cut -d' ' -f 2) | |
if [[ -z "$dmdev" || "${dmdev:0:3}" != "dm-" ]]; then | |
echo "Did not find DM device" | |
exit 1 | |
fi | |
echo "LUN: $lunid" | |
echo "DM device: $dmdev" | |
# Find slave devices | |
if [ ! -d "/sys/block/${dmdev}/slaves" ]; then | |
echo "Should not be here. Did not find directory /sys/block/${dmdev}/slaves" | |
exit 1 | |
fi | |
# Remove slave devices | |
for f in $(ls -1 "/sys/block/${dmdev}/slaves" ); do | |
echo -n "Removing slave: $f" | |
echo 1 > /sys/block/$f/device/delete | |
echo " done" | |
done | |
# Remove multipath device | |
sleep 5s | |
multipath -f "$lunid" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment