CentOS template for VRA

So with most of the configuration done, it is time to add a template. I do this now since I had an outdated template as it is and I wanted to also note down a bit of the things I do for the template.

I am not going to go through the installation of the linux distro I will be using, which is  CentOS. There are enough other pages to do this and the installation is quite intuitive. At the time of writing this, version 7.6 is still the newest release so I will go with that.

I do tend to select  a minimal installation with 512 mb ram and 5 GB harddisk. I do not usually want to have a whole lot of extra things added to my Linux system for various reasons.

I set the root password (of course) and I do create a custom user with non admin rights.

I also tend to configure sudo rights, and for the user I create as a non administrator.

The next steps are as follows (First the step and then the command to do it).

As per VMware you need to make sure a couple of things are included into the manual installation apart from what is included by default. These things are listed here.

Unzip, Perl, wget, ip-tools are the three extra repositories required from VMware.

0: Install prerequisites that are not installed in the minimal installation.

  1. yum install perl  net-tools  wget unzip yum-utils -y

1: Update the system via Yum

  1. Log in as your secondary user
  2. run sudo yum update -y and let the system perform updates
  3. Reboot the host (This is needed to load on the latest kernel and allow you to do step 3).

2: Stop logging services

  1. systemctl stop rsyslog
  2. service auditd stop (This is why I love systemctl, systemctl does not permit it to stop).

3: Clean up old kernels 

Since we installed a minimal installation we need to first install the yum-utils.

  1. /bin/package-cleanup –oldkernels –count=1 -y
  2. /usr/bin/yum clean all

4: Shrink/Clean the log space.

  1. /usr/sbin/logrotate -f /etc/logrotate.conf
  2. rm -f /var/log/*-???????? /var/log/*.gz
  3. rm -f /var/log/dmesg.old
  4. rm -rf /var/log/anaconda
  5. cat /dev/null > /var/log/audit/audit.log
  6. cat /dev/null > /var/log/wtmp
  7. cat /dev/null > /var/log/lastlog
  8. cat /dev/null > /var/log/grubby

5: Remove old hardware rules and the UUID from the ifcfg scripts

  1. /bin/sed -i ‘/^(HWADDR|UUID)=/d’ /etc/sysconfig/network-scripts/ifcfg-e*
  2. In /etc/sysconfig/network-scripts/ifcff-ens-192
    1. Change ONBOOT to “yes”
    2. CHange BOOTPROTO to “dhcp”
    3. Remove HWADDR/UUID

6: Remove the SSH host keys so it is generated with each new VM

  1. /bin/rm -f /etc/ssh/*key*

7: Clear the temp folders:

  1. /bin/rm -rf /tmp/*
  2. /bin/rm -rf /var/tmp/*

8: Remove the root users shell history

  1. rm -f ~root/.bash_history
  2. unset HISTFILE

9: Final step is to remove the users ssh history and then shut down the machine to create the template. The final command shuts down the guest and you should be ready with the template. Any additional commands you want to run on the template should be run before sys-unconfig.

  1. rm -rf ~root/.ssh/
  2. history -c
  3. sys-unconfig

After this is performed you can convert the vm to a template. Remember to create a new VM customization specification to use with VRA for the blueprint creation.