VMware Cloud Community
J_Wood
Enthusiast
Enthusiast

Post install script not running in ESX 4 kickstart script

Greetings friends...

I have used code samples from several examples I have found both here and on other groups and blogs. If some code looks familiar, thank you!

I am having an issue with the final piece of my ESX4 install script. For the most part, everything works great and the script builds a functioning ESX host however the last few steps that must be done in a script still elude me.

Here is my script fragment:

#######################################

#Create post-install config script

cat << \EOF > /etc/rc3.d/S99post.sh

#!/bin/bash

###################

#Enable VMotion on the VMKernel port

/usr/bin/vmware-vim-cmd hostsvc/vmotion/vnic_set vmk0

###################

#Set active and standby failover policy for vSwitch0 uplink nics

/usr/bin/vmware-vim-cmd hostsvc/net/portgroup_set vSwitch0 'Service Console' --nicorderpolicy-active vmnic0 --nicorderpolicy-standby vmnic1

/usr/bin/vmware-vim-cmd hostsvc/net/portgroup_set vSwitch0 'Production' --nicorderpolicy-active vmnic1 --nicorderpolicy-standby vmnic0

###################

#Grant host administrator privileges to esxadmin group members

/usr/bin/vmware-vim-cmd vimsvc/auth/entity_permission_add vim.Folder:ha-folder-root esxadmin true Admin true

###################

#Reset system to normal boot mode

#rm /etc/rc3.d/S99post.sh

EOF

chmod +x /etc/rc3.d/S99post.sh

As you can see in this example I am trying to run this from /etc/rc3.d. I have tried this several different ways, saving to /tmp (which ESX4 kindly clears for me after install, thanks guys! ), calling a separate script from /rc.d/rc.local and so on. None have executed this final script. However when I execute the script after I log in it runs just fine and does just what I expect.

What am I missing to get this to run on first boot?

Thanks for any assistance...

JAMES WOOD | SENIOR SYSTEMS ADMINISTRATOR | ARIZONA DEPARTMENT OF TRANSPORTATION

Phoenix, Arizona

James Wood, VCP
Senior Systems Administrator | Arizona Department of Transportation | Phoenix, Arizona
Tags (2)
0 Kudos
7 Replies
bretti
Expert
Expert

Give this a try. It has worked for me.

%post --interpreter=bash

cat > /etc/rc.d/rc3.d/S11servercfg << EOF

#!/bin/bash

###################

#Enable VMotion on the VMKernel port

/usr/bin/vmware-vim-cmd hostsvc/vmotion/vnic_set vmk0

###################

#Set active and standby failover policy for vSwitch0 uplink nics

/usr/bin/vmware-vim-cmd hostsvc/net/portgroup_set vSwitch0 'Service

Console' --nicorderpolicy-active vmnic0 --nicorderpolicy-standby vmnic1

/usr/bin/vmware-vim-cmd hostsvc/net/portgroup_set vSwitch0 'Production'

--nicorderpolicy-active vmnic1 --nicorderpolicy-standby vmnic0

###################

#Grant host administrator privileges to esxadmin group members

/usr/bin/vmware-vim-cmd vimsvc/auth/entity_permission_add vim.Folder:ha-folder-root esxadmin true Admin true

  1. Rename the file after first execution. Since file name isn't Cap S, it's ignored in subsequent boots -- a run-once script.

mv /etc/rc.d/rc3.d/S11servercfg /etc/rc.d/rc3.d/s11servercfg

EOF

  1. Make the S11servercfg file executable

/bin/chmod +x /etc/rc.d/rc3.d/S11servercfg

EOF

0 Kudos
J_Wood
Enthusiast
Enthusiast

Okay, it seems the script is running becuse it will rename the

script file however none of the commands in the script are successfull

(with exception of the rename command).

Here is what I ended up with:

#######################################

#Create post-install config script

cat > /etc/rc.d/rc3.d/S11servercfg << EOF

#!/bin/bash

###################

#Enable VMotion on the VMKernel port

/usr/bin/vmware-vim-cmd hostsvc/vmotion/vnic_set vmk0

###################

#Set active and standby failover policy for vSwitch0 uplink nics

/usr/bin/vmware-vim-cmd hostsvc/net/portgroup_set vSwitch0 'Service

Console' --nicorderpolicy-active vmnic0 --nicorderpolicy-standby vmnic1

/usr/bin/vmware-vim-cmd hostsvc/net/portgroup_set vSwitch0 'Production'

--nicorderpolicy-active vmnic1 --nicorderpolicy-standby vmnic0

###################

#Grant host administrator privileges to esxadmin group members

/usr/bin/vmware-vim-cmd vimsvc/auth/entity_permission_add vim.Folder:ha-folder-root esxadmin true Admin true

###################

#Reset system to normal boot mode

mv /etc/rc.d/rc3.d/S11servercfg /etc/rc.d/rc3.d/s11servercfg

EOF

bin/chmod +x /etc/rc.d/rc3.d/S11servercfg

I am going to redirect the output of each command to a file and see if there are any errors reported.

JAMES WOOD | SYSTEMS ADMINISTRATOR | ARIZONA DEPARTMENT OF TRANSPORTATION

Phoenix, Arizona

James Wood, VCP
Senior Systems Administrator | Arizona Department of Transportation | Phoenix, Arizona
0 Kudos
bretti
Expert
Expert

I've had issues with some commands not running as well. The best thing you can do is put some logging in place in the script to see why it's not working. Or try some different commands.

0 Kudos
jah81
Contributor
Contributor

Hi James, did you ever find a solution for this - I seem to be having the same problem?

0 Kudos
J_Wood
Enthusiast
Enthusiast

No, I never did. What I ended up doing was havig the install build the script then manually run it when I logged in to the host. That doesn't help much for automating the deployment of new hosts though.

JAMES WOOD | SYSTEMS ADMINISTRATOR | ARIZONA DEPARTMENT OF TRANSPORTATION

Phoenix, Arizona

James Wood, VCP
Senior Systems Administrator | Arizona Department of Transportation | Phoenix, Arizona
0 Kudos
Sreejesh_D
Virtuoso
Virtuoso

it may be an issue with the wake up delay of hostd. can you try with a SLEEP 60 at the beginning of script?

:+: VCP,RHCE,EMCPA.

0 Kudos
whitey1123
Enthusiast
Enthusiast

Ok I know this is an old thread but I FINALLY just ran into the fix for the symptoms you are experiencing. Put another '/bin/sleep 120' statement in your second %post section right after your #!/bin/bash lineand all will be well. Been busting my head for hours now banging away at my script to no avail and then added this. It apparently lets hostd fire back up and allows the rc.local to run the script once and removes it. Just be patient after the initial reboot of the kickstart network install and watch your virtual console (f1 is a lifesaver). You can debug fairly well using the f1 console but I usually find it takes about 1 minute for hostd to come up while the post script is sleeping for my designated two minute interval and then you will see the changes apply in the recent tasks pane. Long and short, be patient and watch f1 console for success of debugging and also your recent tasks pane for the commands to be executed. I am currently usign the following modifications and plan to investigate auto setting additional VMFS volumes adds to 8 MB default block size.

%post --interpreter=bash

cat << \EOF > /etc/rc3.d/S99postconf

#!/bin/bash

/bin/sleep 120

/usr/sbin/esxcfg-firewall --openport 88,tcp,out,KerberosClientTCP

/usr/sbin/esxcfg-firewall --blockOutgoing

/usr/bin/vmware-vim-cmd hostsvc/vmotion/vnic_set vmk0

/usr/bin/vmware-vim-cmd hostsvc/memoryinfo 838860800

/usr/bin/vmware-vim-cmd vimsvc/auth/entity_permission_add vim.Folder:ha-folder-root lg-esxsu true Admin true

echo “Removing automated post script.”

rm /etc/rc3.d/S99postconf

EOF

chmod +x /etc/rc3.d/S99postconf

0 Kudos