How to clone a virtual machine in ESXi 6

VMWare vSphere Logo

Background

Here I will go through the steps to clone a virtual machine in ESXi 6. This is especially useful to create a base operating system with minimal requirements and environment personal customisation and then save the virtual disk for future use. Whenever you need a new system you can use this pre-configured system and not starting from scratch.

I usually install git, vim, mysql, etc. and set-up my user accounts, groups, firewall and ip address preferences as well as personalised environment configuration for bash and vim etc. and leave it somewhere safe and re-use it for next server installation.

If you lucky enough to have a paid version of VMware, cloning and back up is as easy as a right-click and select the copy button. But not so easy when using vSphere to connect to ESXi 6.0, the free version of the VMware.

Fortunately there are few options and workarounds that you can take. Most of them involve installing some sort of extra software on your client machine. I usually try to avoid adding another software to my already heavy machine if at all possible. So we go with the option that doesn’t need any extra tool. All you need to have is a ssh connection to the ESXi host machine.

I use putty (or MTPuTTY to be more specific) from my windows machine. login to the ESXi host on a ssh connection and follow steps below.

Here we want to clone merrikh virtual machine to new one named nahid. You need to have root access to the system to go through these steps.

Copy virtual drive (if no snapshots taken)

cd /vmfs/volumes/m2sata
mkdir nahid
vmkfstools -i /vmfs/volumes/m2sata/merrikh/merrikh.vmdk /vmfs/volumes/m2sata/nahid/nahid.vmdk -d thin

You should see a brief progress status and a successful copy should end with this message.

Destination disk format: VMFS thin-provisioned
Cloning disk '/vmfs/volumes/m2sata/merrikh/merrikh.vmdk'...
Clone: 100% done.

Switches used:

  • -i switch is for clone. You need this.
  • -d switch tells the disk format. If you don’t add this it will be default which is zeroedthick

 

Copy virtual drive (with snapshot points)

cd /vmfs/volumes/m2sata
mkdir nahid
vmkfstools -i /vmfs/volumes/m2sata/merrikh/merrikh-000001.vmdk /vmfs/volumes/m2sata/nahid/nahid.vmdk -d thin

You should see a brief progress status and a successful copy should end with this message.

Destination disk format: VMFS thin-provisioned
Cloning disk '/vmfs/volumes/m2sata/merrikh/merrikh-000001.vmdk'...
Clone: 100% done.

Switches used:

  • -i switch is for clone. You need this.
  • -d switch tells the disk format. If you don’t add this it will be default which is zeroedthick

Clone Virtual Host

Then follow normal steps to add a new virtual machine as below.

1 Create New VM

Everything else not included in the figures can be left as default. Finish create new virtual machine process.

Now at this stage cloning your virtual machine is done. Reboot your system and its good to go.

Note: there is a known issue with Centos7 when changing motherboard or disk it might may fail to boot due to the lack of proper drivers. So follow the instructions in that page to fix the issue.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.