VMware Cloud Community
BlueMike
Contributor
Contributor

Create a VM from a template that has two harddisks, going to two different datastores

In order to improve IOPS, our team decided to separate our Windows 7 VDIs to two datastores.  Going on the NetApp, we would put the base OS, where a nightly deduplicate on the Netapp would consolidate the VMs.  However, in order to reduce IO to the NetApp, we created a new hard disk (D:) where we store the temp directory and place the system swap file.  We created this second hard disk on our SAN.

Disk1 - NetApp Datastore

Disk2 - SAN Datastore

Our previous build scripts for new VDI's would pick a datastore based on free space and assign it to the appropriate datastore, however now I need to apply a second hard disk to a different datastore.

I use the following command to build a new VM from our template:

New-VM -Name $VMName -Template $template -OSCustomizationSpec $CustSpec -VMHost $vmhost -Datastore $VMDatastoreName -Location $buildfolder -RunAsync

When I run this command, however, both hard drives end up on the same datastore.

I can, through the vSphere Client (vSphere 4.1), select the datastores for each hard disk individually by clicking the advanced button while prompted to pick the datastore, but cannot find a PowerCLI equivalent.

I have discovered a way to use Set-Harddisk to move the hard disk to the appropriate datastore after the fact, but I don't have a way to run this command with -RunAsync like I do with the New-VM option, causing my script to wait for the entire cloning process to complete before applying the hard disk move.  Additionally, this will create extra IO to our NetApp for the migrate, where if I use the GUI option I would only hit the datastores once each.

Because I have some VMware View entitlement also applying through this same automated process, manually building a VDI is impractical.  Since our organization is now 100% for all employees (over 1000), this is a common task that must be automated as best as possible.

Does anyone have an idea on how to effectively deploy a VM from a template with two hard disks that must reside on two separate datastores?

Reply
0 Kudos
2 Replies
LucD
Leadership
Leadership

Why don't you use the New-VM cmdlet with a Template that just contains the C-partition.

Once the VM is created, you can use the New-Harddisk cmdlet to add a 2nd disk.

And yes, the Datastore parameter on the New-VM cmdlet is rather limited in its options. Everything will go to that specific datastore.

If you want to have the same possibilities as with the vSphere client, you would have to use the CreateVM_Task method for now, I'm afraid


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
BlueMike
Contributor
Contributor

Thank you for the quick response.  This will require a bit of tweaking to the way to perform the post-configuration, but it should work.  Thank you for the insight.

Reply
0 Kudos