If you are accustomed to VMware vCenter Server and the virtual center management tool then you are well aware of the option to clone a virtual machine. This seems to be the most simple way to create a new virtual machine, especially in a time crunched situation. While Microsoft is pretty widespread and has sufficient GUI options, Linux is not quite the same. There are a ton of Linux gurus out there so forgive me if this is quite elementary as it is aimed at the less experienced Linux user. For the purpose of this article I will use Red Hat Enterprise Linux 5.5 (RHEL) as my example, simply because I administer it on a daily basis in my virtual infrastructure. It’s important to note that VMware ESX/ESXi is based on an RHEL kernel so it’s good to at least know the basics of the Linux kernel in order to create a solid foundation on which to build your VMware skill set.
The other day I was given the task of installing and configuring ESX 3.5 (yes, we are a tad behind) on two new Dell R610 servers and then subsequently build and deploy 60 RHEL 5.5 VMs on each server. At first glance this seems like a daunting task, but with the use of Virtual Center and its endless options, it is much more manageable than you would think. After installing and configuring the servers, I added the hosts to my vCenter inventory and then created an RHEL 5.5 virtual machine. Once I created it, I opened up a new terminal window and typed hostname RHEL01 which on the surface seems to have applied the hostname. However, if you are to reboot your machine and type the hostname command in a terminal window, you would not see RHEL01, it doesn’t stick. The proper way to give your VM a hostname that will stick is to configure both your /ect/hosts file as well as your /etc/sysconfig/network file.
The /etc/hosts File
What the heck is an /etc/hosts file anyways? Your /etc/hosts file is a simple text database that will work in conjunction with DNS in giving you name to IP address mapping, in short, it puts the name with and address. If you don’t have a DNS server stood up you can place the host name of all your local computers connected to your LAN. To configure your /etc/hosts file, simply open a terminal window, type vim /etc/hosts then hit enter, and your /etc/hosts file will appear in your vim editor. At this point in time you will see in the /etc/hosts file the file name of the VM that you cloned from. Having multiple VMs with the same hostname will cause you havoc on your network, I think this is pretty obvious though. This is where you need to enter into edit mode (by typing a lower case i) and change the old host name to your new hostname, hit esc when you are done and then :wq! to save what you have written in that file. Your /etc/hosts file should look something like this (depending on the distro of Linux):
- 127.0.0.1 localhost.localdomain localhost
188.8.131.52 server.name.de server
The /etc/sysconfig/network File
Now that you are a vim genius, and you have conquered the /etc/hosts file, time to graduate over to the /etc/sysconfig/network file. This is important because if you leave it configured with the original VM’s network settings you will obviously have an IP address conflict and you’ll never reach the Internet (duhn, duhn, duhn!). So let’s make it right so that we don’t have users griping at us. Your /etc/sysconfig/network file will look something like this (depending on the distro of Linux):
You will need to make sure that NETWORKING is set to yes, FORWARD_IPV4 is set to yes, make sure you erase the old host name and enter your new host name, then set your GATEWAY to whatever it is on your given subnet, GATEWAYDEV should be where gwdev is the device name eth# you use to access the remote gateway. That’s it, it’s quite simple and there is nothing more you need to do with this file.
Clone With Caution
You should be set to clone away on your ESXi host. Just remember that if you attempt to do to many clones at the same time, you will take a major hit on performance speed. Take your time, never attempt to have more than 5 clones processing at the same time. Another important thing to remember is to make sure you have enough space on your host for the amount of clones that you or your customer wants. I ran into this problem with a customer and he was incensed that he couldn’t have as many clones as he wanted. He wanted VMs with huge hard drives but didn’t have enough SAS drives to cover it. Just make sure you cover your bases before diving into a cloning frenzy, make sure it will be easy, that’s how it’s supposed to be.