1

I found a script to create alias for multipath for Nimble volumes and I modified it to work in freenas the content of it is

#/bin/bash
# This script will scan the system for attached Nimble Volumes
# and output a list of multipath alias statements for the linux
# /etc/multipath.conf.  This will allow for the volume to be 
# referenced by the volume name in place of the normal mpathX
# 
# To use the script, just run it.  If Nimble volumes are present
# it will output the confiugration data to standard out
# Just copy and paste that output in to /etc/multipath.conf
# Take care when adding these lines to make sure another alias
# is not present or if there are other multipath statements

# Start by checking to see if we have any Nimble volumes connected
ls -l /dev/disk/by-path | grep freenas > /dev/null

if [ $? -eq 0 ] 
then

#Build list of Nimble devices
DEV_LIST=$(ls -l /dev/disk/by-path | grep freenas | awk '{print $NF'} | sed 's/..\/..\///')

# Output the first line of the config
echo "multipaths {"

# For each device found we determine the name and the mpathid
for i in $DEV_LIST
    do

    SUBSTRING=$(ls -l /dev/disk/by-path | grep $i  | awk -F: '{print $4}') 

    # This uses pattern matching to find the name of the volume
    OFFSET=$(echo $SUBSTRING | awk --re-interval 'match($0, /\-[v][a-z0-9]{16}/) { print RSTART-1 }')
    NIMBLEVOL=${SUBSTRING::$OFFSET}

    # Here we collect the MPATHID
    MPATHID=$(multipath -ll /dev/$i | grep FreeBSD | awk '{print $2}' | sed -e 's\(\\g' | sed -e 's\)\\g')

    # Enable for debug
    #echo "Volume name for $device is $nimblevol with multipath ID is $mpathid"

    # Putting it all together with proper formatting using printf
    MULTIPATH=$(printf "multipath {\n \t\twwid \t\t%s \n \t\talias\t\t %s\n \t}" $MPATHID $NIMBLEVOL)
    MATCH='multipaths {'

    echo "$MULTIPATH"

    done

    # End the configuration section
    echo "}"
else 

    # If no Nimble devices found, exit with message
    echo "No Nimble Devices Found, have you met leeloo?"
    exit 1
fi

exit 0

when I run it it get

multipaths {
multipath {
                wwid            36589cfc000000e9f2e24f431339ec7b0
                alias
        }
multipath {
                wwid            36589cfc00000026c07d6caed9e43aa22
                alias
        }
multipath {
                wwid            36589cfc000000f051b0d5718e0b46b2f
                alias
        }
multipath {
                wwid            36589cfc000000af38b5be525e3cf1cb4
                alias
        }
multipath {
                wwid            36589cfc000000824684e211c61d58fc5
                alias
        }
multipath {
                wwid            36589cfc000000f0f579280a94ef72125
                alias
        }
multipath {
                wwid            36589cfc000000e9f2e24f431339ec7b0
                alias
        }
multipath {
                wwid            36589cfc00000026c07d6caed9e43aa22
                alias
        }
multipath {
                wwid            36589cfc000000f051b0d5718e0b46b2f
                alias
        }
multipath {
                wwid            36589cfc000000af38b5be525e3cf1cb4
                alias
        }
multipath {
                wwid            36589cfc000000824684e211c61d58fc5
                alias
        }
multipath {
                wwid            36589cfc000000f0f579280a94ef72125
                alias
        }
}

without any alias do you have any suggestions??

  • either SUBSTRING or OFFSET failed to initialize properly, besides devices are listed twice. – Archemar Feb 27 '16 at 14:43
  • SUBSTRING is fine as i get output but i think OFFSET is the problem so can you help me please – Khalid Abo El MaGd Feb 27 '16 at 14:47
  • How does the ls -l /dev/disk/by-path output look like? – Thomas Feb 27 '16 at 14:51
  • can you edit your post with a sample of SUBSTRING ? – Archemar Feb 27 '16 at 14:51
  • SUBSTIRNGacsf-lun-0 -> ../../sdd data1-lun-0 -> ../../sdm data2-lun-0 -> ../../sdj ocr1-lun-0 -> ../../sdf ocr2-lun-0 -> ../../sdb ocr3-lun-0 -> ../../sdh acsf-lun-0 -> ../../sde data1-lun-0 -> ../../sdk data2-lun-0 -> ../../sdl ocr1-lun-0 -> ../../sdg ocr2-lun-0 -> ../../sdc ocr3-lun-0 -> ../../sdi – Khalid Abo El MaGd Feb 27 '16 at 14:52
1

Comment the lines starting with OFFSET= and NIMBLEVOL= and insert

NIMBLEVOL=$(echo $SUBSTRING | sed -e 's/^\(.*\)-lun.*/\1/')

right below the commented lines.

...
#OFFSET=$(echo $SUBSTRING | awk --re-interval 'match($0, /\-[v][a-z0-9]{16}/) { print RSTART-1 }')
#NIMBLEVOL=${SUBSTRING::$OFFSET}
NIMBLEVOL=$(echo $SUBSTRING | sed -e 's/^\(.*\)-lun.*/\1/')
...

Not sure if that will really will create a valid configuration, assuming you want to have data1, data2 etc as alias.

  • how to remove duplicates?? – Khalid Abo El MaGd Feb 27 '16 at 15:44
  • Might be not too easy without rewriting the complete script.Can you post the complete output of ls -l /dev/disk/by-path. But please use pastebin to copy the output. – Thomas Feb 27 '16 at 16:06
  • pastebin.com/2bNNJDJ2 – Khalid Abo El MaGd Feb 27 '16 at 16:10
  • I suggest to modify the for loop to count the half of the i entries if it possible?? – Khalid Abo El MaGd Feb 27 '16 at 16:13
  • Maybe for now it's best to edit the duplicates with a text editor and rewrite the script from scratch. Not really sure, the more I think about the script the more I suppose it's better to search for the volume names the other way round. wwid -> /dev/sd* -> <volume-name> – Thomas Feb 27 '16 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.