So I downloaded CentOS 7 Minimal install ISO and thought I would have my first blueprint ready to be deployed in no time. However, it took me 3 hours to figure out how to properly prepare Linux VM for Guest OS customization. The customization is also used with Site Recovery Manager to customize VMs after faill over and when providing VM with vRealize Automation.
I am gonna be working with vRA and blueprints for a while so I thought I would document all steps of the process and share it.
It is pretty simple so there will be no screenshots.
1. Enable networking (I think I missed that step in GUI installation wizard)
run
vi /etc/sysconfig/network-scripts/ifcfg-enXXXXX
And change this line as following
ONBOOT=yes
Alternatively you can enable Ethernet card using nmtui command
2. Install PERL (it is also needed for customization and it doesn't come with Minimal CentOS)
yum install perl gcc make kernel-headers kernel-devel -y ONBOOT
Check if it is installed with whereis perl command
3. Install open-vm-tools - yep, not standard Vmware tools, but open source VM tools.
yum install open-vm-tools
4. Install the deployPkg Tools Plug-in.
This is important addition to the Open VM tools which is responsible for actual customization of the Linux VM
Create reposository file vmware-tools.repo in /etc/yum.repo.d/ and add the following lines to the file.
[vmware-tool]
name = VMware Tools
baseurl = http://packages.vmware.com/packages/rhel7/x86_64/
enabled = 1
gpgcheck = 0
And then run
This helps vSphere to recognise the CentOS as RHEL and do proper customization.
If you don't run this command you will end up with customization applied to wrong files, e.g. you will have eth0 file with the IP Address you setup in Customization profile instead of updating the actual NIC file, e.g. eno16780032
rm -f /etc/redhat-release && touch /etc/redhat-release && echo "Red Hat Enterprise Linux Server release 7.0 (Maipo)" > /etc/redhat-release
6. Run Preparation script that deletes unique and temp data.
#!/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 -f /etc/ssh/*key*
#engage logrotate to shrink logspace used
/usr/sbin/logrotate -f /etc/logrotate.conf
#and lets shutdown
init 0
Create reposository file vmware-tools.repo in /etc/yum.repo.d/ and add the following lines to the file.
[vmware-tool]
name = VMware Tools
baseurl = http://packages.vmware.com/packages/rhel7/x86_64/
enabled = 1
gpgcheck = 0
And then run
yum install open-vm-tools-deploypkg
5. Change the release name
5. Change the release name
This helps vSphere to recognise the CentOS as RHEL and do proper customization.
If you don't run this command you will end up with customization applied to wrong files, e.g. you will have eth0 file with the IP Address you setup in Customization profile instead of updating the actual NIC file, e.g. eno16780032
rm -f /etc/redhat-release && touch /etc/redhat-release && echo "Red Hat Enterprise Linux Server release 7.0 (Maipo)" > /etc/redhat-release
6. Run Preparation script that deletes unique and temp data.
#!/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 -f /etc/ssh/*key*
#engage logrotate to shrink logspace used
/usr/sbin/logrotate -f /etc/logrotate.conf
#and lets shutdown
init 0
Here are some links I used when compiling this short instruction - thanks a lot guys.
http://serverfault.com/questions/653052/from-vsphere-5-5-deploying-centos-7-from-template-ignores-customizations
https://lonesysadmin.net/2013/03/26/preparing-linux-template-vms/
http://www.boche.net/blog/index.php/2015/08/09/rhel-7-open-vm-tools-and-guest-customization/
Update
I tried to re-create another Linux template today using the steps in this procedure and for some reasons deploying VM from VRA was failing during the guest customisation. However, when I cloned the VM manually from vCenter and used the same customisation all went fine.
Then I repointed the vRA blueprint to just cloned VM and now I am able to deploy VMs from vRA.
Have no idea what would cause the problem... :(
Update
I tried to re-create another Linux template today using the steps in this procedure and for some reasons deploying VM from VRA was failing during the guest customisation. However, when I cloned the VM manually from vCenter and used the same customisation all went fine.
Then I repointed the vRA blueprint to just cloned VM and now I am able to deploy VMs from vRA.
Have no idea what would cause the problem... :(
This comment has been removed by the author.
ReplyDeleteThe solution to delete HWADDR and UUID in /etc/sysconfig/network-scripts/ifcfg-… does not work for UUID.
ReplyDelete#nmcli c
still gives you the same UUID for every VM you create from the template.
It appears that the deploy package is no longer required and can cause a conflict for upgrades. https://bugzilla.redhat.com/show_bug.cgi?id=1291894
ReplyDeleteAny guidance on doing the same with Fedora 19 / 20 ?
ReplyDeleteWhat step of my guideline fail in Fedora? I never tested it with Fedora, but I believe it is pretty close to Centos.
Deletejust checked the Guest OS Customization support on vSphere and Fedora is not on the list.
ReplyDeletehttp://partnerweb.vmware.com/programs/guestOS/guest-os-customization-matrix.pdf
Niice post thanks for sharing
ReplyDelete