Created
February 4, 2015 22:43
-
-
Save huskercane/a35ad8ba402ca991561a to your computer and use it in GitHub Desktop.
Find and format new iscsi disk on vmware esx using esxcli command
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/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