Growing SAN LUN on Linux

This procedure works on SLES 15, should work on RHEL, but not yet tested.

This script is for growing SAN LUNs running via multipath on Linux. Makes it look like AIX and just as easy!

Growing SAN LUNs in Linux is a rather frustrating affair, as Googling the subject will tell you. As many different methods as Google hits. This script, ‘chvg’, combines the tools needed, and targets only the volume group you have extended LUNs for.

#!/bin/bash

####################################
# chvg script to increase disk in VG
####################################

# Version history
#
# 2022-09-14    HM      1.0     Initial
#

ver=1.0

# Set variables
today="$(date +%Y-%m-%d)"

# Setup a little usage function
helpFunction()
{
   echo ""
   echo "Usage: $0 -g <Volume Group>"
   echo -e "\t-g Update size of disks in volume group"
   exit 1 # Exit script after printing help
}

# Set a bogus VG to pick up running script with no arguments
VG="Gobbledegook"

# Pick out options
while getopts "g:" opt
do
   case "$opt" in
      g ) VG="$OPTARG" ;;
      ? ) helpFunction ;; # Print helpFunction in case parameter is non-existent
   esac
done

# If VG isn't right, exit with help text
vgs ${VG} >/dev/null 2>&1 || helpFunction

# Save a copy of the current multipathed disks
multipath -ll > /tmp/multipath.before.out.${today}

# Find disks in VG
disks="$(pvs | grep -w ${VG} | awk '{ print $1 }' | awk -F/ '{ print $NF }' | tr '\n' '
')"

# Find paths
for disk in ${disks}
do
   # Find first set of paths
   paths1="$(multipath -ll ${disk} | grep -v -- "-+-" | grep "| |-" | awk '{ print $4 }')"

   # Find second set of paths
   paths2="$(multipath -ll ${disk} | grep -v -- "-+-" | grep -v "| |-" | grep "|-" | awk '{ print $3 }')"

   # Find last disk in first set
   paths3="$(multipath -ll ${disk} | grep -- "| \`-" | awk '{ print $4 }')"

   # Find last disk in second set
   paths4="$(multipath -ll ${disk} | grep -- "  \`-" | awk '{ print $3 }')"

   # Add to full list of paths
   allpaths=${allpaths}" "${paths1}" "${paths2}" "${paths3}" "${paths4}
done

# Now set the paths to rescan
for path in ${allpaths}
do
   # Write a true to the rescan parameter for the device
   echo 1 > /sys/block/${path}/device/rescan
done

# Now restart multipathd to rescan ("Linux" magic)
systemctl restart multipathd

# And save the new multipath output
multipath -ll > /tmp/multipath.after.out.${today}

# Resize the PVs in the VG
for pv in ${disks}
do
   pvresize /dev/mapper/${pv}
done

exit 0
This entry was posted in Linux, Scripting and tagged , , , , . Bookmark the permalink.

Leave a Reply