Cloning a running Virtual Machine using the Service Console

Cloning a running Virtual Machine using the Service Console

To clone a virtual machine with VirtualCenter you have to power off the guest, but what if your next maintenance window isn’t any time soon, you can’t afford to schedule the outage, or you just need a copy of the VM during normal business hours? Did you know that making a copy of a running, powered on VM is possible. At a high level the process requires a snapshot to freeze the VM’s original disk which in turn allows you to clone the frozen disk. This is essentially the way VCB, vRanger, or any of the live VM backup products work. Therefore, cloning a powered on VM can be accomplished with a little Console command magic.

I want to acknowledge that researching this method was inspired by the VMTN Virtualization Roundtable Episode 1 Podcast’s coverage of snapshots. Specifically Eric Siebert mentions that using VMware Converter as an alternative to committing snapshots is not the best option and offers the idea of using vmkfstools to do the job.


Also, this step by step guide is based on the “How can I hot clone a VM without using VMware Converter?” tip found at  Vmware-land.com’s VMware Tips.

  1. Login to the Service Console (Use mRemote or Putty for remote Console Access)
  2. Switch to your source VM’s directory.
    • For example if you are cloning a VM named MyVM1 enter:

      #cd /vmfs/volumes/MyVM1

  3. Create a snapshot
    • Use vmware-cmd – syntax is: “vmware-cmd <path & name.vmx file> createsnapshot <name> <description> <quiesce> <memory>”

      #vmware-cmd MyVM1.vmx createsnapshot “MyVM1 Snapshot” “Clone snapshot” 1 0

    • Setting memory to 0 prevents the snapshotting of the VM’s memory which we do not want for the clone. It will return “createsnapshot(MyVM1 Clone snapshot 1 0) = 1” when it successfully creates the snapshot.
    • Optionally you can create the snapshot using the Snapshot Manager in the VI Client.
  4. Create a new VM using the VI Client
    • For this example we will call it MyVM2.
    • Assign the NIC for this VM to an Internal Only vswitch (no physical NIC’s assigned to the vswitch) so it does not conflict with MyVM1. For the hard drive you can accept the 4GB default or make it smaller since you will be deleting it anyway. Do not power on the VM.
  5. Back at the Console Delete the .vmdk files of the new VM.
    • Switch to the MyVM2 folder

      #cd /vmfs/volumes/MyVM2

    • Delete all vmdks

      #rm *.vmdk

    • you will be prompted for deletion confirmation of the two vmdk files for the VM.
  6. Copy the original disk to the new VM directory
    • Switch back to your original VM’s directory

      #cd /vmfs/volumes/MyVM1

    • Use vmkfstools to copy your original disk to the new VM’s directory, the format is “vmkfstools –i <source vmdk file> <destination vmdk file>”

      #vmkfstools –i MyVM1.vmdk /vmfs/volumes/MyVM2.vmdk

  7. Power on your new VM using the VI Client.
    • MyVM2 will be in a crash consistent state (hard powered off) so run chkdsk if you can.
  8. Delete the snapshot
    • Remove all snapshots for MyVM1 from the Console. (you should already be in the MyVM1 folder from step 6)

      #vmware-cmd MyVM1.vmx removesnapshots

    • Optionally you can remove the snapshot using Snapshot Manager in the VI Client.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值