Pages

Finds dead LUNs and removes them automatically after confirmation

finds dead EMC LUNs (disks seen by AIX but not managed by PowerPath) but also removes them automatically after confirmation.

How It Works:
  • powermt check refreshes PowerPath device status.
  • Collects all active PowerPath LUNs (powermt display dev=all).
  • Collects all EMC disks known to AIX (lsdev -Cc disk | grep EMC).
  • Compares both lists using comm -23 to identify dead LUNs.
  • Displays all dead disks to the user.
  • Prompts for confirmation before removing.
  • Runs rmdev -dl <disk> for each dead LUN safely.
  • Verifies removal and prints a summary.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#!/bin/ksh
# ------------------------------------------------------------------------------
# Script Name : remove_dead_luns_powermt.ksh
# Purpose     : Identify and remove EMC disks defined in AIX but not managed by PowerPath
# Platform    : AIX
# Author      : Tasleem A Khan
# ------------------------------------------------------------------------------

echo ">>> Running powermt check....................................................................."
powermt check >/dev/null 2>&1
sleep 2

# Temporary files
POWER=/tmp/power_active.list
DISK=/tmp/aix_defined.list
DEAD=/tmp/dead_luns.list

# Clean up old temp files
> $POWER
> $DISK
> $DEAD

echo ">>> Collecting active PowerPath LUNs........................................................"
# List all PowerPath device names (e.g., hdiskpowerX)
powermt display dev=all | grep fscsi | awk '{print $3}' | sort -u > $POWER

echo ">>> Collecting all EMC-defined disks from AIX................................................"
# Get list of EMC disks currently defined to AIX
lsdev -Cc disk | grep EMC | awk '{print $1}' | sort -u > $DISK

echo ">>> Comparing AIX-defined EMC disks against PowerPath-managed disks.........................."
# Find disks present in AIX but missing from PowerPath
comm -23 $DISK $POWER > $DEAD

echo ""
if [ ! -s $DEAD ]; then
    echo ">>> No dead LUNs found — all EMC disks are managed by PowerPath."
    echo ">>> Cleanup complete."
    rm -f $POWER $DISK $DEAD
    exit 0
fi

echo ">>> Dead LUNs detected (present in AIX but not managed by PowerPath):"
cat $DEAD
echo ""
echo "These disks appear to be stale/unmanaged LUNs and can be safely removed from AIX."
echo ""

# Confirm removal
echo "Do you want to remove these dead LUNs from the system? (y/n)\c"
read answer

if [ "$answer" != "y" ]; then
    echo ">>> Operation cancelled by user. No disks were removed."
    rm -f $POWER $DISK $DEAD
    exit 0
fi

echo ""
echo ">>> Starting LUN removal process............................................................."
while read disk
do
    if [ -n "$disk" ]; then
        echo " - Removing $disk ..."
        rmdev -dl $disk >/dev/null 2>&1
        if [ $? -eq 0 ]; then
            echo "   Successfully removed $disk"
        else
            echo "Failed to remove $disk (check if still in use)"
        fi
    fi
done < $DEAD

echo ""
echo ">>> Verifying that all dead LUNs have been removed............................................"
for disk in $(cat $DEAD)
do
    lsdev -Cc disk | grep -w $disk >/dev/null 2>&1
    if [ $? -eq 0 ]; then
        echo "$disk still appears in AIX device list!"
    else
        echo "$disk successfully removed from ODM."
    fi
done

# Summary
echo ""
echo ">>> Summary:"
echo " - Total EMC disks in AIX before : $(wc -l < $DISK)"
echo " - PowerPath-managed disks       : $(wc -l < $POWER)"
echo " - Dead LUNs removed             : $(wc -l < $DEAD)"
echo ""
echo ">>> Dead LUN cleanup complete."

# Clean temp files
rm -f $POWER $DISK $DEAD
exit 0

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

1. Add the above script contents
# vi remove_dead_luns_powermt.ksh
2. Make it executable
# chmod +x remove_dead_luns_powermt.ksh
3. Run script
# ./remove_dead_luns_powermt.ksh
or
# sh remove_dead_luns_powermt.ksh

Script Output:

>>> Running powermt check.....................................................................
>>> Collecting active PowerPath LUNs........................................................
>>> Collecting all EMC-defined disks from AIX................................................
>>> Comparing AIX-defined EMC disks against PowerPath-managed disks..........................

>>> Dead LUNs detected (present in AIX but not managed by PowerPath):
hdisk12
hdisk14

These disks appear to be stale/unmanaged LUNs and can be safely removed from AIX.

Do you want to remove these dead LUNs from the system? (y/n)y

>>> Starting LUN removal process.............................................................
 - Removing hdisk12 ...
   Successfully removed hdisk12
 - Removing hdisk14 ...
   Successfully removed hdisk14

>>> Verifying that all dead LUNs have been removed............................................
   hdisk12 successfully removed from ODM.
   hdisk14 successfully removed from ODM.

>>> Summary:
 - Total EMC disks in AIX before : 20
 - PowerPath-managed disks       : 18
 - Dead LUNs removed             : 2

>>> Dead LUN cleanup complete.






No comments:

Post a Comment