%post fails on ESX deployment
by Andy Archer
I sometimes get asked why commands in the %post section of kickstart files fail, often there is a reasonably simple explanation for this. Consider the following simple script that creates a virtual switch, a port group and links 2 physical nics to the switch;
%post
esxcfg-vswitch -a vSwitch2
esxcfg-vswitch -A Production vSwitch2
esxcfg-vswitch -L vmnic2 vSwitch2
esxcfg-vswitch -L vmnic1 vSwitch2
The commands from this script are syntactically correct and will run after the installer has created the file systems and copied the files and carried out a basic configuration. But the VMkernel is not loaded at this point. The %post section in the example is issuing VMkernel commands, esxcfg-<anything>, and the VMkernel is not there to carry them out.
What is needed is a script that will run after the first reboot, at which point of course the VMkernel is loaded, this script will then carry out the configuration commands.
The following version of the %post creates the script called S99verylast for run level 3. At the end the script a command renames itself so as to avoid it running on each boot.
%post
cat> /etc/rc.d/rc3.d/S99verylast << EOF99
esxcfg-vswitch -a vSwitch2
esxcfg-vswitch -A Production vSwitch2
esxcfg-vswitch -L vmnic2 vSwitch2
esxcfg-vswitch -L vmnic1 vSwitch2
mv /etc/rc.d/rc3.d/S99verylast /etc/rc.d/rc3.d/xS99verylast
EOF99
chmod +x /etc/rc.d/rc3.d/S99verylast
Take care to ensure that you use a UNIX editor, for example PFE32 for Windows, as Windows text editors add CR characters that would cause script execution to fail. |