Last active
December 9, 2015 23:08
-
-
Save epleterte/4341982 to your computer and use it in GitHub Desktop.
resize logical volumes in volume groups on multipath devices
only works with one logical volume per volume group
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -ue | |
function list_paths() { | |
multipath -ll -v 1 | |
} | |
function print_usage() { | |
cat <<EOF | |
Multipath device resizer | |
Resize multipath device if one LV in one VG on a multipath device PV | |
with FS supported by resize2fs. | |
Usage: ${0} [-h|-l] <multipath device> | |
-h Halp | |
-l List available multipath devices | |
EOF | |
} | |
while getopts hl o | |
do | |
case $o in | |
h) | |
print_usage ; exit ;; | |
l) | |
list_paths ; exit ;; | |
esac | |
done | |
shift $(($OPTIND-1)) | |
[ $# -eq 0 ] && { echo 'error: you must provide at least one multipath device to resize'; exit 1; } | |
mdevices="${@}" | |
available_mdevices=($(list_paths)) | |
for mdevice in ${mdevices}; do | |
# check if mdevice exists in list of valid mdevices using substring removel | |
[[ "${available_mdevices[@]}" == "${available_mdevices[@]#${mdevice}}" ]] && { echo "error: mdevice ${mdevice} does not seem to be a valid one"; continue; } | |
# find devices | |
# XXX: is there a better way to list devices? | |
echo "resizing multipath device ${mdevice}" | |
devices=$( multipath -ll "${mdevice}" | grep 'active\]\[ready' | awk '{ print $3 }' ) | |
[ "${devices}" == "" ] && { echo "error: no devices found for ${mdevice}"; continue; } | |
# rescan devices | |
for a in ${devices}; do echo 1 >/sys/block/$a/device/rescan; done | |
multipathd -k"resize map ${mdevice}" | |
#pvresize /dev/mpath/${mdevice} | |
# XXX: this is not so pretty | |
p=$( echo $mdevice | sed -e 's/3[Pp]ar[12]_//' -e "s/$(hostname -s)_//" -e 's/_1$//' ) || true | |
#pvinfo=($( pvs --noheadings -o pv_name,vg_name | grep $mdevice )) | |
# ughh, a lot of special cases in naming. ugggly trix for catching more cases follows.. | |
pvinfo=($( pvs --noheadings -o pv_name,vg_name | grep $p )) || true | |
[ "${pvinfo:-}" == "" ] && p=$( echo $mdevice | sed -e 's/3[Pp]ar[12]_//' -e "s/$(hostname -s)_//" -e 's/_1$//' -e 's/_data//') | |
# intentional: rerun with possibly changed $p (if not it returns the same as above). XXX: check for varuable change instead? B) | |
pvinfo=($( pvs --noheadings -o pv_name,vg_name | grep $p )) | |
mpath=${pvinfo[0]} | |
vgroup=${pvinfo[1]} | |
pvresize ${mpath} | |
# this last bit...needs work. | |
#lvextend -l +100%FREE /dev/mapper/<volume> | |
lvcount=$( vgs --noheadings -o lv_count "${vgroup}" ) | |
[ $lvcount -gt 1 ] && { echo "error: multiple disks in VG ${vgroup} - don't know which one to lvextend and resize - needs manual intervention"; continue; } | |
#lvol=$( lvs --noheadings -o lv_name "${vgroup}" ) | |
#lvextend -L +100%FREE /dev/${vgroup}/${lvol} | |
lvolpath=$( lvs --noheadings -o lv_path "${vgroup}" ) | |
lvextend -l +100%FREE ${lvolpath} | |
resize4fs ${lvolpath} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment