I am working on my PowerShell module for Pure/VMware operations and one of the cmdlets I am writing is for growing a VMFS. When perusing the internet, I could not find a lot of direct information on how to actually do this. There is not a default cmdlet for doing this.
The illustrious Luc Dekens talks about this problem here and even provides a great module for doing this:
If you just need want to run a quick script you can use that. If you want to write it yourself here is a quick overview of what you need to do. I am talking about a specific use case of:
- I have a datastore on one extent and that extent exists on a LUN (or device or volume or whatever you want to call it) on an array. That LUN has been grown on the array.
- I want to grow the VMFS to use the new capacity and not create a new extent, just grow it.
This is generally the most common use case and is what I recommend customers to do. Luc’s script covers a lot more use cases so there is a lot more code in there that you won’t need for this situation. So let me boil down the PowerCLI to the basics.
I have a datastore called CodyVMFS and it is 4 TB in size:
The underlying device is 4 TB too:
Now I resize the volume on the array itself, you can of course use PowerShell to do this, but I will use the GUI for clarity:
After a rescan, by looking in VMware you can see the underlying device is now 8 TB:
So now we have a 4 TB VMFS that sits on a 8 TB volume. So let’s use PowerCLI to expand the datastore to use the full 8 TB.
After connecting to vCenter, use get-datastore to get the datastore object.
$datastore = get-datastore CodyVMFS
Then you need to access the host datastore system. Since there is not direct cmdlet for this, we need to access the extension data of the host to run the methods directly. So, I grab a host object that has access to that datastore:
$esxi = Get-View -Id ($Datastore.ExtensionData.Host |Select-Object -last 1 | Select -ExpandProperty Key)
Then I need to grab the datastore system from that host:
$datastoreSystem = Get-View -Id $esxi.ConfigManager.DatastoreSystem
The next step is to query the datastore for the specification that is needed to expand it to the new space. There is a simply method you can run to have ESXi build this for you automatically. Run it from $datastoreSystem and pass in the MoRef of the datastore like so:
$expandOptions = $datastoreSystem.QueryVmfsDatastoreExpandOptions($datastore.ExtensionData.MoRef)
Now pass the “spec” parameter and the datastore MoRef to another method to expand it:
$datastoreSystem.ExpandVmfsDatastore($datastore.ExtensionData.MoRef,$expandOptions.spec)
This will expand the VMFS!
Pretty simple.
The whole script process is below:
$datastore = get-datastore CodyVMFS $esxi = Get-View -Id ($Datastore.ExtensionData.Host |Select-Object -last 1 | Select -ExpandProperty Key) $datastoreSystem = Get-View -Id $esxi.ConfigManager.DatastoreSystem $expandOptions = $datastoreSystem.QueryVmfsDatastoreExpandOptions($datastore.ExtensionData.MoRef) $datastoreSystem.ExpandVmfsDatastore($datastore.ExtensionData.MoRef,$expandOptions.spec)
The last line returns the expanded datastore object:
Does this typically require a rescan of the HBA/VMFS?
Yeah usually. Some arrays issue unit attentions back to the host so a rescan is not necessary. So the real answer is it depends
Just used this on some datastores that I originally created with undersized extents (due to a temporary lack of space on the underlying storage). When I expanded the LUNs (2x16Tib,+2x14TiB -> 4 x 16TiB) neither the vCenter GUI not the ESXi WebUI would expand the extents (despite previous success with this).
This worked fine on one with just a single undersized extent, but with multiple LUNs to process, I modified the last line to:
foreach ($spec in $expandOptions.spec) {$datastoreSystem.ExpandVmfsDatastore($datastore.ExtensionData.MoRef,$spec)}
Which did the trick. Other option would be to run it as 3 commands and refer to the spec as $expandOptions.spec[0] etc
Pure genius.