VMware PowerCLI Instant Clone Lab
Most of you have probably already heard quite some time ago about VMware project Fargo which has now matured into VMware Instant Fork technology that allows rapid deployment via rapid cloning of an already running virtual machine. ย This is especially a tremendously beneficial technology in the VDI environment especially with Horizon 7. ย With a VMware fling, you can also utilize this instant clone technology in a regular vSphere environment if you are in need of multiple clones of running virtual machines. ย For me a particularly interesting use case is in a lab or testing environment. ย Let’s take a look at a VMware PowerCLI Instant Clone Lab and some of the things that I learned in playing around with this technology.
Check out Duncan Epping’s great explanation of how VMForks work.
VMware PowerCLI Instant Clone Lab
First of all, I want to detail a few of the resources that I used in putting the knowledge and information together for my VMware PowerCLI Instant Clone lab. They are:
- https://blogs.vmware.com/PowerCLI/2015/08/using-vmware-instant-clone-via-powercli-extensions-fling.html
- https://labs.vmware.com/flings/powercli-extensions?download_url=https%3A%2F%2Fdownload3.vmware.com%2Fsoftware%2Fvmw-tools%2Fpowercliext%2FVMware.VimAutomationExtensions.zip#comments
- https://www.thevirtualist.org/vmfork-instant-clone-and-horizon-view-intergration/
These steps are already pretty well documented in the links above as well as in other blog posts, however, I want to detail these a bit more as when I read through some of the documentation, I was unclear on a few of the concepts here. ย Also, I wanted to pass along a few of the errors that I received along the way which will no doubt help you if you see some of the similar errors that I ran into.
Get the right Module
One of the mistakes that I made off the start was that I pulled down the wrong PowerCLI module. ย If you navigate to the PowerCLI fling for Instant Forking, you may not recognize the combo box which also has the option forย VMware.VimAutomation.Extensions_for_PCLI_63R1_and_above.zip which is what you need if like most of you, you are running the latest and greatest version of PowerCLI. ย Be sure to get the right version as I didn’t, the first go around. ย Follow the instructions after you download to get the module installed into the right location.
Here are the steps I used to get a working PowerCLI session up and running. ย First things first, you need to connect to your vCenter enviroment. ย Many of the blogs have you to import the module and then connect, but I have found that it didn’t make any difference.
connect-viserver yourvcenterserver
Now we want to import the module that we downloaded above for the PowerCLI fling:
import-module vmware.vimautomation.extensions
Next, we actually start working the magic of getting the parent VM setup which will be the parent for our instant cloned VMs. ย Here we are simply setting a variable value with the name of the VM that will be the parent.
$parentvm = get-vm yourparentVM
Next, we actually setup the parentVM that we have defined above with the following Posh code:
$parentForkVM = Enable-InstantCloneVM -VM $parentVM -guestUser โadministratorโ -GuestPassword 'P@$$w0rd' -postclonescript C:myscriptspostconfig.bat
- Note the postclonescript path is a path on your workstation that you are running the command on, not the parent VM. ย This was unclear in the documentation I read or at least that I found
Note after you run the script above, you will lose connectivity to your parentVM, so don’t be surprised about this. ย None of the blog posts I read really detailed that. ย Basically your parentVM is quieced though to be the parent for your instant cloned VMs.
Errors received
At this point I want to detail a few errors that I saw to hopefully shed light on these if you get similar errors in your environment. ย Make sure toย encloseย yourย guestpasswordย in single quotes as you can see below what happens if you do not do this, especially if your password contains reserved characters.
Also, I received this error when using theย postclonescript with myย enable-instantclonevm commandlet. ย The weird thing was I only received this on a particular VM so I think it is environmental to that VM. ย The script was indeed copied over to c:windowsTEMP however, it was having issues executing for some reason. ย I simply copied theย postconfig.batย file to the workstation that failed and ran it manually on the instant cloned VM which worked.
Next, we prepare the $ConfigSettings parameter which sets the network settings in the advanced configuration parameters of our resulting instant cloned VM.
$ConfigSettings = @{ โipaddressโ = '192.168.85.36'; โnetmaskโ = โ255.255.255.0โ; โgatewayโ = โ192.168.85.2โ; โdnsโ = โ192.168.85.2โ; }
Finally, we actually create ourย $childForkVM with variables that we have pieced together above:
$childForkVM = New-InstantCloneVM -ParentVM $parentForkVM -Name MyInstantCloneVM -ConfigParams $ConfigSettings
When you run the above command, you will actually see your instant cloned VM appear in your inventory.
Last but not least, you need to start the resulting instant clone VM:
$childForkVM | start-vm
Noteย You will not be able to access the resulting instant cloned VMs by the vSphere client, only theย web client. ย Also, I was not able to access them with the Remote Console. ย I was able to access by simply double clicking the little preview box that launches the console in a web browser tab.
A few things I noted about the Instant Clones
A few things to note:
- Your parent VM is not useable in this process, so you would essentially have to clone two instant clone VMs to regain what you had in the parent, and then have an additional machine to work with
- Youย can have your instant clones attached to different networks. ย I didn’t see anything about this listed or tested by others, so I tested it in my lab. ย I was able to connect one instant clone to one network and attach the other to another network.
- You can’t migrate your instant cloned virtual machines to another host. ย They are bound to the parent VM wherever it is located and on that particular host.
To tear down your instant clone, you can run the following two commands in powercli
stop-vm yourinstantclone remove-instantclonevm yourinstantclone
The above commands will power off and remove the instant clone.
To bring yourย parentVM back to a useable state, simplyย power off the parent VM as there is no option toย shutdown. ย Keep in mind the parentVM is in a quieced state, so it should be safe to simply power off. ย Once you boot it back up, it returns toย normal VM operational state.
Thoughts
Instant clones are way cool and definitely have some really neat use cases. ย Hopefully thisย VMware PowerCLI Instant Clone Lab will help any who are interested in giving this new technology a test drive or even use it in certain lab situations.