| Article Index |
|---|
| VMware vSphere - Scripted Installer for ESX Server |
| The Pre Section |
| The Post Sections |
| The esx-post-script |
| The Actual Config |
| All Pages |
The PRE section
The special marker "%pre" identifies a section that should be executed before the installer runs the actual configuration file. The thing that makes this work is that anything in it can be bash script.
So, the first thing we do is define a %pre section, read in the options that were given at the installer prompt, and then go on to create the above two configuration files.
ks.cfg PRE
# This is the PRE section $pre --interpreter=bash set -- `cat /proc/cmdline` for I in $*; do case "$I" in *=*) eval $I;; esac; done ESXCODE=`printf "%02d\n" "$ESXID"` ESXHOSTNAME="ESX-$ESXCODE" ESXIP="10.20.30.$ESXID"
What we've done here is quite simple.
- Line 2 tells the installer to start a new PRE section, and to use bash to execute it.
- Line 4 and Line 5 take the input specified on bootup, and turns them all into variables. This means we now have an ESXID variable, which will be populated with a number.
- Lines 6, 7 and 8 take the single-digit ESXID and format it in various ways to get the hostname, and ipaddress.
Now, we can't just run the networking and partitioning options within this PRE section, because we're in a bash shell, so it doesn't know the commands. So what we do is create the files in here, then include them like we saw above.
ks.cfg PRE
# Create the disk configuration cat << EOFdisk >> /tmp/diskconfig clearpart --alldrives --overwritevmfs part '/boot' --fstype=ext3 --size=1100 --onfirstdisk part 'none' --fstype=vmkcore --size=110 --onfirstdisk part 'LocalStorage-${ESXHOSTNAME}' --fstype=vmfs3 --size=8804 --grow --onfirstdisk virtualdisk 'esxconsole' --size=7804 --onvmfs='LocalStorage-${ESXHOSTNAME}' part 'swap' --fstype=swap --size=800 --onvirtualdisk='esxconsole' part '/var/log' --fstype=ext3 --size=2000 --onvirtualdisk='esxconsole' part '/' --fstype=ext3 --size=5000 --grow --onvirtualdisk='esxconsole' EOFdisk # Create the networking config cat << EOFnic >> /tmp/networkconfig network --ip=${ESXSCIP} --hostname=${ESXHOSTNAME} --nameserver=${ESXSCIP} --netmask=255.255.0.0 --gateway=10.20.0.1 --addvmportgroup=true --device=vmnic1 --bootproto=static EOFnic
This will
- Line 2: Create a new /tmp/diskconfig file.
- Lines 3-10: output a bunch of part commands.
- Line 13: Create a new /tmp/networkconfig file.
- Line 15: output the network command.
The last (and confusing) bit in the PRE section is required because later on when we switch into the POST section, we loose access to the ESXID. So what we do is create a small runner-script which will call out main post-configuration script later with the ESXID as a parameter:
ks.cfg PRE
# The ESXID var is lost later, so keep it somewhere cat << EOFcs >> /call-script.sh /esx-post-script.sh ${ESXID} EOFcs chmod a+x /call-script.sh
Now we move onto the two POST sections. These are run after all the packages are installed, and we also have access to the new filesystem that the ESX box will be running.


