inVURTED.com

With great virtualisation comes great responsibility!

[TUTORIAL] Hot clone a Virtual Machine

So, they’ll tell you that you can’t make a template of a running Virtual Machine. This is how to make a template of a running Virtual Machine!

[root@esx2 volumes]# cp server1test/server1test-flat.vmdk .
cp: cannot open `server1test/server1test-flat.vmdk' for reading: Device or resource busy


Instead, we want to make a snapshot of the server1test VM and then do our magic.

Step 1: Take a snapshot of the VM
Either by using the vmware-cmd command on the Service Console or using the GUI in the VI3 client, you must make a snapshot of your source VM. Note that you don’t really care about a memory snapshot, so it isn’t necessary to check the Snapshot the virtual machine’s memory checkbox.

I’ll take my snapshot from the console:
[root@esx2 volumes]# vmware-cmd server1test/server1test.vmx createsnapshot HotClone "Creating a hot clone of this VM" 1 0
createsnapshot(HotClone Creating a hot clone of this VM 1 0) = 1

Step 2: Create the destination virtual machine
Now you need to create a new VM to place our not yet cloned disk into. Essentially, you just need to use the VI3 client to make a new VM. It will make you add a disk to that virtual machine, so just create it with a disk and then remove it. Here’s what I did:

File -> New -> Virtual Machine

Wizard Type: Typical

Virtual Machine Name: server1clone

Select a destination datastore that is present on the ESX server housing the source VM.
Pick the appropriate guest operating system to match the source VM.
Configure the processor count, RAM amount and networking as appropriate.

When prompted for the virtual disk size, just pick something small. You will replace this .vmdk later. I picked 1MB.

Step 3: Replace the .vmdk and -flat.vmdk files
Now that you have a new VM and the source VM in a snapshot mode, all you have to do is login to the Service Console of the ESX server and copy the source .vmdk files over those of the destination virtual machine.

[root@esx2 volumes]# cp server1test/server1test.vmdk server1test/server1clone.vmdk
cp: overwrite `server1test/server1clone.vmdk'? y
[root@esx2 volumes]# cp server1test/server1test-flat.vmdk server1test/server1clone-flat.vmdk
cp: overwrite `server1test/server1clone-flat.vmdk'? y

Step 4: Blow away your snapshot
Now that you’ve copied the vmdk files, you can remove the snapshot from the source virtual machine. This is best done through the VI3 client’s Snapshot Manager.

Step 5: Fix the filename in the new .vmdk file
Notice that earlier we copied server1test-flat.vmdk to a new file called server1clone-flat.vmdk. Since we renamed the -flat file, we need to edit the server1clone.vmdk file and update it to reflect this. Open the file with an editor on the ESX server and look for a line like:
RW 16777216 VMFS “server1test-flat.vmdk”
Change it to reflect the renaming:
RW 16777216 VMFS “server1clone-flat.vmdk”

Save.

Step 6: Boot your new virtual machine.
It should boot now.

http://smkelly.livejournal.com/66017.html

Tagged as:

3 Comments

  1. Interesting to see how this can be accomplished. I always thought it should be possible, contrary to VMWare’s statements.

    Regarding step 5, where did the monkeys come from? Don’t you mean server1 instead?

  2. Yeah. It should have been server1. I will edit it out.

  3. You could at least credit the original author that you’ve plagiarised.

    http://smkelly.livejournal.com/66017.html

    And you really should use vmkfstool instead of cp.

Leave a Response

Please note: comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

*