Created
November 8, 2010 13:19
-
-
Save keymon/667682 to your computer and use it in GitHub Desktop.
Initial commit of script to change the exported LUN (the lun that the client gets) of a mapped Virtual Target Disk in a VIOS.
This file contains 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/sh | |
SCRIPT_NAME=$0 | |
if [ $# -lt 2 ]; then | |
cat <<EOF | |
Updates the exported LUN of a mapped VTD (Virtual Target Device) device in a VIOS. | |
This script will set the device to "Defined" stated and then rescan the Virtual Adapter: | |
rmdev -l vtd | |
odmget | odmchange | |
cfgmgr -l vhostX | |
Usage: | |
$SCRIPT_NAME <vtd> <newlun> | |
EOF | |
exit | |
fi | |
vtd=$1 | |
lun=$2 | |
# Check the vtd | |
if ! lsdev -l $vtd | grep -q "Virtual Target Device"; then | |
echo "$SCRIPT_NAME: The device '$vtd' does not exists or is not a Virtual Target Device" 1>&2 | |
exit 1 | |
fi | |
# Check the lun number | |
lun=$(echo $lun | tr a-f A-F | awk '/0x[0-9A-F]{16}/ {print}') | |
if [ -z "$lun" ]; then | |
echo "$SCRIPT_NAME: Lun must have format "0xNNNNNNNNNNNNNNNN" (16 digits)" 1>&2 | |
exit 1 | |
fi | |
# check that lun changes | |
actual_lun=$(odmget -q "name=$vtd and attribute=LogicalUnitAddr" CuAt| \ | |
sed -n 's/.*value = "\(.*\)"/\1/p' | tr a-f A-F) | |
if [ "$lun" == "$actual_lun" ]; then | |
echo "$SCRIPT_NAME: lun already is $lun for '$vtd'. No change." 1>&2 | |
exit 0 | |
fi | |
# change the lun. | |
# 1. set the VTD to defined | |
# 2. update odm | |
# 4. cfgmgr vadapter | |
vadapter=$(lsdev -Cl $vtd -F parent) | |
echo "Updating the lun of $vadapter.$vtd..." | |
rmdev -l $vtd > /dev/null | |
odmget -q "name=$vtd and attribute=LogicalUnitAddr" CuAt | \ | |
sed "s/value =.*/value = \"$lun\"/" | \ | |
odmchange -q "name=$vtd and attribute=LogicalUnitAddr" -o CuAt | |
cfgmgr -l $vadapter | |
lsattr -El $vtd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment