Script – Grow VMFS datastores in command line

Ce message est également disponible en : French

Recently, i have worked on a script to automate these operations because it involved a lot of datastores. The script only works if the LUN hosting the datastore has previously been expanded.

For more information regarding the command line describe in this article you can check this  2002461.

Update :02/06/2015 – Add Powershell + plink

In my powershell script i used a script from @Alan Renouf that will generate a choice box (Cluster,ESX,Datastore)

So in this script, you will be able to choice in which cluster and esx the script will be launched.

The script has been tested in ESXi 5.0 U2 but should work with 5.x.

Unzip the file and run the script DatastoreExtend.ps1

– 1 : Enter the vCenter Name


– 2 : Provide the vCenter credentials


– 3 : Then provide the root password of your ESXi.Extend-3– 4 : Select your cluster


– 5 : Select your host


– 6 : Select your dastatore. The script files will be uploaded on it.




Once the script is done, you can choose to restart it on another cluster.





This is the content” script that will generate a list of datastores. The script will check only vmfs datastore.


# Julien VARELA Script 
# Release v1.0 02/03/2015
#Grow VMFS Datastore

#Export Datastore List
esxcli storage filesystem list > /tmp/vmfs.txt
cat /tmp/vmfs.txt | grep “VMFS” | awk ‘{print $2}’ > /tmp/datastorelist.txt # C

while read i; do /tmp/ $i;done <  /tmp/datastorelist.txt

#Remove temporary files
rm -rf /tmp/vmfs.txt
rm -rf /tmp/datastorelist.txt


Content of script.

# Julien VARELA Script
# Release v1.0 02/03/2015
#Grow VMFS Datastores

# Retrieve naa.
parted=$(vmkfstools -P /vmfs/volumes/$1 | grep “naa.” | sed ‘s/..$//’)
naa=$(echo $parted  | sed ‘s/ //g’)

#Retrieve last sector available
endsecavailable=$(partedUtil getUsableSectors /vmfs/devices/disks/$naa | awk ‘{print $2}’)

#Retrieve current last sector
endsecactive=$(partedUtil get /vmfs/devices/disks/$naa | sed ‘1d’ |awk ‘{print $3}’)

#Retrieve partition number
numpartition=$(partedUtil get /vmfs/devices/disks/$naa | sed ‘1d’ |awk ‘{print $1}’)

#Retrieve first sector
firstsector=$(partedUtil get /vmfs/devices/disks/$naa | sed ‘1d’ |awk ‘{print $2}’)
echo “Nom du datastore a traiter : ” $1
echo “Identifiant du lun : ” $naa
echo “Premier secteur : ” $firstsector
echo “Dernier secteur en place : ” $endsecactive
echo “Dernier secteur disponible : “$endsecavailable #| awk ‘{print $2}’
echo “Numero de la partion : ” $numpartition

if [ $endsecactive = $endsecavailable ]
        echo “Le datastore est deja etendu”
echo “VMFS Resize”
partedUtil resize /vmfs/devices/disks/$naa $numpartition $firstsector $endsecavailable

echo “Rescan”
vmkfstools -V
echo “growfs”
vmkfstools –growfs /vmfs/devices/disks/$naa:$numpartition /vmfs/devices/disks/$naa:$numpartition
echo “Rescan”
vmkfstools -V
echo “Grow VMFS Datastore ended on : ” $1


Will not be processed, datastore that were already expanded



You can download the zip file here : ExtendDatastore

Unzip the file and run the script DatastoreExtend.ps1 😉 have fun


The script will be translate in few days.

Follow me

Julien Varela

Sr. Systems Engineer et blogger @vThink. Je suis passionné par les nouvelles technologies. Et tout particulièrement, celles concernant la virtualisation. j'ai su apporter par mon autonomie, ma curiosité, ma pugnacité et ma technicité mon expertise dans ce domaine.
Follow me

Leave a Reply