I create a kickstart script and anything within the standard commands works fine, however I can't get any of the post installation commands to work. If I add --vmnic0 to the networking field the install script exits prematurely. My hope was that this would be used instead of continually backing up the Host OS on ESX.
snip
Auto-Generated Scripted Install Configuration file.
This file is used for VMware ESX Server Scripted Install Deployment
Installation Method
url --url=http://[UDA_IPADDR]/[OS]/[FLAVOR]
root Password
rootpw --iscrypted 'not displayed'
Authconfig
auth --enableshadow --enablemd5
BootLoader ( The user has to use grub by default )
bootloader --location=mbr
Timezone
timezone America/Edmonton
X windowing System
skipx
Install or Upgrade
install
Text Mode
text
Network install type
network --device=vmnic0 --bootproto dhcp --addvmportgroup=0
Language
lang en_US
Langauge Support
langsupport --default en_US
Keyboard
keyboard us
Mouse
mouse none
Reboot after install ?
reboot
Firewall settings
firewall --disabled
Clear Partitions
clearpart --all --initlabel --drives=sda
Partitioning
part /boot --fstype ext3 --size 200 --ondisk sda --asprimary
part / --fstype ext3 --size 10240 --ondisk sda --asprimary
part swap --size 1600 --ondisk sda --asprimary
part /var --fstype ext3 --size 10240 --ondisk sda
part /var/log --fstype ext3 --size 10240 --ondisk sda
part /home --fstype ext3 --size 10240 --ondisk sda
part /tmp --fstype ext3 --size 10240 --ondisk sda
part /vmimages --fstype ext3 --size 5120 --ondisk sda
part None --fstype vmkcore --size 110 --ondisk sda
part None --fstype vmfs3 --size 1 --grow --ondisk sda
VMware Specific Commands
vmaccepteula
%packages
@base
@ everything
%post
#Add user for ssh connectivity
/usr/sbin/useradd console
/usr/sbin/usermod -p password console
#Modify DNS Config
cat > /etc/resolv.conf << EOF
search companyname
nameserver x.x.x.x
nameserver x.x.x.x
EOF
#Modify NTP Config
chkconfig --level 345 ntpd on
cat > /etc/ntp.conf << EOF
restrict 127.0.0.1
restrict default kod nomodify notrap
server x.x.x.x
driftfile /var/lib/ntp/drift
EOF
cat > /etc/ntp/step-tickers << EOF
172.22.20.20
EOF
/sbin/chkconfig --level 345 ntpd on
/sbin/service ntpd start
/sbin/hwclock --systohc
#MOTD Restriction Banners
cat > /etc/restricted_access << EOF
Logging onto a Restricted Server - UNAUTHORIZED ACCESS PROHIBITED
EOF
echo Banner /etc/restricted_access >> /etc/ssh/sshd_config
VMNetworking
/usr/sbin/esxcfg-vswitch --add vSwitch0:64
/usr/sbin/esxcfg-vswitch --add-pg="Service_Console" vswitch0
/usr/sbin/esxcfg-vswitch --add-pg-uplink vmnic0 vSwitch0 --pg="Service_Console"
/usr/sbin/esxcfg-vswitch --add-pg-uplink vmnic2 vSwitch0 --pg="Service_Console"
/usr/sbin/esxcfg-vswitch --add vSwitch1:64
/usr/sbin/esxcfg-vswitch --add-pg="vMotion" vswitch1
/usr/sbin/esxcfg-vswitch --add-pg-uplink vmnic3 vSwitch1 --pg="vMotion"
/usr/sbin/esxcfg-vswitch --add-pg-uplink vmnic7 vSwitch1 --pg="vMotion"
/usr/sbin/esxcfg-vswitch --add vSwitch2:128
/usr/sbin/esxcfg-vswitch --add-pg="Prod_v100" vswitch2
/usr/sbin/esxcfg-vswitch --add-pg-uplink vmnic1 vSwitch2 --pg="Prod_v100" --vlan=100
/usr/sbin/esxcfg-vswitch --add-pg-uplink vmnic4 vSwitch2 --pg="Prod_v100" --vlan=100
/usr/sbin/esxcfg-vswitch --add-pg="Prod_v21" vswitch2
/usr/sbin/esxcfg-vswitch --add-pg-uplink vmnic1 vSwitch2 --pg="Prod_v21" --vlan=21
/usr/sbin/esxcfg-vswitch --add-pg-uplink vmnic4 vSwitch2 --pg="Prod_v21" --vlan=21
/usr/sbin/esxcfg-vswitch --add-pg="VMInternal_v4094" vswitch2
/usr/sbin/esxcfg-vswitch --add-pg-uplink vmnic1 vSwitch2 --pg="VMInternal_v4094" --vlan=4094
/usr/sbin/esxcfg-vswitch --add-pg-uplink vmnic4 vSwitch2 --pg="VMInternal_v4094" --vlan=4094
/usr/sbin/esxcfg-vswitch --link=vmnic0 vSwitch0
/usr/sbin/esxcfg-vswitch --link=vmnic2 vSwitch0
/usr/sbin/esxcfg-vswitch --link=vmnic3 vSwitch1
/usr/sbin/esxcfg-vswitch --link=vmnic7 vSwitch1
/usr/sbin/esxcfg-vswitch --link=vmnic1 vSwitch2
/usr/sbin/esxcfg-vswitch --link=vmnic4 vSwitch2
perl -p -i -e 's/teamPolicy\/maxActive = "."/teamPolicy\/maxActive = "2"/g' /etc/vmware/esx.conf
Configure Command Queue Depth
if grep "QLogic" /etc/vmware/esx.conf ; then
/usr/sbin/esxcfg-module -s ql2xmaxqdepth=128 qla2300_707_vmw
fi
/usr/sbin/esxcfg-advcfg -s 128 /Disk/SchedNumReqOutstanding
/usr/sbin/esxcfg-advcfg -s 1 /Disk/UseLunReset
/usr/sbin/esxcfg-advcfg -s 0 /Disk/UseDeviceReset
/usr/sbin/esxcfg-boot -b
Set Memory for Service Console to 512 MB
/usr/bin/vimsh -n -e "hostsvc/memoryinfo 536870912"
snip
Any Thoughts?
Best practice is to cat everything into a .sh file and then on first boot you switch rc.local to use that .sh file, then at the end of the .sh file you swap back rc.local so on final boot the server boots normally.
Also, you can't run any commands that use the vmkernel during the kickstart, the vmkerel is not loaded. In v4, the vmkernel is loaded during scripted builds.
Everything between the << EOF1 and EOF1 will be echoed to /tmp/build.sh
cat >> /tmp/build.sh << EOF1
#!/bin/sh
mydate=`date +"%F_%H%M"`
log=/tmp/build-log-$mydate.txt
echo "Start build script"
linux command 1
linux command 2
linux command 3
linux command etc
We're all done with the rc.local that has the build.sh command in it.
# replace with the original and then reboot
echo "restore original rc.local"
cp --reply=yes -p /etc/rc.d/rc.local.sav /etc/rc.d/rc.local
rm -f /tmp/build.sh
echo "rebooting..."
reboot
EOF1
#
End of /tmp/build.sh creation ###############
Welcome to the Forums!!
I followed Duncan Epping's blog on this topic and it worked perfectly for me. The only hiccup I had was Windows kept wanting to put 0D characters into the file when I saved it. The presence of these characters messes the scripted install up.
http://www.yellow-bricks.com/2008/06/27/scripted-install/
Charles Killmer, VCP
If you found this or other information useful, please consider awarding points for "Correct" or "Helpful".
I followed a number of posts on this and found the only post scripts that work were the ones that only used "cat" or "echo" otherwise if I used the esxcfg commands or vimsh it doesn't even run them.
I have tried adding --interpreter=/bin/bash to the %post and the script fails completely.
Am I missing something?
Also the adduser statement only adds the user, but ssh either doesn't recognize the user is in the Ssh conf or ecetera...
Chris Halverson
Best practice is to cat everything into a .sh file and then on first boot you switch rc.local to use that .sh file, then at the end of the .sh file you swap back rc.local so on final boot the server boots normally.
Also, you can't run any commands that use the vmkernel during the kickstart, the vmkerel is not loaded. In v4, the vmkernel is loaded during scripted builds.
Everything between the << EOF1 and EOF1 will be echoed to /tmp/build.sh
cat >> /tmp/build.sh << EOF1
#!/bin/sh
mydate=`date +"%F_%H%M"`
log=/tmp/build-log-$mydate.txt
echo "Start build script"
linux command 1
linux command 2
linux command 3
linux command etc
We're all done with the rc.local that has the build.sh command in it.
# replace with the original and then reboot
echo "restore original rc.local"
cp --reply=yes -p /etc/rc.d/rc.local.sav /etc/rc.d/rc.local
rm -f /tmp/build.sh
echo "rebooting..."
reboot
EOF1
#
End of /tmp/build.sh creation ###############
That makes complete sense, I had planned on creating all these items in a bash script and running them in a cron job or something but that will work much better. I am going to try it and report back.
Thanks!
Chris
Well the solution still doesn't run. It appears nothing in the %post script works. Whether I use a cat or any other command.
I see many solutions around this that work in the post commands so is there something that I am missing?
C
Did you replace rc.local with the contents of the catted file in the %post section?
yes. here is the %post that I run
%packages
@base
@ everything
%post
#Modify DNS Config
cat > /etc/resolv.conf << EOF
search <removed>
nameserver <removed>
nameserver <removed>
EOF
#Modify NTP Config
cat > /etc/ntp.conf << EOF
restrict 127.0.0.1
restrict default kod nomodify notrap
server <removed>
driftfile /var/lib/ntp/drift
EOF
cat > /etc/ntp/step-tickers << EOF
<removed>
EOF
#MOTD Restriction Banners
cat > /etc/restricted_access << EOF
Logging onto a Restricted Server - UNAUTHORIZED ACCESS PROHIBITED
EOF
echo Banner /etc/restricted_access >> /etc/ssh/sshd_config
cat > /tmp/esxcfg.sh <<EOF1
#!/bin/sh
Configure ESX Server
/sbin/chkconfig --level 345 ntpd on
/sbin/service ntpd start
/sbin/hwclock --systohc
/usr/sbin/esxcfg-vswitch --del-pg="Service Console" vswitch0
/usr/sbin/esxcfg-vswitch --add-pg="Service_Console" vswitch0
/usr/sbin/esxcfg-vswitch --add-pg-uplink vmnic0 vSwitch0 --pg="Service_Console"
/usr/sbin/esxcfg-vswitch --add-pg-uplink vmnic2 vSwitch0 --pg="Service_Console"
/usr/sbin/esxcfg-vswitch --add vSwitch1:64
/usr/sbin/esxcfg-vswitch --add-pg="vMotion" vswitch1
/usr/sbin/esxcfg-vswitch --add-pg-uplink vmnic3 vSwitch1 --pg="vMotion"
/usr/sbin/esxcfg-vswitch --add-pg-uplink vmnic7 vSwitch1 --pg="vMotion"
/usr/sbin/esxcfg-vswitch --add vSwitch2:128
/usr/sbin/esxcfg-vswitch --add-pg="Prod_v100" vswitch2
/usr/sbin/esxcfg-vswitch --add-pg-uplink vmnic1 vSwitch2 --pg="Prod_v100" --vlan=100
/usr/sbin/esxcfg-vswitch --add-pg-uplink vmnic4 vSwitch2 --pg="Prod_v100" --vlan=100
/usr/sbin/esxcfg-vswitch --add-pg="Prod_v21" vswitch2
/usr/sbin/esxcfg-vswitch --add-pg-uplink vmnic1 vSwitch2 --pg="Prod_v21" --vlan=21
/usr/sbin/esxcfg-vswitch --add-pg-uplink vmnic4 vSwitch2 --pg="Prod_v21" --vlan=21
/usr/sbin/esxcfg-vswitch --add-pg="VMInternal_v4094" vswitch2
/usr/sbin/esxcfg-vswitch --add-pg-uplink vmnic1 vSwitch2 --pg="VMInternal_v4094" --vlan=4094
/usr/sbin/esxcfg-vswitch --add-pg-uplink vmnic4 vSwitch2 --pg="VMInternal_v4094" --vlan=4094
/usr/sbin/esxcfg-vswitch --link=vmnic0 vSwitch0
/usr/sbin/esxcfg-vswitch --link=vmnic2 vSwitch0
/usr/sbin/esxcfg-vswitch --link=vmnic3 vSwitch1
/usr/sbin/esxcfg-vswitch --link=vmnic7 vSwitch1
/usr/sbin/esxcfg-vswitch --link=vmnic1 vSwitch2
/usr/sbin/esxcfg-vswitch --link=vmnic4 vSwitch2
perl -p -i -e 's/teamPolicy\/maxActive = "."/teamPolicy\/maxActive = "2"/g' /etc/vmware/esx.conf
Create a local user for SSH Access
useradd -p 'removed' -c "New Account Created By Kickstart" ctemp
EOF1
Make esxcfg.sh eXecutable
chmod +x /tmp/esxcfg.sh
Make esxcfg.sh run from rc.local and make rc.local reset itself
cat >> /etc/rc3.d/S30vmwarePostConfig <<EOF
cd /tmp
/tmp/esxcfg.sh
EOF
I tried with the replacing of the rc.local and this is the latest attempt. The S30vmwarepostconfig nor the /tmp/esxcfg.sh ever get created.
anyone?