Search This Blog

Wednesday, October 1, 2008

ESXi Copy/Clone VM - Poor Man's Template and Clone

Ran into an issue today on a ESXi box.

We do not have VirtualCenter in a remote location and we wanted to add a new ESXi server. Do it as cheap as possible - no VC and thus no Templates.

1st problem - need to copy ISO's to the ESXi box to do the Windows installations.
No Problems - just login to the local VI client of the server and use the datastore browser to upload files to the root of datastore1.

Now - use these ISOs to install Windows Server.
Patch Windows Server.

Problem 2 - Without VirtualCenter you do not have the ability to make a template of this server. Also on ESXi you cannot clone a server.
  1. In VI create a new directory in the datastore for your new server
  2. Copy the vmdk file from the Windows Server you created 1st into this new directory. Only copy the vmdk file - nothing else.
  3. Now you need to get a console on ESXi to do some of this work. But, no service console and no SSH. I found a posting on how to enable the 'Tech Support' mode on ESXi and that will open SSH.
WARNING - This is NOT SUPPORTED and introduces Security Issues, follow at your own risk.
From (http://www.yellow-bricks.com/2008/08/10/howto-esxi-and-ssh/)
  1. Go to the ESXi console and press alt+F1
  2. Type: unsupported
  3. Enter the root password
  4. At the prompt type “vi /etc/inetd.conf”
  5. Look for the line that starts with “#ssh” (you can search with pressing “/”)
  6. Remove the “#” (press the “x” if the cursor is on the character)
  7. Save “/etc/inetd.conf” by typing “:wq!”
  8. Restart the management service “/sbin/services.sh restart”

Now login via Putty to get a console.

  1. Navigate to the new directory created above. (cd \vmfs\volumes\datastore1\xxx)
  2. rename the Server to the new name (mv 'Windows1.vmdk' 'Windows2.vmdk')
    Need to do this for both files - the vmdk and the *-flat.vmdk
  3. VI Windows2.vmdk
  4. find the line near the top that has the old filename listed
  5. change this filename to the new one and save/exit VI

Back to VMWare VI client

  1. Make a new VM on this server
  2. Choose 'Custom' and when you get to the 'Select a Disk' portion of creation you will browse the datastore and select this newly renamed vmdk file.

Now just start the new VM and go!

EDIT

You can use these same steps to clone a VM.
Just take the VM that you wish to clone and do the VMDK copy from above. Don't forget to edit the new vmdk file and then create a new VM - attach this copy of the vmdk and you have now cloned a VM in ESXi!

11 comments:

Unknown said...

Hi, I've tried to follow the steps you indicated to clone an existing VM on ESXi 3.5 but when I try to power on the cloned VM I get the following error message:

""this virtual machine cannot be powered on because its working directory..."

Do you have any ideas what can be causing this?

Thanks in advance!!

Andre

Unknown said...

Or, you could just try something like this to clone a VM.

http://www.slashzero.com/2008/10/how-to-thin-provision-an-exsiting-vmware-disk-on-esxi-without-virtual-center/

Raf said...

Response to Andre's question.

The error message you're getting is quite misleading.
One on the cause is that the original VM has its CD/DVD drive pointing to an ISO file.
If this file is not accessible by your cloned VM you're likely to get this message.

I've solved this by editing the .vmx file (it's plain text) and remove the line with mention to an iso file.
I believe you can also edit the VM settings and got rid of it there.

Hope this helps.
Cheers
Raf

Unknown said...

Just came across this when I needed to clone a series of Linux installs for a class I'm providing. My question is, rather than using the VIC for the copy, wouldn't it make sense to just ssh in and cp the vmdk files to the new directory rather than waiting around for the VIC to finish? Is there something special the VIC does beyond just copying the vmdk and flat files over to the new directory on the datastore?

Mike King said...

You still have to use Putty to edit the vmdk file, but you can use the Infrastructure Client to copy the file as well. (Copy, Paste function)

Nyle said...

Can't you just use the datastore browser to copy the vmdk to another folder and build a new VM with that vmdk? I'm hoping so because I'd like to use that for poor man's disaster recovery for my Scalix Community VM that I just set up.

Anyone test that?

Unknown said...

When I try and PuTTY to my server it says "PuTTY Fatal Error" "Network Error: Connection Refused". Has anyone else had this same issue?

Andi said...

Corey, it didn't work for me either. After you enable ssh in /etc/inetd, do:
# ps | grep inet
(this will show you the inetd PID)
# kill -HUP [pid_of_inetd]
and Putty/ssh will start working

Unknown said...

Hey, thanks for the nice article. I tried it and it somewhat worked. Only problem is, I have a couple of files like xxxxx-000001.vmdk, xxxxx-000002.vmdk etc. in my vm's folder. I guess they belong to the snapshots. I would love to know how I could get them pulled over to the clone since I only get a very early instance by copying only the one xxxxxx.vmdk (which is also the largest file).
Anyone any clue? Thanks!

Andrew Bradley II said...

Hello Hakan,

There is a limitation on the clone/template operation and it requires that the VM not have any existing snapshots.

To do this you will have to commit all snapshots prior to makeing the template/clone.

Now you can make a copy of all files and then run the copy, commit the snapshots in this copy and complete the clone/template operation. Then you could delete this copy and restart the one with the snapshots.

Unknown said...

Awesome writeup! exactly what I was looking for. Thanks!!!

Video Conference UK