How to clone ESXi 5

I recently received an e-mail with the following question: How do I copy an ESXi installation from a USB key drive on to the internal hard disk of my computer? Normally you would answer like this: You don't do it. You backup the ESXi configuration (e.g. with the vicfg-backup tool), install a fresh copy of ESXi on your hard disk and then restore the saved ESXi configuration.

However, the guy who asked this couldn't do that, because his computer had only one CPU core, and you are not able to install ESXi 5 on a system with less than two CPU cores. Actually the USB key drive that he was using to boot this computer had been created by installing ESXi on another computer (with multiple CPU cores) and was then plugged into the one-core-machine (which is a smart way to overcome this limitation).

There is at least one other reason why you would want a clone of an existing ESXi installation rather than installing a new one: If you boot your system from a USB key drive then you might want to have an exact copy of it in a safe place for the quickest possible replacement if the primary key drive fails (Imagine the machine is at a remote location with an "IT guy" on site who has absolutely no VMware experience ...). Can you think of other reasons? Let me know in the comments of this post!

So how do you clone an ESXi 5 installation?

I will describe two different methods to do this: one super fast method for experienced Linux users, and one super easy method for all other users.

Method 1: Using dd and (s)gdisk

1. Boot the system with a Linux Live CD. I have used the lightweight Systemrescue-CD for testing, it includes all the tools that I used here.

Systemrescue-CD v3.1.2 boot screen
2. List the detected disk with a command like
   parted -l
This should list you at least the source disk (a USB key drive named /dev/sdb in my example) and the target disk (an internal hard disk named /dev/sda)

3. Print the partition table of the source disk with a command like
   sgdisk -p /dev/sdb
sgdisk is a tool for handling disks with the GPT partition table which is what a new ESXi 5.x install will use (Please note: If your system was upgraded from an earlier version of ESXi it might use the MBR partition layout). The command will produce an output like this:
Disk /dev/sdb: 15679488 sectors, 7.5 GiB
Logical sector size: 512 bytes
Disk identifier (GUID): 3703B3D8-7FBE-4A3A-8526-FE24A6BF76DC
Partition table holds up to 128 entries
First usable sector is 34, last usable sector is 15679454
Partitions will be aligned on 32-sector boundaries
Total free space is 13836413 sectors (6.6 GiB)

Number  Start (sector)    End (sector)  Size       Code  Name
   1              64            8191   4.0 MiB     EF00
   5            8224          520191   250.0 MiB   0700
   6          520224         1032191   250.0 MiB   0700
   7         1032224         1257471   110.0 MiB   FFFF
   8         1257504         1843199   286.0 MiB   0700
If your source disk is a USB key drive or SD card then you will always see exactly this list of partitions. If your source disk is a hard disk then you will notice another partition (a persistent scratch partition with a size of 4 GB) that ends at sector 10229759.

4. Note the end sector number of the last partition and dump this number (+1, because numbering starts at 0) of sectors from the source to the target disk:
   dd if=/dev/sdb of=/dev/sda bs=512 count=1843200
(As an experienced Linux user you are of course aware that this will overwrite the target disk and cause a loss of all data stored on it.)

5. Fix the GPT partition table of the target disk using the gdisk tool as follows:
   gdisk /dev/sda
      x (to enter the expert's menu)
      e (to relocate backup data structures to the end of the disk)
      w (to write the fixed partition table)

Congratulations! You now have a bootable copy of your original ESXi installation on the target disk. This was the super fast method and now for the super easy one:

Method 2: Using the Clonezilla Live CD

1. Download the Clonezilla Live CD, burn it and boot your system with it.

2. Follow the instructions on screen:
  • Choose your preferred display language and keyboard settings
  • Start Clonezilla from the menu and select the device-device mode (for copying one device to another)
  • Select "Beginner" mode and then "local disk to local disk clone mode"
  • You will then be presented with the list of detected disks with their device names and sizes, so it should be easy for you to identify and select the correct source disk:

    Select the source disk with Clonezilla's disk to disk cloning
  • In the next menu select the target disk from the remaining disk devices
  • Accept the default selection for the file system repair options (skip checking/repairing ...)
  • As a safety measure you will then be asked three times in a row whether you want to continue. Answer y each time. And you should really be aware now that your target disk will be overwritten causing a loss of all data on it ;-)
  • Now the partimage tool will finally do the job of copying all partitions:

    Clonzilla copying partitions with partimage
  • After that press Enter, then select Power off or reboot.
Clonezilla is a free and powerful tool for handling disks and partitions. You could also use it to dump the ESXi system into a backup image and later create copies of it using the backup image as input.

PSOD?

After having cloned the ESXi installation you must make sure that you do not have both the source and target disk attached to the computer when you are going to boot it. Otherwise ESXi will greet you will a PSOD (Purple Screen Of Death) and the message "Two filesystems with the same UUID have been detected. Make sure you do not have two ESXi installations" (see KB1035107). This is what I call a clear error message ;-)

Now have fun cloning!


32 comments:

  1. Great tutorial. Thank you. Next question, while this clones the VMware OS, how do you clone the storage system on the Host so that the copy has not only VMware but also the same VM's and ISO's as the source Host server?

    ReplyDelete
    Replies
    1. The latest partclone versions can also handle VMFS partition, so you can probably use the same method for this (just also include the VMFS datastore(s) besides from the system partitions).

      I never tried this though.

      Delete
    2. Stefa, did you try cloning a VMFS via the same process? If so, did it work? What tools did you use.

      Delete
    3. Stefan, Mike,
      can you please explain the use case for cloning a VM host including VMs (here or via e-mail to blog[at]v-front.de)? I'm really curious ... Thanks!
      Andreas

      Delete
    4. I'm reading this because I just bought an SSD drive for my white box ESXi installation. Right now there is a 1tb drive in the box that has both the ESXi system files and a datastore on it, and the write performance is pretty slow because EXSi does no caching as it expects a caching disk controller, which I don't have on this whitebox. I was looking for a way to clone the whole thing onto a 1tb SSD drive by connecting both drives and booting clonezilla from a usb key.

      Delete
  2. My current use case for this scenario is I have ESXi5 with datastores across 3 different physical hard drives. I want to take everything and plop it on to 1 physical hard drive. Not really sure how to do it with a clone.

    ReplyDelete
  3. I tried this using Clonezilla 2.1.2-43-amd64.iso
    1TB to 3TB Seagate

    Clonezilla appeared to copy everything and the new drive booted after the clone. There is something terribly wrong with the datastore, it knows how many VMs I have, but they have no names and will not start.

    ReplyDelete
    Replies
    1. I've done the same, using clonezilla to copy across an ESXi host and it's local datastore.

      However the local datastore was absent when the machine was brought back up.
      (I needed to change the underlying RAID so cloning the whole host was an attractive idea - although I did also backup the VM and ESXi configuration so if the clone failed I wasn't stuffed).

      I did find that the datastore was copied across though and can be re-instated.
      I removed the inaccessible VM from the inventory, which meant the datastore the ESXi host couldn't 'find' vanished.
      Rescanning the HBA didn't help.

      So then I tried adding the datastore back, specifiying the partition I had cloned.
      It did add the datastore back, using the 'Add storage' wizard but only when you specify 'Assign a new signature' withing the Select VMFS Mount Options.
      The datastore is added with a name in the format:
      snap-xxxxxxxx-
      Seems to work ok and I was able to browse the data store and add the VM without any problems.

      Delete
  4. Is there a way to copy ESXi partitions to extended partition on and existing disk? Say I have windows and Linux as dual boot and want to add ESXi as another OS on the same disk? Without erasing the disk? A partition to partition copy would or should be able to it, no?

    ReplyDelete
    Replies
    1. I don't think that this will work, and it is also not necessary to try this.
      Just install ESXi to a USB thumb drive and boot ESXi from it.

      Delete
  5. Hi, For the scenario mentioned earlier cloning the ESXi system and the VMs on three different HDDs I would:
    1)Clone the system as described in this tutorial
    2)Backup each VM using thinware or vconverter to a temporary storage
    3)Boot up your new ESXi system (with no VMs)
    4)Restore the backups back on the bigger single HDD datastore.

    :)

    ReplyDelete
  6. Hi all,

    I'm no ESX expert but after several years of using ESXi I would higly recommned Canalla's method as being one of the safest options, BACKUP BACKUP BACKUP. I have done something similar in that the ESXi OS was installed on a smaller drive with no datastore or VM's, in this case you can replace the OS drive and simply re-install ESX 5.1, it will detect existing Datasores and ask if you want to add them to the fresh install.

    Then it's just a case of adding your VM's to inventory. Bear in mind I have only done this from ESX 5.1 to 5.1, so am not sure about cross versions!

    ReplyDelete
  7. I need to move the OS and all VM's from physical site to physical site. I work in a business that installs new datacenters and the ability to build out while waiting for equipment delivery to another site is priceless. This method allows me to work weeks in advance and if time is money, this is proceless. My onely question is, which will allow this move to a different server altogether with new NICs and MAc Addresses - backup or cloning? Does either have any issues with that or can they be changed after the cloning process? Thanks! -Todd

    ReplyDelete
    Replies
    1. Hi Todd,

      please do not try to clone ESXi together with the VMs! The normal procedure in your case would be:
      1. Backup all VMs to an external hard disk (using the Export to OVF function of the vSphere client) and ship it to the destination datacenter
      2. Install ESXi on the new host in the target location (this is done really quickly)
      3. Import the VMs from the backup disk to the new host.

      If you have network connectivity between the old and the new site with sufficient bandwidth then you could also copy the VMs directly from the old host to the new host using ovftool.

      Andreas

      Delete
  8. How do I copy an existing esxi host to deploy to 12 new servers? I have nimber drivers on the "master" host.

    ReplyDelete
    Replies
    1. Hi Bob,

      I'd prefer building a customized ESXi installation ISO that includes all the additional drivers that you need and use that to install the 12 new hosts.
      You can use my ESXi-Customizer-PS to build the customized ISO.

      Andreas

      Delete
  9. Hi guys, I inherited a machine with esxi installed on USB drive and i think there is definitelly no backup of this USB key. Can I simply copy everything as it is from one usb key to another one and use it as backup? Or is the originall key somehow signed? Must the usb key has the same size? Thanks.

    ReplyDelete
    Replies
    1. Hi Anonymous,

      you can clone it using the instructions here, but you can also just backup the ESXi configuration, and - in case of desaster: reinstall ESXi on a new USB drive and restore the ESXi configuration.
      See KB2042141 for instructions.

      Andreas

      Delete
  10. This method did not work for me. I was trying to clone an ESXi 5.5 host using Clonezilla, I followed the steps, after Clonezilla finished, I powered off the system and tried to start from the new SSD drive (disconnected the old HDD), and the system said no bootable drive found.... I did not get any errors during the process. I'm just going to do a fresh install, backup and restore using other tools.

    ReplyDelete
  11. Just for future reference, if this helps anyone, I was able to get around the problem. I installed a fresh copy of ESXi on the new SSD drive, which made the SSD bootable and created the partition layout and structure. I then used Clonezilla to do partition cloning, instead of entire disk cloning. First, I cloned the two 250MB partitions from the old HDD. This is where the ESXi Linux operating system images reside, which contain all the settings, drivers and customizations. Then I cloned the largest VMFS partition from the old HDD to the SSD. This is where the Datastore with my VMs are located. After booting up the new SSD, the VMs were not available because the VMFS partition was not mounted. I mounted the partition in the ESXi GUI (keeping existing signature), and this made my VMs immediately available and able to boot up. Everything is now intact as it was working with the old HDD. The only problem now is that the VMFS partition is the same size as it was in the old HDD. Since the SSD is larger than the old HDD, I now have some open space in the SSD that is not being used. Clonezilla was unable to resize the VMFS partition when it copied it, saying that VMFS is an unknown format. This leads me to think that Clonezilla may not be fully compatible with VMFS partitions. I would like to be able to resize the VMFS partition on the SSD where my datastore resides, and I am currently researching how to do that so it can use all the space available in the new SSD.

    ReplyDelete
    Replies
    1. Hi Mario,

      have you tried using "Increase..." from the datastore properties window in the vSphere Client?

      Andreas

      Delete
    2. Yes I did. Initially, it was grayed out and I found out that in order to enable that button I needed to unmount the datastore, and re-mount it and change the signature. Once I did that, the Increase button became available. However, after clicking Increase, the LUN selection window was blank so there was nothing I could increase. I was stuck with the old partition size. I read in VMware forums that the only way would be to destroy the datastore entirely and reformat it. So I did. I moved my VMs to another drive I had (I connected it and added it as a second datastore). Then I went to ESXi shell and with the partedUtil deleted the old VMFS datastore partition in the SSD. I then used the GUI to recreate the datastore in the SSD and this time it used the entire available space. Finally, I moved the VMs back from the second datastore and re-added them to the inventory. Everything is working great now!

      Delete
  12. Hi,

    I built one ESXi 5.1 patch 2 host with RAID1 OS boot disks on IBM 3650M H/W. All disks are internal disks. Customized the settings and copied some files/scripts/software ISO into datastore1 which is the same boot disks. Then to clone the ESXi host1 I took one boot disks out and used it to build other ESXi hosts2 as I need to built more ESXi hosts. The cloned ESXi host2 booted from the disk which I took from ESXi host1 and reconfigured IMM & hostname/IP on ESXi host2 and working fine.
    The question is that I see same system/uuid in /etc/vmware/esx.conf file. I was reading article for nested ESXi host but mine is not nested but they are two independent h/w. Do I need to do anything in this scenerio. Do I need to change system/uuid or MAC address or any other settings? I do not have any VMs but I do have some VM Templates *.vmtx (not .vmx). Do I need to change anything for these VM templates? I am planning to use VM templates to build VMs on both ESXi servers. I haven't yet tried to add them into Vcenter servers yet. Would there be any issue while adding into Vcenter servers with same system/uuid?

    ReplyDelete
    Replies
    1. Hi Anonymous,

      having duplicate host UUIDs will cause issues sooner or later, so I would fix that asap.
      Just remove the line from the /etc/vmware/esx.conf file on the cloned host and reboot it. A new unique UUID will be automatically generated.

      Andreas

      Delete
  13. Thanks much Andreas,

    is there anything else I need to change besides this which I might not have notices yet? Do I need to set esxcfg-advcfg -s 1 /Net/FollowHardwareMac also?
    I see same/dumplicate mac address for vmk2 IMM_Network on both ESX hosts when I run esxcfg-vmnic -l which is I believe for vSwitchUSB0 128 3 128 1500 vusb0. vusb0 Pseudo cdc_ether Up 10Mbps Half 0a:94:ef:06:73:c7 1500 Unknown Unknown Do I need to change it. if yes, what need to do?
    How about VMTemplate? Do I need to change anything for VM template?

    ReplyDelete
    Replies
    1. Yes, also set

      esxcfg-advcfg -s 1 /Net/FollowHardwareMac

      and reboot. That should be sufficient. You don't need to do anything about the VM templates.

      Delete
    2. As a note. there is not snapshot for this LUN. So the method to resignature datastore won't work. Is there a way to change UUID of main datastore (not a snapshot)? I tried rename datastore but it shows renamed datastored on both ESXi server1 and server2.

      Delete
  14. Thanks Andreas,
    After I configured both ESX server1 & server2(cloned) I see that datastore1(22) is shown as mounted on both servers? Is this a problem? Is there any ID need to be change after cloning?

    ReplyDelete
    Replies
    1. Assign a new UUID to the cloned datastore by following instructions here.

      Delete
  15. Hello everyone. I used Clonezilla to clone my current usb esxi 6 drive to a new one using all defaults. Now neither usb will boot in my Dell r730 server. I have 3 hosts in a cluster with vsan. I did not backup the configuration.
    I have no idea why source usb was touched or changed. I booted a Clonezilla iso and it all went without error. Esxi 6 gpt boot partition may be unsupported.
    Can I repair the boot sector? Maybe run esxi install and choose upgrade?
    Thanks

    ReplyDelete
  16. I fixed the issue. Both USB flash drives were perfect. I just had to force the Dell Boot mode from BIOS to uEFI and reboot. Now I have a good copy and I'll be backing up my host from now on.
    -Carl

    ReplyDelete
  17. an other reason of cloning esxi could be because you made some manual host configuration e.g. integrating ghettoVCB or XSIbackup

    ReplyDelete

***** All comments will be moderated! *****
- Please post only comments or questions that are related to this post's contents!
- Advertising and link spamming will not be tolerated!