Wednesday, February 20, 2013

Linux : Deleting Multiple Multipath Devices


How to delete multiple Linux DM-MPIO (Device Mapper - Multi Path IO ) devices from a Linux system?


From below command output, find wwid of multipath devices you want to remove and list them in a file.

  multipath -l |grep dm-
  vi /tmp/wwid_of_multipath_devices_to_delete.txt
  cat /tmp/wwid_of_multipath_devices_to_delete.txt


Verify the details of devices you are going to remove

  while read i ; do multipath -ll $i ; done </tmp/wwid_of_multipath_devices_to_delete.txt

Collect LUN's scsi ID of multipath devices you are going to delete
  
   while read i ; do
     multipath -l $i|grep -E "[0-9]{1,2}:{1,4}"|awk '{print $2}'|awk '{print $2}'
   done </tmp/wwid_of_multipath_devices_to_delete.txt | sort -u > /tmp/disks_scsi_id.txt
   cat /tmp/disks_scsi_id.txt


Ensure multipath devices are not used on system. Flush multipath device information

   multipath -ll > multipath-output-pre.txt
       multipath -ll | grep -E "$(cat wwid_of_multipath_devices_to_delete.txt |grep -v "^$"|tr '\n' '|')xxxxyyy"|awk '{print $1}' | tee multipath_disk_alias_name.txt
     cat multipath_disk_alias_name.txt
   while read i ; do
        multipath -f $i
        echo "$i flushed"
   done </tmp/multipath_disk_alias_name.txt
       multipath -ll > multipath-output-post.txt
       diff multipath-output-pre.txt multipath-output-post.txt 


Now they should NOT be seen in multipath output
  
    while read i ; do 
         multipath -ll $i
   done </tmp/wwid_of_multipath_devices_to_delete.txt

Delete LUN details from the Linux Kernel

   while read j ; do
     echo 1 > /sys/bus/scsi/drivers/sd/$j/delete
     echo "$j deleted"
   done </tmp/disks_scsi_id.txt


Delete the device information from /etc/multipath.conf

  cp -a /etc/multipath.conf /etc/multipath.conf.ORG
  vi /etc/multipath.conf


Restart multipathd and verify that the disks have been deleted and no more recognized by multipathd. Below should not list any device

  service multipathd restart
  while read i ; do multipath -ll |grep $i ; done </tmp/wwid_of_multipath_devices_to_delete.txt
  while read i; do ls -l /dev/mapper/|grep $i; done </tmp/wwid_of_multipath_devices_to_delete.txt


Unmask LUN from system on Storage SAN Switch/Frame


If you decide to add the LUNs again on same system, mask the LUN on system, rescan the BUS and add them in multipath.conf

  for i in $(ls /sys/class/scsi_host/) ; do echo - - - > /sys/class/scsi_host/$i/scan ; done
  service multipathd restart
  multiptah -ll | grep dm-
  vi /etc/multipath.conf
  service multipathd reload



References
http://www.kernel.org/doc/ols/2005/ols2005v1-pages-155-176.pdf
http://en.wikipedia.org/wiki/Linux_DM_Multipath


No comments:

Post a Comment