Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save huskercane/a35ad8ba402ca991561a to your computer and use it in GitHub Desktop.

Select an option

Save huskercane/a35ad8ba402ca991561a to your computer and use it in GitHub Desktop.
Find and format new iscsi disk on vmware esx using esxcli command
#!/bin/sh
esxcli storage core path list | grep "Device:" | grep "naa" | awk '{print $2}' | sort > /tmp/2.txt
esxcli storage vmfs extent list | grep naa | awk '{print $4}' | sort > /tmp/1.txt
new_disk=`grep -v -f /tmp/1.txt /tmp/2.txt`
echo "Adding iSCSI datastore ${new_disk}"
if [[ ! -z $new_disk ]]; then
echo "format and configure datastore"
list=`ls /vmfs/devices/disks/naa* | grep -v ':'`
list2=${list// /$'\n'}
count=1
for disk in $list2; do
let count+=1
done
disk="/vmfs/devices/disks/${new_disk}"
echo ${disk}
disk_name="iscsiDataStore${count}"
if [[ $# == 1 ]]; then
disk_name=$1
fi
echo "new volume is ${disk_name}"
partedUtil setptbl $disk gpt "1 2048 10000 AA31E02A400F11DB9590000C2911D1B8 0" #format so disk is not unknown and then we can properly format
temp=`partedUtil getUsableSectors $disk`
endsector=${temp##* }
partedUtil setptbl $disk gpt "1 2048 $endsector AA31E02A400F11DB9590000C2911D1B8 0"
vmkfstools -C vmfs5 -S ${disk_name} $disk:1
fi
echo "Formatting of iSCSI LUNs complete. iSCSI volumes are:"
ls /vmfs/volumes | grep iscsi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment