LUN maniuplation in rhel

Title:LUN maniuplation in rhel
Author:Douglas O’Leary <dkoleary@olearycomputers.com>
Description:Commands/processes to manipulate luns in rhel
Date created:08/2013
Date updated:08/2013
Disclaimer:Standard: Use the information that follows at your own risk. If you screw up a system, don’t blame it on me...

Overview:

These commands are available on the web; but, I’m getting tired of hunting them down - and the ones to deallocate luns aren’t out there, from what I’ve seen:

Allocate new lun (without rebooting):

  • Store a copy of the disks before any scans: cp /proc/partitions /tmp/pre
  • ID the number of controllers: ll /sys/class/scsi_host
  • Execute the scan by putting three ‘-‘ separated by spaces into the file called scan under each host#
for i in $(seq 0 #)
do
    echo '- - -' > /sys/class/scsi_host/host${i}/scan
done
  • If the disks don’t show up, and this is a new array that you’re adding, execute a storage array scan
for i in $(seq 0 #)
do
    echo 1 > /sys/class/fc_host/host${i}/issue_lip
done
  • ID any new disks. If no difference, reboot and check again
cp /proc/partitions /tmp/post
diff /tmp/pre /tmp/post
  • Add wwids to blaclist_exceptions section, if appropriate. Check How to ID WWID from lun for details on identifying the wwid
cd /etc; rcsdiff multipath.conf # check it in if differences.
#
for pv in $(diff /tmp/pre /tmp/post | grep sd | awk '{print $NF}')
do
    scsi_id --page=0x83 --whitelisted --device=/dev/${pv}
done| sort -u | while read wwid
do
    print "    wwid \"%s\"\n" ${wwid}
done | tee -a /etc/multipath.conf
vi /etc/multipath.conf # mv newly added wwids to blacklist_exceptions section.
ci -l -m'updated blacklist_exceptions" multipath.conf

Deallocate luns from a system:

  • Ensure luns are not in use:
    • VGs
    • Partitions
    • oracleasm
  • Get list of disks to remove. You’ll need both lists:
    • If you have a list of sd’s, ID multipath devs via multipath -ll ${sd}
    • If you have a list of multipath devs, ID the sds via multipath -ll ${mpath} | awk '{print $3}'
  • Clean up multipath.conf
for pv in $(cat list-o-sds)
do
    scsi_id --page=0x83 --whitelisted --device=/dev/${pv}
done| sort -u | while read wwid
do
    eval "perl -i -nle 'print unless (m{${wwid}})' /etc/multipath.conf"
done
  • Flush mulitpath:

    for mp in $(cat list-o-mpaths)
    do
        multipath -f ${mp}
    done
    
  • Eject the device:

    for pv in $(cat list-o-sds)
    do
        echo 1 > /sys/bloc/${pv}/device/delete
    done
    
  • Possibly reboot if devices aren’t gone from /proc/partitions.