Cloning VMs in ESXi only
JDMurray
Admin Posts: 13,092 Admin
Is anyone able to clone VMs using ESX or ESXi only and without any assistance from VC?
I'm calling the VI API to clone a VM on ESXi 3.5.0 U4, but the operation is throwing a NotSupportedFault error. There seems to be some disagreement in the VMWare community if it is or is not possible to clone a VM using only ESX(i) and the VI API. I'm wondering if anybody here knows of a manual or programmatic way to clone VMs without using VC to control ESX(i).
I'm calling the VI API to clone a VM on ESXi 3.5.0 U4, but the operation is throwing a NotSupportedFault error. There seems to be some disagreement in the VMWare community if it is or is not possible to clone a VM using only ESX(i) and the VI API. I'm wondering if anybody here knows of a manual or programmatic way to clone VMs without using VC to control ESX(i).
Comments
-
astorrs Member Posts: 3,139 ■■■■■■□□□□Is anyone able to clone VMs using ESX or ESXi only and without any assistance from VC?
I'm calling the VI API to clone a VM on ESXi 3.5.0 U4, but the operation is throwing a NotSupportedFault error. There seems to be some disagreement in the VMWare community if it is or is not possible to clone a VM using only ESX(i) and the VI API. I'm wondering if anybody here knows of a manual or programmatic way to clone VMs without using VC to control ESX(i). -
JDMurray Admin Posts: 13,092 AdminOr am I way off base and you're still running in 60 day eval mode?
There are a lot of blog articles on how to clone VMs by manually copying and modifying the VM's files using VI Client, SSH, or the "unsupported" console. I need to find an automated way to do it through software only and build it myself. -
cnfuzzd Member Posts: 208I am still running in 60-day eval mode with U3 and U4 on different machines.
There are a lot of blog articles on how to clone VMs by manually copying and modifying the VM's files using VI Client, SSH, or the "unsupported" console. I need to find an automated way to do it through software only and build it myself.
I am not that knowledgeable about this, but does it fail on the U3 machines? I know that ESXi U3 had the bug that granted access to the cli or somesuch, but was fixed in U4. I doubt thats it, but a possibility. If you resolve this, I would be interested in knowing how.
Thanks!
John__________________________________________
Work In Progress: BSCI, Sharepoint -
JDMurray Admin Posts: 13,092 AdminESX and ESXi do not support the cloning of VMs, only Virtual Center does, and this is by design. You can manually clone VMs using VI Client by creating folders in a datastore, copying .vmdk files to those folders, changing the name of the VM in the .vmx and .vmxf files, and associating the .vmdk files with new VMs. I'm just wondering if anyone has developed an automated way (outside of VC) to do this with ESXi.
-
HeroPsycho Inactive Imported Users Posts: 1,940Why not use Converter?
Edit: If that won't work for you, you could surely put a script together using the VI Toolkit for Windows plus the Community Extensions, which has useful cmdlets for this such as Copy-TkeDatastoreFile.
http://vitoolkitextensions.codeplex.com/SourceControl/ListDownloadableCommits.aspx
Edit redux: http://powershell.com/cs/media/p/1655.aspxGood luck to all! -
JDMurray Admin Posts: 13,092 AdminI finally came up with a solution for this cloning problem on ESXi.
Cloning requires making a copy of a parent VM's files into a separate folder in a datastore, changing the name of the VM in the .vmx file, removing a few lines from the .vmx file causing a new UUID and MAC address to be auto-generated when the clone is first started, and registering the cloned VM in the ESXi inventory. You also need to make sure that the parent VM is not running or paused during the cloning operation.
For the copy and .vmx file modifications, I wrote a shell script that runs on the ESXi server itself and is run (by a remote client program I also wrote) via an SSH connection. Stopping the parent VM and registering the clone is performed using the VI API called from the same client program.
ESXi runs the very minimal BusyBox Linux, which uses ash for a shell. The scripting language implemented in ash is rather lacking in features one would expect to find in other shells, like bash and ksh. Even performing simple string substitutions is not supported, leaving external programs (like sed) to be used as a workaround. And BusyBox doesn't come with Perl, Python, Java or other shells preinstalled, so you're stuck with ash.
My ESXi VM cloinging solution isn't very elegant, but it works. -
tiersten Member Posts: 4,505ESXi runs the very minimal BusyBox Linux, which uses ash for a shell.And BusyBox doesn't come with Perl, Python, Java or other shells preinstalled, so you're stuck with ash.
If you want to just remove a line then you could do it with grep as well. "grep -v" will show you everything except what the pattern matches. The BusyBox implementation of grep supports this option. -
JDMurray Admin Posts: 13,092 AdminYes, BusyBox is everything except the Linux kernel itself. And I never considered using grep, as sed works wonders for me.
They only thing I couldn't figure out how to do in ash was construct a command to rename files as I copied them. I wanted to loop through files in a directory and create the command cp oldfilename.oldextension newfilename.oldextension for each file to copy, but the args were always reversed no matter what I did. Something odd about variable assignment in a loop that's screwy. I didn't have the patience to figure it out; it turned out that the clone's files didn't need to have their names changed anyway. -
tiersten Member Posts: 4,505Yes, BusyBox is everything except the Linux kernel itself.I wanted to loop through files in a directory and create the command cp oldfilename.oldextension newfilename.oldextension for each file to copy, but the args were always reversed no matter what I did. Something odd about variable assignment in a loop that's screwy.
-
JDMurray Admin Posts: 13,092 AdminI had a look through the BusyBox sources and the ash.c file. It appears that some standard shell features simply aren't implemented in ash--for whatever reasons. But with so much pre-existing shell source code to look at, why wouldn't the author(s) implement simple substitution (e.g., s/oldstring/newstring/)? I don't know if ash is currently supported or not.
-
Jordus Banned Posts: 336Good greif. You'd think you could just sysprep the VM and copy the vmkd file.
Guess not. -
JDMurray Admin Posts: 13,092 AdminSysprep is only used for a VM with a Windows guest OS. The cloning operation itself is independent of any guest OS installed (or not) in the VM to be cloned. VC is wonderful for automatically handling things like sysprepping during cloning, but a stand-alone ESXi server won't do any of that for you.
-
Jordus Banned Posts: 336Sysprep is only used for a VM with a Windows guest OS. .
Well duh.The cloning operation itself is independent of any guest OS installed (or not) in the VM to be cloned. VC is wonderful for automatically handling things like sysprepping during cloning, but a stand-alone ESXi server won't do any of that for you.
Also duh.
My point was, that you seem to have to go to pretty lengthy measures (creating scripts, etc) to simply clone a VM for ESX when for Virtual PC, Virtual Server 2005, and Hyper-V you just copy the VHD and prep the guest OS accordingly.
SCVMM allows for ease of tasks for sysprep and cloning (via templates, etc) but even without enterprise level tools its easy enough. -
dynamik Banned Posts: 12,312 ■■■■■■■■■□JD's a developer dude. He's trying to write an automated method of cloning the VMs himself. He's not just stuck trying to clone a VM.
-
tiersten Member Posts: 4,505My point was, that you seem to have to go to pretty lengthy measures (creating scripts, etc) to simply clone a VM for ESX when for Virtual PC, Virtual Server 2005, and Hyper-V you just copy the VHD and prep the guest OS accordingly.
1. Copy entire VM to new directory
2. Change IDs and name
3. Register new VM in the inventory
I don't see that as being particularly lengthy. -
JDMurray Admin Posts: 13,092 AdminI'm basically trying to write my own automation app that's a functional subset of VMWare's Virtual Center and Lab Manger.
Somebody gots to write all the kewl warez for you IT chumps to use. -
tiersten Member Posts: 4,505I'm basically trying to write my own automation app that's a functional subset of VMWare's Virtual Center and Lab Manger.
Somebody gots to write all the kewl warez for you IT chumps to use. -
JDMurray Admin Posts: 13,092 AdminVirtualMurrayCenter?
-
JockVSJock Member Posts: 1,118***BUMP***
Yes, I knew there was going to be a thread on this as I have spent the last few days getting all of the updates/patches for the three xp clients and Win 2003 servers in my VMWare environment.
I was thinking, 'there has to be a better way for this.'
Goggling around didn't find anything free Virtual Centers for Linux either.***Freedom of Speech, Just Watch What You Say*** Example, Beware of CompTIA Certs (Deleted From Google Cached)
"Its easier to deceive the masses then to convince the masses that they have been deceived."
-unknown -
tiersten Member Posts: 4,505JockVSJock wrote: »Yes, I knew there was going to be a thread on this as I have spent the last few days getting all of the updates/patches for the three xp clients and Win 2003 servers in my VMWare environment.
-
JockVSJock Member Posts: 1,118Just VWMare Server for Linux, under Ubuntu 8.04.Are you using ESX? Your other thread seemed to imply that you were using VMware Server...***Freedom of Speech, Just Watch What You Say*** Example, Beware of CompTIA Certs (Deleted From Google Cached)
"Its easier to deceive the masses then to convince the masses that they have been deceived."
-unknown -
marc.techguy Member Posts: 1 ■□□□□□□□□□I finally came up with a solution for this cloning problem on ESXi.
Cloning requires making a copy of a parent VM's files into a separate folder in a datastore, changing the name of the VM in the .vmx file, removing a few lines from the .vmx file causing a new UUID and MAC address to be auto-generated when the clone is first started, and registering the cloned VM in the ESXi inventory. You also need to make sure that the parent VM is not running or paused during the cloning operation.
For the copy and .vmx file modifications, I wrote a shell script that runs on the ESXi server itself and is run (by a remote client program I also wrote) via an SSH connection. Stopping the parent VM and registering the clone is performed using the VI API called from the same client program.
ESXi runs the very minimal BusyBox Linux, which uses ash for a shell. The scripting language implemented in ash is rather lacking in features one would expect to find in other shells, like bash and ksh. Even performing simple string substitutions is not supported, leaving external programs (like sed) to be used as a workaround. And BusyBox doesn't come with Perl, Python, Java or other shells preinstalled, so you're stuck with ash.
My ESXi VM cloinging solution isn't very elegant, but it works.
Do you think you could share your code with everyone? Or send me a copy? -
JDMurray Admin Posts: 13,092 AdminI can't share the actual script I wrote, but I explained what it does, and it's only about a page-and-a-half of script. The tricky part is learning the VI API.