10

I've been having troubles when deploying CentOS7 from template in that the customizations do not take effect. For the VM OS setting - I have selected RHEL7 as the OS rather than CentOS (previously having learned that lesson with Oracle Linux 6.5 at my previous job). It should work right? Not exactly.

Symptom:
After deploying a new VM from the CentOS7 template, on first boot the server comes up with the correct hostname, then the customization scripts execute, and after the VM reboots it has the original template hostname again, and while /etc/sysconfig/network-scripts/ifcfg-ether has the correct settings, the ifcfg settings for the correct nic (ifcfg-e*) have not been implemented.

Background:

I followed the VMWare's instructions for CentOS setup: http://partnerweb.vmware.com/GOSIG/CentOS_7.html

After a few package additions (including net-tools which is required for vSphere customizations), I then buttoned up the template as follows using my "templatize script" (credit to http://lonesysadmin.net/2013/03/26/preparing-linux-template-vms/ for steps):

#!/bin/bash    
# clean yum cache
/usr/bin/yum clean all
#remove udev hardware rules
/bin/rm -f /etc/udev/rules.d/70*
#remove nic mac addr and uuid from ifcfg scripts
/bin/sed -i '/^\(HWADDR\|UUID\)=/d' /etc/sysconfig/network-scripts/ifcfg-eth0
#remove host keys (important step security wise.  similar to system GUID in Windows)
/bin/rm /etc/ssh/ssh_host_*
#engage logrotate to shrink logspace used
/usr/sbin/logrotate -f /etc/logrotate.conf
#and lets shutdown
init 0

Supported Versions where workarounds are no longer needed:

  • vSphere 5.5u3 (build 3000241 or higher)
  • vSphere 6.0 and higher

VMWare's "Guest OS Customization Support Matrix": http://partnerweb.vmware.com/programs/guestOS/guest-os-customization-matrix.pdf

5
  • You should incorporate the sys-unconfig into your template-creation process.
    – ewwhite
    Dec 16, 2014 at 21:45
  • @ewwhite Thanks. Good tip. I'll put that in my toolkit. Looking at it, its most useful for bare metal images where there isn't vSphere Customizations or KVM where Virt-Tools are available.
    – Jeff Burns
    Dec 17, 2014 at 3:58
  • What's your esx update version? Nov 22, 2016 at 17:05
  • My vcenter 5.5 2001466 don't show RedHat Enterprise 7 as option. Nov 22, 2016 at 17:16
  • kikicarbonell - I've updated my question to reflect where the workarounds are no longer needed, and the supported versions of Guest OS's. In your case, you need to upgrade to 5.5u3. Cheers
    – Jeff Burns
    Mar 19, 2017 at 22:39

2 Answers 2

5

UPDATE: Just tested, this still works in Centos 7.1 using RHEL 6 as the guest OS option and the command below.

FYI redhat-release is symlinked to centos-release. If you edit redhat-release, you are actually modifying centos-release.

To follow the solution's recommendation in not modifying distro specific version files, do this instead:

rm -f /etc/redhat-release && touch /etc/redhat-release && echo "Red Hat Enterprise Linux Server release 7.0 (Maipo)" > /etc/redhat-release
1
  • Thank you. I can't believe I didn't notice they were symlinked... I've moved the solution to your answer as its nice, succinct, and accurate for what I had actually originally intended.
    – Jeff Burns
    Jan 22, 2015 at 15:23
6

Solution: I changed /etc/redhat-release to a vSphere recognized value of "Red Hat Enterprise Linux Server release 7.0 (Maipo)", and I can now deploy a VM from my CentOS7 template with customizations applied just fine. Be sure to rm the existing /etc/redhat-release symlink first. See mjevange's answer for the elegant one liner solution.

Background: After creating and deploying a new Oracle Linux 7 (OEL7) template using the same method as above for CentOS 7 and having it WORK, I quickly realized what the issue was. Check it out:

Default /etc/redhat-release file in Centos7:

 cat /etc/redhat-release
 CentOS Linux release 7.0.1406 (Core)  

Default /etc/redhat-release file in RHEL7/OEL7:

 cat /etc/redhat-release
 Red Hat Enterprise Linux Server release 7.0 (Maipo)

(Please note that the version files for CentOS and Oracle Linux are centos-release and oracle-release respectively. Do NOT touch those as they are the distro specific version files.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .