Cloning a VM on ESX Server 3.0.1

I’ve had time this week to get familiar with our test server environment which is a rather old Dell server running VMWare ESX Server 3.0.1. After creating a new VM and getting a base linux OS configured, I wanted to clone it for later use. I’ve used VMWare Workstation and VMWare Server before and the … Continue reading “Cloning a VM on ESX Server 3.0.1”

I’ve had time this week to get familiar with our test server environment which is a rather old Dell server running VMWare ESX Server 3.0.1. After creating a new VM and getting a base linux OS configured, I wanted to clone it for later use. I’ve used VMWare Workstation and VMWare Server before and the cloning process there is very simple–just copy. On ESX Server, there are a couple more steps required and then some other steps that are optional, but make life easier in the long run.

Here is the process I followed to perform a clone. It worked well and I was successful in getting my cloned VM running. I didn’t find a process describing exactly what I did, so I thought I’d post it (mostly so I can find it later when I forget what I did). I did find a similar process for a slightly older version and most of this post comes from that process with a few exceptions.

  1. Perform a clean OS shutdown of the guest OS running in the VM. Ideally, this will result in the VM being powered off.
  2. Login to the ESX Server using SSH as the root user.
  3. Use “vdf –h” to determine where the VMFS filesystems are mounted. In our example, this is /vmfs/volumes/AttachedSCSI
  4. Locate the current VM image (at /vmfs/volumes/AttachedSCSI/shelob).
  5. Run “cp –r /vmfs/volumes/AttachedSCSI/shelob /vmfs/volumes/AttachedSCSI/shelob-clone &
  6. Go do something else for a while to let the copy finish (at least 30 mins)
  7. Once the copy is finished, go to the new directory (shelob-clone) and rename all the files to use the new clone name. For example, the string “shelob” will be in the filename for each file. You should rename the file so that “shelob-clone” is in the filename instead of “shelob”.
  8. Once you’ve renamed all the files, run “file *” in this directory (shelob-clone).
  9. Edit all files (back them up first) that are listed as “ASCII text” or “ASCII English text”. In each of those files, you may find references to the old filenames or directory names. Modify the references appropriately to use the new names.
  10. Also edit the shelob-clone.vmx file to remove the following lines:
    ethernet0.generatedAddress = "....."
    ethernet0.generatedAddressOffset = "....."
    uuid.location = "....."
    uuid.bios = "....."
  11. Add the following line to shelob-clone.vmx:
    uuid.action = "keep"
  12. Register the new cloned VM with ESX server by running the following command (this should all be on one line):
    vmware-cmd -s register /vmfs/volumes/AttachedSCSI/shelob-clone/shelob-clone.vmx
  13. Go to the Virtual Infrastructure client and start the new VM. If the guest OS is linux, you should expect kudzu to detect that the old Ethernet controller was removed and a new one has been added. The benefit of this detection is that it will prompt you to add network configuration information. When you’re prompted, you can choose the appropriate IP configuration/address for this new guest VM. Note that you should make sure that your original VM and the new VM have different IP addresses if you intend to have them running at the same time.

Please post suggestions in the comments and I’ll respond and/or update the post.

These steps are going to come in handy as I start playing with the VMs that eventually get posted up at www.OracleVMs.com.

48 thoughts on “Cloning a VM on ESX Server 3.0.1”

  1. Hi, I tried doing this and got the following errors.
    cp: cannot open `Test/Test.vmxf’ for reading: Permission denied
    cp: cannot open `Test/Test.vmsd’ for reading: Permission denied
    cp: cannot open `Test/Test-flat.vmdk’ for reading: Permission denied
    cp: cannot open `Test/Test.vmdk’ for reading: Permission denied
    cp: cannot open `Test/Test.nvram’ for reading: Permission denied

    The VM is stopped. I continued on and edited the vmx file. When I started the VM, it said there is a missing file and stopped. BTW you need to rename the VM inside the vmx file or there will be double entries.

  2. I didn’t know the converter tool could do clones. I’ve used the P2V (physical to virtual) converter to create a new VM based on a physical system. Is that the tool you’re talking about?

  3. A clone as described in my post is to take an existing ESX virtual machine and copy it to create a new ESX virtual machine. The converter will take a physical system and convert it to a VM (but you have to use the enterprise version to convert to an ESX server destination).

    I’ve used the converter free tool and it works quite well, but that’s not what this post was about.

  4. you can use the converter tool to take a esx virtual machine and copy it to another esx server, the same esx server or to a vmware server or workstation. i’ve done it multiple times in the last two days.

    the converter tool addresses exactly what this post was about.

  5. I see now–I think you’re talking about the licensed version of the converter tool (I’ve never used the licensed version). With the free version of the converter tool (they call it the “starter edition”), you can’t do anything related to ESX, so I guess that’s where the post here would come in handy.

    Please correct me if I’m wrong.

    Reference: http://www.vmware.com/products/converter/get.html

  6. I used the free version and it let me clone from esx to esx. try it! it’s pretty slow but it works.

  7. I’m not sure I know what vmkfstools -i does. Looks like it just clones a disk, not a whole VM by reading the docs. This process will clone an entire VM, possibly to a different server if you’d like. Maybe you know more about what vmkfstools -i does–I haven’t tried it myself.

  8. Will this process allow me to restore host to the most recent status? Will it be possible to traverse through snapshots taken on the source host?

  9. @Andrzej Excellent question. I haven’t tested that personally, but I should expect that all snapshots would be available after importing the VM on the target host. If I have time in the next few weeks, I’ll try it. If you try it and have some results, let me know and I’ll update the post here.

  10. Dan, It looks it works for most recent status of the host as well as the snapshots. Additional steps are required. Beside renaming files you will also need to modify all non-binary files to reflect all references to the new file names.

  11. That’s what step #9 above is all about–editing the contents of the non-binary files to change the references. Are you saying that you have to do more than what’s stated there in step 9?

  12. 🙂 not really, I just overlooked that. Concluding the entire procedure is complete and it works.

  13. Pingback: Confluence: ICT
  14. Why not just right click the virtual server that you have shutdown and want to clone in Virtual Centre. Once you right click, choose clone.

  15. The reason I developed this procedure was because I didn’t have access to Virtual Centre. This is the “manual” way–if you have VC, you’re right, it’s a lot easier. However, last I checked, VC isn’t free, so not everyone will have it configured.

  16. We own 3 ESX Servers and this is the method that we use ever time to copy our Master Linux Clone. Please keep in mind that if you are copying a striped version of Unix based OS you may need to some extra work to get the NIC/ETH0 online. We use Ubuntu 7.10 LTS and one you clone you must delete the: /etc/udev/rules.d/70-persistent-net.rules and reboot in order for the server to detect the new NIC/ETH0 that it thinks it has.

  17. Couldn’t you simply perform the following successfully?

    1. Create a new machine using VM Infrastructure Client choosing the same base OS that you want to clone.
    2. Once the machine is created, you log into the ESX server as root through SSH and locate the new VM machine (VMnew).
    3. Now what you can do is copy the “VMoriginal-flat.vmdk” file that you want to clone and replace the new VM “VMnewflat.vmdk” file with “VMoriginal-flat.vmdk”, making sure you change the name.
    4. Start the new VM from the VM Infrastructure Client.

  18. @Gavin: That sounds like it might work–I haven’t tried it though. Have you tried it and was it successful? Unfortunately, my ESX environment isn’t available for testing any longer, so I can’t test it out.

  19. The method proposed by Gavin worked for me with a Debian VM. Like Ryan described above for Ubuntu, here i needed to delete /etc/udev/rules.d/25-persistent-net.rules and reboot to get the NIC back up.

  20. If you would like to clone virtual machine on esx server without the help of virtual center here is the instruction to do so

    log into esx server

    su to root and type the following command

    $ vmkfstools -i /vmfs/volumes/datastore/sourcevm/sourcevm.vmdk /vmfs/volumes/datastore/destvm/destvm.vmdk

    this will clone the virtual machine from source to destination

    once you have finished cloning

    go to vi client and run file->new virtual machine

    use custom instead of typical

    give the same name as the destination virtual machine name

    use next next until you get to point where it ask’s you for select disk change it to use an existing virtual disk and specify the path to .vmdk file

    and click next and next and finish this job

    Now you should be able to turn on the machine with out any issues

    Hope this works for you 😉

  21. That looks relatively easy compared to what I tried to do originally.
    We've upgraded our ESX server now, so I'm not sure if this method works
    on 3.0.1 or not, but next time we need to clone, I'll give it a try on
    our current version.

    Thanks!

  22. Tom,

    Thanks for the tip. One of the admins here installed the tool to try it out and says it's awesome and can't believe that he gets exactly the types of things he needs for free. There is a pay-for version, but the free version does all he needs, so he's quite pleased. You've made someone's life easier–thanks!

  23. Hi Dan,

    I wonder if you can provide me with your (colleagues) backup and restore process with VM Explorer?
    I have been able to backup and restore but, I've not been able to get the restored VM to detect the operating system.

    If you can help, I would very much appreciate it!

    Thanks!
    Herc

  24. I forwarded your note/question to the admin that's tested it. I'm not sure he's done much with backup and restore, but if he has, he should respond with an email pretty soon.

  25. Hi,
    I cloned the source OAS to target using perl scripts provided in clone/bin on OAS. After cloning my source OAS became very slow.

    Please let me know if i need to remove any files after cloning on source?

  26. I don't think so and there's no reason why I would expect your source to become slow. You can read the clone scripts too and I don't think you'll find anything in there that would be a cause for slowness. There's nothing you have to delete, but if you want to clean up, I think the files that the pre-clone step create are in $OH/clone somewhere.

  27. Perfect. The VMware Infrastrcture Client Clone operation kept timing out. You saved my weekend! Thank you.

  28. You can also copy and manually edit the VMX file to reconfigure the new server.

    Also note that if you have snapshots this clone process will not clone the data that came after the snapshots. You have to merge the snapshots first – at least as far as I can tell

  29. Pingback: Communication
  30. Thanks, this worked perfectly. It is perplexing that they wouldn’t add the clone VM feature in the free version of ESX. Either way, I will just script up this process and call it a day. Thanks again.

    Chris
    BlueCava.com

  31. Pingback: Confluence: ICT

Comments are closed.