Setting the customization script for virtual machines in vSphere 7.x and 8.x
search cancel

Setting the customization script for virtual machines in vSphere 7.x and 8.x

book

Article ID: 313048

calendar_today

Updated On:

Products

VMware vSphere ESXi

Issue/Introduction

This article provides information on creating guest customization scripts for Linux virtual machines that will be applied before and after customization.

Environment

VMware vSphere ESXi 7.x
VMware vSphere ESXi 8.0.x

Resolution

Prerequisites

vmware-toolbox-cmd config get deployPkg enable-custom-scripts
  • To enable this option, launch below command in guest operating system:
vmware-toolbox-cmd config set deployPkg enable-custom-scripts true

The customization script could be defined in “Customization script” page of a customization specification for Linux, the script:
  • Is called during guest operating system customization.
  • The default timeout period for the guest customization to complete is set to 100 seconds and includes the time for the script to run when using the precustomization command-line parameter. If you run scripts that will exceeding the timeout, the guest customization will fail.
  • Is called with the precustomization command line parameter before the guest customization begins.  As a result, the virtual NIC is disconnected and you cannot access the network
  • Is called with the postcustomization command line parameter after the guest customization finishes. As a result, the script is scheduled in the initialization process after the virtual machine powers on, the NIC is connected, and you can access the network.
  • The script could be Shell, Python or Perl etc.

Sample customization scripts for Linux virtual machines:

A Linux sample Shell script

#!/bin/sh
if [ x$1 = x"precustomization" ]; then
    echo "Do Precustomization tasks"
elif [ x$1 = x"postcustomization" ]; then
    echo "Do Postcustomization tasks"
fi


A Linux sample Python script

#!/usr/bin/env python
import sys
if sys.argv[1] == "precustomization":
    print "Do Precustomization tasks"
elif sys.argv[1] == "postcustomization":
    print "Do Postcustomization tasks"


A Linux sample Perl script

#!/usr/bin/perl
if ($ARGV[0] eq "precustomization") {
     print "Do Precustomization tasks";
}
elsif ($ARGV[0] eq "postcustomization") {
    print "Do Postcustomization tasks";
}


Note:
1. The length of customization script cannot be greater than 1500 characters in vSphere 7.x, this length
    limitation has been increased to 65536 characters in vSphere 8.x.
2. The error in customization script can cause the customization failure, so please verify your customization
    script in your VM before using it to customize the VM. Follow below steps as root to do the verification.
   2.1 Save your script in a text, e.g. customization_script
   2.2 Add execute permission for customization_script
       chmod +x customization_script
   2.3 Verify the script by below commands
       ./customization_script precustomization
       ./customization_script postcustomization