Difference between revisions of "Creating a CentOS\Red Hat VMware template"

From Peter Pap's Technowiki
Jump to: navigation, search
(Created page with "One of the good things about VMware is that you can create an OS template. That's a complete pre-configured VM that you can use to create other machines from. However, you can...")
 
(Make sure the template is correct)
Line 23: Line 23:
  
 
NOTE: If you have to reboot for any reason before converting this VM into a template, you will have to repeat step 2.
 
NOTE: If you have to reboot for any reason before converting this VM into a template, you will have to repeat step 2.
 +
 +
 +
== Fixing a VM made with a bad template ==
 +
 +
So you didn't follow the instructions above and now have a machine with incorrect MAC addresses and no network connectivity.  You can recover it by:
 +
 +
1. Edit any ifcfg-ethX files, in /etc/sysconfig/netwrok-scripts/, that you may have and delete the MAC address lines, i.e. HWADDR=XX:XX:XX:XX:XX:XX
 +
 +
2. Edit /etc/udev/rules.d/70-persistent-net.rules and delete any lines that have a MAC address in them.
 +
 +
3. Shutdown the VM
 +
 +
4. Delete the Virtual interfaces from the machine via the vSphere Client and then add them again.
 +
 +
5. Re-start the VM.
 +
 +
It should now have re-created the contents of etc/udev/rules.d/70-persistent-net.rules and should have the right MAC addresses for each NIC.

Revision as of 06:46, 8 February 2012

One of the good things about VMware is that you can create an OS template. That's a complete pre-configured VM that you can use to create other machines from. However, you can get into a little bit of trouble with CentOS/Red Hat, in particular with networking. When creating a template, you first build a VM, install an OS, configure it the way you like it and then convert it into a template. When you convert a CentOS/Red Hat VM into a template it will keep the virtual NIC MAC address of the original VM you created it from. As such, when you build other VM's from this template, they will have incorrect MAC addresses for their virtual NIC's. Here's how to make sure this doesn't happen.


Make sure the template is correct

The last steps before converting the VM into a template should be:

1. Edit any ifcfg-ethX files, in /etc/sysconfig/netwrok-scripts/, that you may have and delete the MAC address lines, i.e. HWADDR=XX:XX:XX:XX:XX:XX

2. Edit /etc/udev/rules.d/70-persistent-net.rules and delete any lines that have a MAC address in them.

Example:

 # PCI device 0x8086:0x1076 (e1000)
 SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0e:0c:07:75:dd", ATTR{type}=="1", NAME="eth0"
 
 # PCI device 0x8086:0x103a (e100)
 SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0e:a6:35:9c:be", ATTR{type}=="1", NAME="eth1"

NOTE: Don't worry, this will be automatically re-created when you start the new VM.

3. Shutdown the VM and convert into a template immediately.

NOTE: If you have to reboot for any reason before converting this VM into a template, you will have to repeat step 2.


Fixing a VM made with a bad template

So you didn't follow the instructions above and now have a machine with incorrect MAC addresses and no network connectivity. You can recover it by:

1. Edit any ifcfg-ethX files, in /etc/sysconfig/netwrok-scripts/, that you may have and delete the MAC address lines, i.e. HWADDR=XX:XX:XX:XX:XX:XX

2. Edit /etc/udev/rules.d/70-persistent-net.rules and delete any lines that have a MAC address in them.

3. Shutdown the VM

4. Delete the Virtual interfaces from the machine via the vSphere Client and then add them again.

5. Re-start the VM.

It should now have re-created the contents of etc/udev/rules.d/70-persistent-net.rules and should have the right MAC addresses for each NIC.