Clone a VMware’s VM without vCenter in ESXi 5.x by commands (the official way)

Almost a year ago, I wrote an article about cloning VMWare VMs via vSphere client GUI and actually this is one of the most viewed posts in my blog. This method had the disadvantage of keeping the vm filenames the same. Let’s see an official way of cloning VMWare vms using vmkfstools command. Of course this method works with the free edition of ESXi 5.5 as well. I will show the procedure by cloning a snapshot of a vm since this is a little more tricky than cloning just a single vm.

First let’s make a snapshot of my Xp3 vm. Right click the vm and make a snapshot, let’s call it “mySnapshot”. Of course you don’t need to do this if you just want to clone a single vm. After that, shutdown the vm otherwise the files will be locked.

vm snapshot

vm snapshot

Now enable the ssh service on your ESXi by going to the configuration tab and the security policy option. Just start it for the moment, you don’t need to set it to start automatically. Use a ssh client like putty and connect to the hypervisor. Browse the folder under /vmfs/volumes path. It should look like this

datastores

datastores

so type

cd /vmfs/volumes
ls -la

in my case I have two datastores and my Xp3 vm is in datastore2, so let’s get into it.

Xp3 vm and snapshot

Xp3 vm and snapshot

cd datastore2
ls -la

As you can see now, there are more than one vmdk disk files, the flat vmdk, the delta vmdk and the vmdk descriptor file (the Xp3-000001.vmdk file in our example), along with the memory snapshot and various control and log files. What we should use here as a source file is the descriptor file that points to our snapshot. If you didn’t have a snapshot, the source file would be the vmdk descriptor file of your vm, Xp3.vmdk.

Now, what I need to do is clone my Xp3 snapshot to a new Xp4 vm. First create the destination folder in datastore2 folder and type in the following commands

mkdir Xp4

and clone the disk file

vmkfstools -i /vmfs/volumes/datastore2/Xp3/Xp3-000001.vmdk /vmfs/volumes/datastore2/Xp4/Xp4.vmdk -d thin

if it was a single vm without a snapshot, you should run

vmkfstools -i /vmfs/volumes/datastore2/Xp3/Xp3.vmdk /vmfs/volumes/datastore2/Xp4/Xp4.vmdk -d thin

if you list the files in the destination folder you will see the new flat file and the descriptor file.

cloned disk files

cloned disk files

The actual syntax of vmkfstools command is

vmkfstools -i source_path destination_path -d disk_format -a adapter_type

type man vmkfstools for more on this command

Finally create a new vm and force the use of an existing disk file.

create new vm

create new vm

use existing virtual disk

use existing virtual disk

select the cloned vmdk

select the cloned vmdk

You are ready to power it on.

power on

power on

if you list the folder of the cloned vm you will see something like that

cloned vm files

cloned vm files

Don’t forget to use sysprep command in windows to generalize your new virtual machine. More on this at the end of my previous article.

Reference: VMWare’s website article

Advertisements

Installing Xentools on Ubuntu 13.04 desktop on Citrix XenServer 6.2 hypervisor

When I installed ubuntu 13.04 desktop on a Citrix Xenserver 6.2 hypervisor I could not use XenMotion to live migrate the vm from one hypervisor to another since the xentools could not be installed via gui. The problem solved by running the following commands on a terminal session on ubuntu desktop (this works with the server edition as well).

First mount the dvddrive to xentools.iso on xencenter gui or by executing:

sudo mount /dev/cdrom /mnt

on a terminal console. Then run:

cd <mounted path>/Linux (in our case cd /mnt/Linux)

and

ls -la (to see the included packages) and finally

sudo dpkg -i ./<the package>.deb (there are 2 different versions for i386 and amd64 architectures)

and reboot the vm.

in my example I run sudo dpkg -i ./xe-guest-utilities_6.2.0-1120_i386.deb on my i5 box.

Depackaging xentools

Depackaging xentools

Now you are ready to suspend the vm or enable xenmotion and migrate the ubuntu virtual machine to another host.

Ubuntu vm live migration

Ubuntu vm live migration

Installing VMware vCenter Appliance on vSphere

VMware‘s vCenter server provides a centralized platform for managing your virtual infrastructure. The vCenter Server Appliance (vCSA) is a preconfigured Linux-based virtual machine that is optimized for running vCenter Server and associated services. Note that this version does not support Microsoft SQL server and IBM DB2. vCSA has some limitations, so it is not prefered in production environments. There is an interesting article summarizing these VMware vCenter Server Appliance 5.1 (vCSA) Limitations.

Goto myVMware Downloads page and press the button “View Download” at VMware vCenter Server record.

myVMware downloads page

myVMware downloads page

Then press the “Download Manager” button at the VMware-vCenter-Server-Appliance line with File type OVA. An OVA (open virtual appliance or application) is merely a single file distribution of the OVF and VMDK files stored in the TAR format.

An OVF refers to the Open Virtualization Format, which is a “packaging standard designed to address the portability and deployment of virtualization appliances”. The OVF file is a descriptor file of the packaging and VMDK files are containers for virtual hard disk drives of the appliance. For example, our OVA file includes the following files:

The ova file

The ova file

You can see the manifest file and the certificate files as well.

Appliance Download

Appliance Download

And download the appliance file. Then open the vCenter client and connect to your hypervisor. Select “Deploy OVF Template” from the main menu, to start the import wizard. Browse the downloaded ova file and press Next.

Source File

Source File

OVF Template Details

OVF Template Details

Enter the name for the Appliance, for example “vCenter Appliance”.

Name and Location

Name and Location

Select  Thick Provision Eager Zeroed disk format since this is the fastest way to write to a virtual disk (without zeroing blocks first or extending the disk file). I copy the policies from VMware’s website:

Thick Provision Lazy Zeroed

Creates a virtual disk in a default thick format. Space required for the virtual disk is allocated when the virtual disk is created. Data remaining on the physical device is not erased during creation, but is zeroed out on demand at a later time on first write from the virtual machine.

Using the default flat virtual disk format does not zero out or eliminate the possibility of recovering deleted files or restoring old data that might be present on this allocated space. You cannot convert a flat disk to a thin disk.

Thick Provision Eager Zeroed

A type of thick virtual disk that supports clustering features such as Fault Tolerance. Space required for the virtual disk is allocated at creation time. In contrast to the flat format, the data remaining on the physical device is zeroed out when the virtual disk is created. It might take much longer to create disks in this format than to create other types of disks.

Thin Provision

Use this format to save storage space. For the thin disk, you provision as much datastore space as the disk would require based on the value that you enter for the disk size. However, the thin disk starts small and at first, uses only as much datastore space as the disk needs for its initial operations.

Disk Format

Disk Format

Select the Network Map.

Network Mapping

Network Mapping

Check the Power on after deployment checkbox and press Finish.

Ready to Complete

Ready to Complete

It will take some time to deploy the vCenter Appliance.

Deploying

Deploying

Deploying

Deploying

Finally the vCenter Appliance will appear on vSphere client. It will power on and get an ip from your DHCP server.

vCenter Appliance Console

vCenter Appliance Console

Open a browser and type in the url of the appliance at SSL port 5480. for example https://10.1.1.10:5480

vCenter Appliance Administrative Console

vCenter Appliance Administrative Console

The default login credentials are username root and password vmware.

13

Finally configure the appliance pressing the setup wizard button!

Adding static routes to VMware’s vCenter Virtual Appliance

Sometimes it is useful to statically assign different gateway addresses for different network segments when configuring multiple Service Console network interfaces on VMware vCenter appliance.

A. To apply a static route on an ESXi host, effective immediately, but not persistent across a reboot:

Connect to host with a ssh client (I prefer putty) and execute the following command:

# route add -net <TargetNetwork> netmask <NetmaskAddress> gw <GatewayAddress> dev <interface>

e.g. route add -net 10.1.2.0 netmask 255.255.255.0 gw 10.1.1.1 dev eth0

then run

# route

to verify that the route was added successfully. In our example, the entry 10.1.2.0 10.1.1.1 255.255.255.0 UG 0 0 0 eth0 should appear.

B. To apply a persistent static route on the appliance:

Connect to host with a ssh client and open the static-routes file with a text editor:

# vi /etc/sysconfig/network/ifroute-eth0

(supposing the interface is eth0)

For every route add a line with the following format:

<TargetNetwork> <GatewayAddress> <Netmask> <Interface>

Then run the following command:

# service network restart

and finally verify the route with:

# route

Cloning a VM without vCenter in ESXi 5.1 free edition

Check out my new vm cloning article here.

VMware vSphere is the most robust virtualization solution today. Cloning a Virtual Machine (VM) in ESxi 5.1 is a feature of vCenter server. Out of the box vSphere free edition hypervisor does not support cloning. But there is an alternative way to clone a VM.

vSphere client version

vSphere client version

In this example we will use version 5.1.0.

vSphere client connection

vSphere client connection

First connect to the VSphere using the vSphere client and power off the source VM.

vSphere client User Interface

vSphere client User Interface

Select the Configuration tab and Storage settings on the left menu. The Datastores list will come up on the right pane.

vSphere Datastores

vSphere Datastores

Right click on the datastore of the source VM and select Browse.

Datastore

Datastore

Right click on the root folder on the left tree and create a new folder. e.g Application

Copying the files

Copying the files

Select the source folder of the VM to be cloned (2008R2 Machine in this example) and select the configuration file (.vmx) and the virtual disk file (.vmdk). Right click and copy them to clipboard. Now select the destination folder and paste the two files. Finally, right click the copied .vmx file and select Add to Inventory.

Add to Inventory wizard

Add to Inventory wizard

Enter the name of the cloned VM and finish the wizard. Now the VM has been created to the vSphere hypervisor.

In case of  using a VM as a template you should make sure that the template is unique everytime. So you must use sysprep utility to generalize the VM. In case of windows 2008R2 sysprep is included in the windows installation, under the folder c:\windows\System32\sysprep. This utility exists for other Windows versions as well.

Sysprep utility

Sysprep utility

Run sysprep and select Enter System Out-of-Box Experience, check the Generalize box and select Shutdown.

Make a generic VM template

Make a generic VM template

Now everytime you power on the template VM, a mini setup will come up to configure your new VM.

Post Remarks

Check out my new vm cloning article here.

As Frank noted in the comments, it is possible to clone the vm and specify the filenames by command. SSH to your ESXi and use the vmkfstools -i command. Use -d option to specify the thin/thick disk format. Be careful if you need to consolidate delta disks/snapshots. You can find more detailed information in this VMware’s article.