I’ve been asked recently by forumer in VMware Communities, “How can we create a Virtual Machine(VM) from ESX Service Console(SC) or Can’t we?“. When I looked back since the first day I’ve started working with ESX, not a single time I’ve created new VM through SC. I’ve agreed, we can do a lot of things via CLi such as :
- vmware-cmd –> Manage VM, start, stop, snapshot, register/unregister, connect devices & etc
- vmkfstools –> Create, clone, resize, convert VM virtual disk & etc
But that’s all! What about completely build new VM from SC like the one we did from vi-client?. Unless I missed out something, the answer is “NO” and seem imposible to me. Nevertheless, I’m writing this to show you how can we create the new VM using script that I build from scratch.
So, what’s make this script?. I’ve started by assembling few useful commands as below :
- $echo –> will create all VM parameter to .vmx
- $mkdir –> will be used to create VM folder to Datastore
- $vmkfstools -> will be used to create VM disk
- $vmware-cmd –> will be used to register VM
Once I knew which commands need to be used and called first, I finally managed to produce below script “vmcreate.sh” within few minutes.
So, how the above script works?. At first, the script will require user input akin to what we have in vi-client. Second, it will print out all user inputs as a summary and wait for customer confirmation before proceed to the next step. Once confirmed, the script will start creating VM folder in the datastore based on given user input during the first step. Next, it will proceed to create virtual disk inside the VM folder. Then, VM configuration file (.vmx) will be created in the same folder before the script register the VM to the local ESX host as shown below.
Finally, I verified VM setting and it’s look everything was configured as expected.
Yes, it’s possible for us to create new VM from SC using any script. Of-course, we actually no need to rely on real time user input instead we can build and run the script with all VM parameters included just in one line. Unfortunately as I’ve mentioned before, I’m not very good in scripting and I knew someone out there can build better script than mine.
athlon_crazy 17/06/2010 21:20PM
6 Comments so far
Leave a comment