Skip to content

Instantly share code, notes, and snippets.

@danjellesma
Last active January 29, 2018 16:14
Show Gist options
  • Save danjellesma/a60082f03ed60d438882 to your computer and use it in GitHub Desktop.
Save danjellesma/a60082f03ed60d438882 to your computer and use it in GitHub Desktop.
CentOS 7 VMware Customization

Created on: June 26, 2015

Last Updated: July 14, 2015

Synopsis: CentOS 7 on vSphere 5.5 does not clone out correctly using normal cloning methods. Running these fixes allows VMware to deploy from a CentOS 7 template with proper customizations.

Failure to perform these actions can result in :

  • Naming failure inside the VM
  • DNS Registration Failure
  • IP and MAC address conflicts
  • DHCP Failure

CentOS 7 Template

Fix Redhat-Release for customization

https://serverfault.com/questions/653052/from-vsphere-5-5-deploying-centos-7-from-template-ignores-customizations

rm -f /etc/redhat-release && touch /etc/redhat-release && echo "Red Hat Enterprise Linux Server release 7.0 (Maipo)" > /etc/redhat-release`
Preparing Template

https://lonesysadmin.net/2013/03/26/preparing-linux-template-vms/

Stop logging service

/sbin/service rsyslog stop
/sbin/service auditd stop

Remove old kernels

/bin/package-cleanup --oldkernels --count=1

Update and clean out YUM

yum upate
yum clean all

Truncate the audit logs (and other logs we want to keep placeholders for).

/bin/cat /dev/null > /var/log/audit/audit.log
/bin/cat /dev/null > /var/log/wtmp
/bin/cat /dev/null > /var/log/lastlog
/bin/cat /dev/null > /var/log/grubby

Remove all udev persistent device rules. Specifically the net-rules must be deleted to remove any MAC addresses.

This must be run every time you boot up / shutdown the template.

rm -f /etc/udev/rules.d/70*

Remove traces of MAC and UUIDs

sed -i ‘/^(HWADDR|UUID)=/d’ /etc/sysconfig/network-scripts/ifcfg-eth0

-- Note: This might not have a ifcfg-eth0. Check for the correct name and fix as needed

Clean out /tmp

rm –rf /tmp/*
rm –rf /var/tmp/*

Remove Host SSH Keys

rm –f /etc/ssh/*key*

Remove root shell history

rm -f ~root/.bash_history
unset HISTFILE

Remove SSH history

/bin/rm -rf ~root/.ssh/
/bin/rm -f ~root/anaconda-ks.cfg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment