VMware Cloud Community
amircsco
Enthusiast
Enthusiast
Jump to solution

Clone a VM directly from single ESXi Host

Hi,i want to clone a VM with all of the related feathers including associated IDs (CPU ID, UUID, BIOS ID, etc) and redeploy it on another single ESXi host. could any me help me how can do that??

Tags (2)
1 Solution

Accepted Solutions
vNEX
Expert
Expert
Jump to solution

Hello,

without vCenter server you can accomplish this also by PowerCLI script check this useful post below:

HL Tools - Part 1 - Clone a VM without vCenter - LucD notes

If you want to clone just individual disks check this KB:

VMware KB: Cloning individual virtual machine disks via the ESX/ESXi host terminal

_________________________________________________________________________________________

If you found this or any other answer helpful, please consider to award points. (use Helpful or Correct buttons)

Regards,

P.

_________________________________________________________________________________________ If you found this or any other answer helpful, please consider to award points. (use Correct or Helpful buttons) Regards, P.

View solution in original post

7 Replies
MagnetBoy
Enthusiast
Enthusiast
Jump to solution

what do you use to manage(connect to) the hosts?

Are you using vCenter Server to manage your ESXi host or are you using vCenter Client to connect directly to the hosts?

VMware Certified Professional – Datacenter Virtualization (vSphere 5)
vThinkBeyondVM
VMware Employee
VMware Employee
Jump to solution

Cloning a VM can be done only from vCenter server. Either Windows or vCenter server appliance

You need to install vCenter>>Connect to vCenter through web client or Desktop client>> add you hosts there>> right click VM >>click clone>> complete the clone wizard.

Let us know if you have any other questions.


----------------------------------------------------------------
Thanks & Regards
Vikas, VCP70, MCTS on AD, SCJP6.0, VCF, vSphere with Tanzu specialist.
https://vThinkBeyondVM.com/about
-----------------------------------------------------------------
Disclaimer: Any views or opinions expressed here are strictly my own. I am solely responsible for all content published here. Content published here is not read, reviewed or approved in advance by VMware and does not necessarily represent or reflect the views or opinions of VMware.

vNEX
Expert
Expert
Jump to solution

Hello,

without vCenter server you can accomplish this also by PowerCLI script check this useful post below:

HL Tools - Part 1 - Clone a VM without vCenter - LucD notes

If you want to clone just individual disks check this KB:

VMware KB: Cloning individual virtual machine disks via the ESX/ESXi host terminal

_________________________________________________________________________________________

If you found this or any other answer helpful, please consider to award points. (use Helpful or Correct buttons)

Regards,

P.

_________________________________________________________________________________________ If you found this or any other answer helpful, please consider to award points. (use Correct or Helpful buttons) Regards, P.
amircsco
Enthusiast
Enthusiast
Jump to solution

thank you MagnetBoy,i'm using vSphere client not vCenter server.

do i have to install vCenter Server for doing that??

is there any way for cloning a VM? via vShpere client, via vMA/vCLI or even via python/perl/java script!

Reply
0 Kudos
vThinkBeyondVM
VMware Employee
VMware Employee
Jump to solution

Let me clarify your doubts:

The vSphere Client is the principal interface for administering vCenter Server and ESXi.

The vSphere Client user interface is configured based on the server to which it is connected:

When the server is a vCenter Server system, the vSphere Client displays all the options available to the vSphere environment, according to the licensing configuration and the user permissions.

When the server is an ESXi host, the vSphere Client displays only the options appropriate to single host management.

Hence you can use vSphere client to connect to ESXi host as well as vCenter server. In you case, you are using vSphere client to connect to individual ESXi host.

Yes, if you want to clone Virtual machine, easiest way is to install vCenter server & connect to vCenter server using vSphere client or web client (its new user interface). However, you need to have valid vCenter license.  Note that vCenter will give you lot of features to manage your virtual environment. Ex. Features such DRS, DPM , SDRS, SIOC, HA, cloning, snapshots, templates etc.  can only be enabled from vCenter. If you have vCenter server you can manage multiple ESXi host (Either through vSphere client or web client)

Other ways (PowerCLI as well as ESXi CLI) are specified by vNEX. 


----------------------------------------------------------------
Thanks & Regards
Vikas, VCP70, MCTS on AD, SCJP6.0, VCF, vSphere with Tanzu specialist.
https://vThinkBeyondVM.com/about
-----------------------------------------------------------------
Disclaimer: Any views or opinions expressed here are strictly my own. I am solely responsible for all content published here. Content published here is not read, reviewed or approved in advance by VMware and does not necessarily represent or reflect the views or opinions of VMware.

Reply
0 Kudos
amircsco
Enthusiast
Enthusiast
Jump to solution

thank you guys i found that for Cloning a virtual machine on ESXi host there are two solution:

- Using vCenter

- Using Veeam

Regards,

Reply
0 Kudos
MarelFoodProces
Contributor
Contributor
Jump to solution

Although this post was answered, I think this reply will be usefull for anyone searching to clone a VM on a ESXi box, without having vCenter and not wanting to shutdown the source vm

I wrote a script running on the box itself. This is still in a testing phase, but here it goes:

#!/bin/sh

######################################################################################

# Create a clone of a running machine on ESXi, without vCenter services available

# Disable networkcards on connecting at startup

# Start the cloned VM

#

# Created by : Jeroen van Schelt

# Creation date : jan 2015

# Tested on : ESXi 5.5 build 1746018

#

#

# To run this script on a regular basis, without user intervention, do the following :

#

# Copy the script to a datastore

# Add the cron job to the root crontab:

# Edit /var/spool/cron/crontabs/root

# Add the line (all on one line)

# 30  1    *   *   *   /vmfs/volumes/BOXSR0089_das1/scripts/hotcloneBOXPC8888vm.sh > /vmfs/volumes/BOXSR0089_das1/scripts/hotcloneBOXPC8888vm.log 2>&1

# Run the command "kill $(cat /var/run/crond.pid)", This will kill the process crond.

#

# Edit /etc/rc.local.d/local.sh, using a command such as "vi /etc/rc.local.d/local.sh".

# At the end of the file, add 3 lines (using "G" then "O" in vi). The first kills crond, the second adds the new cron job to the root crontab file, ad the third restarts crond:

# /bin/kill $(cat /var/run/crond.pid)

# /bin/echo "30  1    *   *   *   /vmfs/volumes/BOXSR0089_das1/scripts/hotcloneBOXPC8888vm.sh > /vmfs/volumes/BOXSR0089_das1/scripts/hotcloneBOXPC8888vm.log 2>&1" >> /var/spool/cron/crontabs/root

# /usr/lib/vmware/busybox/bin/busybox crond

# Save and exit the editor (Press the "Esc" key then ":wq" then press "Return" in vi)

# Run the command "auto-backup.sh" so that the change to /etc/rc.local survives a reboot.

# Run the command "/usr/lib/vmware/busybox/bin/busybox crond"

######################################################################################

# user variables

SourceVM="NameOfSVM"

SourceDS="/vmfs/volumes/NameOfDS"

DestDS="/vmfs/volumes/NameOfDS"

ScriptDIR="$SourceDS/scripts"

######################################################################################

# Do NOT modify anything beyond this point, unless you know what you are doing

######################################################################################

# script variables

DestVM="HotClone_$SourceVM"

ScriptRunTime=$(date "+%Y%m%d_%H%M")

nicfile=$ScriptDIR/nic_$DestVM.txt

diskfile=$ScriptDIR/disk_$DestVM.txt

# create destination directory

mkdir $DestDS/$DestVM

# copy source vmx? files to destination

cp $SourceDS/$SourceVM/$SourceVM.vmx $DestDS/$DestVM/$DestVM.vmx

sed -i "s/$SourceVM/$DestVM/g" $DestDS/$DestVM/$DestVM.vmx

cp $SourceDS/$SourceVM/$SourceVM.vmxf $DestDS/$DestVM/$DestVM.vmxf

sed -i "s/$SourceVM/$DestVM/g" $DestDS/$DestVM/$DestVM.vmxf

# create snapshot from source

lineCount=`expr $(vim-cmd vmsvc/getallvms | wc -l) - 1`

x=0

while [[ $x -ne $lineCount ]]; do

  x=`expr $x + 1`

  VMID=$(vim-cmd vmsvc/getallvms | tail -$lineCount | awk '{ print $1 }' | sed -n -e "$x"p)

  VMNAME=$(vim-cmd vmsvc/getallvms | tail -$lineCount | awk '{ print $2 }' | sed -n -e "$x"p)

  if [[ $SourceVM == $VMNAME ]]; then

  SourceVMID=$VMID

  vim-cmd vmsvc/snapshot.create $SourceVMID HotClone_$ScriptRunTime HotClone_of_$SourceVM 0 0

  fi

done

# Search for Disks

rm $diskfile > /dev/null 2>&1

while read line ; do

  grep ".vmdk" | awk '{ print $3}' | sed "s/\"//g" >> $diskfile

done < $DestDS/$DestVM/$DestVM.vmx

# copy sourcedisk to destinationdisk (thin provisioned)

while read line ; do

  vmkfstools -d thin -i $SourceDS/$SourceVM/$(echo $line | sed "s/$DestVM/$SourceVM/g") $DestDS/$DestVM/$(echo $line | sed 's/-[0-9]*//g')

done < $diskfile

# If Source already had a snapshot, remove snapdata on vmdk filename in vmx-file

sed -i "s/\(.*\)\-.*\(.vmdk\)/\1\2/g" $DestDS/$DestVM/$DestVM.vmx

# Search for nics

rm $nicfile > /dev/null 2>&1

while read line ; do

  grep ethernet[0-9].virtualDev | awk '{ print $1}' | sed "s/.virtualDev//g" >> $nicfile

done < $DestDS/$DestVM/$DestVM.vmx

# set nic disconnected at boot

while read line ; do

  if [[ -n "$(grep $line.startConnected $DestDS/$DestVM/$DestVM.vmx)" ]]; then

  echo "found in $line"

  sed -i "s/$line.startConnected = \"TRUE\"/$line.startConnected = \"FALSE\"/g" $DestDS/$DestVM/$DestVM.vmx

  else

  echo "nothing on $line"

  echo $line.startConnected = \"FALSE\" >> $DestDS/$DestVM/$DestVM.vmx

  fi

done < $nicfile

# register destination VM in inventory

DestVMID=`vim-cmd solo/registervm $DestDS/$DestVM/$DestVM.vmx`

# Powering up destination virtual machine

vim-cmd vmsvc/power.on $DestVMID &

sleep 15

vim-cmd vmsvc/message $DestVMID _vmx1 2

# Remove HotClone Snapshot from source

SnapToRemove=`vim-cmd vmsvc/snapshot.get $SourceVMID | grep -A 1 HotClone_$ScriptRunTime | grep -e "Id" | awk '{print $4 }'`

vim-cmd vmsvc/snapshot.remove $SourceVMID $SnapToRemove 0

# EOF