Both tasks are quite related.
Basically a VM is assembled by a vmx-file + plus one or more vmdks. That is the part that you control - during initial setup and changes you make later on. ESXi adds some more files to that for its own use: vmsd, vmxf, vswap, nvram and so on.
If you split up the ingredients of a VM into 3 sections:
VM-identity
Virtual hardware
ESXi-autogenerated
and then look into the details inside the VM-identity section - have a look at the next table
| files | vmx-parameters | |
VM-identity | associated vmdks rdms floppies isos | displayName = "hugo" ethernet0.generatedAddress = "00:0c:29:c2:99:05" ethernet1.generatedAddress = "00:0c:29:c4:99:07" numvcpus = "2" cpuid.coresPerSocket = "2" memSize = "4680" scsi0:0.fileName = "hugo.vmdk" scsi0:1.fileName = "hugo-user-data.vmdk" ide1:0.fileName = "win-install.iso" | You want to change this details for all new VMs: |
Virtual hardware | nvram | pciBridge0.pciSlotNumber = "17" pciBridge0.present = "TRUE" pciBridge4.functions = "8" pciBridge4.pciSlotNumber = "21" pciBridge4.present = "TRUE" pciBridge4.virtualDev = "pcieRootPort" pciBridge5.functions = "8" pciBridge5.pciSlotNumber = "22" pciBridge5.present = "TRUE" pciBridge5.virtualDev = "pcieRootPort" pciBridge6.functions = "8" pciBridge6.pciSlotNumber = "23" pciBridge6.present = "TRUE" pciBridge6.virtualDev = "pcieRootPort" pciBridge7.functions = "8" pciBridge7.pciSlotNumber = "24" pciBridge7.present = "TRUE" pciBridge7.virtualDev = "pcieRootPort"
.... | you reuse this configuration from a good template the related vmx-parameters can be copied in block |
ESXi autogenerated | vmsd, vmsn, vmss, vswap | uuid.bios = "56 4d 1c 5a ff 86 6b f8-c8 e9 10 02 49 c2 99 05" uuid.location = "56 4d 1c 5a ff 86 6b f8-c8 e9 10 02 49 c2 99 05" | this is done by ESXi automatically |
vCenter | ... | ... | ... |
Now consider that you want to modify the green part anyway - you need new mac adresses and new full paths and directories.
Then it no longer is a big difference between creating a new VM and cloneing an existing one.
For the identity details you probably need 5 - 15 vmx-parameters.
For the vmdks you can easily switch between creating a new one or run vmkfstools -i source-target.vmdk target.vmdk.
Now lets clone a VM - master "hugo" will be cloned to "isildur"
sh.cript:
mkdir "isildur"
cat hugo/hugo.vmx | grep -v "hugo" | grep -v "Address" > isildur/isildur.vmx
echo >> isildur/isildur.vmx displayName = "isildur"
echo >> isildur/isildur.vmx ethernet0.generatedAddress = "00:0c:29:c2:11:05"
echo >> isildur/isildur.vmx ethernet1.generatedAddress = "00:0c:29:c4:11:07"
echo >> isildur/isildur.vmx scsi0:0.fileName = "isildur-os.vmdk"
echo >> isildur/isildur.vmx scsi0:1.fileName = "isildur-personal-data.vmdk"
vmkfstools -i hugo/hugo.vmdk isildur/isildur-os.vmdk -d thin
and another command creates a new disk for the personal data of isildur.
one more command to register the vmx and your new clone is ready to use.
If you want linked clones with a protective snapshot for the original "hugo" you need a few more lines - but if you have done this a few times
you realize that all you need is a few vmxlines + one or more vmkfstools commands.
Ulli