Kickstart ESXi 4.1

No me apetece cambiar todos los < y >, así que se verá regular :P

#########################################
# ESXi 4.1 Kickstart configuration #
#########################################

# Accept User Agreement
accepteula

# Root password
rootpw –iscrypted PASSWORD

# Disk autopartition
# TIP: Maybe needs some tunning
autopart –firstdisk –overwritevmfs

# Installation files
install url http://URL/4.1/

# Network configuration (install)
network –bootproto=dhcp –device=vmnic0

# Post-configuration tasks
# TIP: It runs in level 998 because is the latest level without root password
# It allow to run high privileges commands without entering the root password
%firstboot –unsupported –interpreter=busybox –level=998

# Enable remote administation
vim-cmd hostsvc/enable_remote_tsm
vim-cmd hostsvc/start_remote_tsm

# Enable local administration
vim-cmd hostsvc/enable_local_tsm
vim-cmd hostsvc/start_local_tsm

# NOTE:
# Enabling administration, shows a warning in vCenter
# In 4.1, it disappears by restarting the hostd agent:
# http://www.vcritical.com/2011/02/get-rid-of-those-esxi-tech-support-mode-warnings/
# In 5, there is an advanced parameter to ignore this:
# http://www.yellow-bricks.com/2011/07/21/esxi-5-suppressing-the-localremote-shell-warning/
# So, uncomment the next line, in 5 ;)
# esxcfg-advopt -s 1 /UserVars/SuppressShellWarning

# Syslog stuff
vim-cmd hostsvc/advopt/update Syslog.Remote.Hostname string
vim-cmd hostsvc/advopt/update Syslog.Remote.Port int 514
# Don’t know if it’s the datastore path of the server, so, disabled
#vim-cmd hostsvc/advopt/update Syslog.Remote.DatastorePath string “[datastoreName] /logfiles/hostName.log”

# Rename the local datastore
vim-cmd hostsvc/datastore/rename datastore1 “$(hostname -s)-local-storage-1″

# Configure ntp
echo “server NTPSERVER” >> /etc/ntp.conf
chkconfig ntpd on

# Configure snmpd
cat > /tmp/snmpd.xml << __SNMP__

COMMUNITIES
true
163 TARGETS

__SNMP__
cp /tmp/snmp.conf /etc/vmware/snmp.xml

# Configure DNS
cat > /etc/resolv.conf << __DNS__
search DOMAIN
nameserver DNS1
nameserver DNS2
__DNS__

# Configure depth queue
# LPFC820 (G7)
if esxcfg-module -l|grep lpfc820 ; then
/usr/sbin/esxcfg-module -s “lpfc0_lun_queue_depth=64 lpfc1_lun_queue_depth=64 lpfc2_lun_queue_depth=64 lpfc3_lun_queue_depth=64 lpfc4_lun_queue_depth=64 lpfc5_lun_queue_depth=64″ lpfc820
fi
# Qlogic
if esxcfg-module -l|grep ql2 ; then
/usr/sbin/esxcfg-module -s “ql2xmaxqdepth=64″ qla2xxx
fi
# LPFC740
if esxcfg-module -l|grep lpfc_740 ; then
/usr/sbin/esxcfg-module -s “lpfc0_lun_queue_depth=64 lpfc1_lun_queue_depth=64 lpfc2_lun_queue_depth=64 lpfc3_lun_queue_depth=64 lpfc4_lun_queue_depth=64 lpfc5_lun_queue_depth=64″ lpfc_740
fi

# Depth Queue
vim-cmd hostsvc/advopt/update Disk.SchedNumReqOutstanding long 64

# Lun Reset
/usr/sbin/esxcfg-advcfg -s 1 /Disk/UseLunReset
/usr/sbin/esxcfg-advcfg -s 0 /Disk/UseDeviceReset

#####################
# Check this in 4.1
#/usr/bin/vimsh -n -e “hostsvc/advopt/update Misc.RunningVCpuLimit int 192″
#sed -i -e ‘s!^!\t450\n\t400\n!g’ $CONFIG
#/usr/sbin/esxcfg-boot -b
#####################

# Create vSwitches
/usr/sbin/esxcfg-vswitch -L vmnic0 vSwitch0
/usr/sbin/esxcfg-vswitch -L vmnic1 vSwitch1
/usr/sbin/esxcfg-vswitch -L vmnic2 vSwitch2
/usr/sbin/esxcfg-vswitch -L vmnic3 vSwitch3
/usr/sbin/esxcfg-vswitch -L vmnic4 vSwitch4
/usr/sbin/esxcfg-vswitch -L vmnic5 vSwitch5
/usr/sbin/esxcfg-vswitch -L vmnic6 vSwitch6

# Interactive network configuration
chvt 1
exec < /dev/tty1 > /dev/tty1
clear

# Check if the hostname ends in
DOMAIN=”.”
nombre_host=”"

echo $nombre_host | grep -q $DOMAIN
RETVAL=$?

echo “”
while [ $RETVAL -ne 0 ]
do
read -p “Introduzca el nombre de host con FQDN: ” nombre_host
echo $nombre_host | grep -q $DOMAIN
RETVAL=$?
done

# Function to check if the IP is valid
valid_dotted_quad()
{
ERROR=0
oldIFS=$IFS
IFS=.
set -f
set — $1
if [ $# -eq 4 ]
then
for seg
do
case $seg in
“”|*[!0-9]*) ERROR=1;break ;; ## Segment empty or non-numeric char
*) [ $seg -gt 255 ] && ERROR=2 ;;
esac
done
else
ERROR=3 ## Not 4 segments
fi
IFS=$oldIFS
set +f
return $ERROR
}
# END

direccion_ip=”"

valid_dotted_quad $direccion_ip
RETVAL=$?

while [ $RETVAL -ne 0 ]
do
read -p “Introduzca la IP: ” direccion_ip
valid_dotted_quad $direccion_ip
RETVAL=$?
done

direccion_gateway=”"

valid_dotted_quad $direccion_gateway
RETVAL=$?

while [ $RETVAL -ne 0 ]
do
read -p “Introduzca el gateway: ” direccion_gateway
valid_dotted_quad $direccion_gateway
RETVAL=$?
done

unset sw

chvt 1
exec < /dev/tty1 > /dev/tty1

# Set IP, hostname, gateway with the interactive parameters
esxcfg-vmknic -i $direccion_ip -n 255.255.255.0 “Management Network”
esxcfg-advcfg -s $nombre_host /Misc/HostName
esxcfg-route -a default $direccion_gateway

# Configure /etc/hosts
echo “$direccion_ip $nombre_host $nombre_host” >> /etc/hosts

# Configure hostsvc to allow vmotion
# TIP: Don’t know if doesn’t needed anymore
cat << EOF > /etc/vmware/hostd/hostsvc.xml

normal

Vmotion

EOF

/usr/sbin/esxcfg-advcfg -s 1 /Migrate/Enabled

# 800 Mb Service Console
# TIP: Don’t needed in ESXi?
#sed -i -e ‘s/\/boot\/memSize\ =\ “[0-9][0-9][0-9]“/\/boot\/memSize\ =\ “800″/1′ /etc/vmware/esx.conf
#esxcfg-boot -g
#esxcfg-boot -b
#sed -i -e ‘s/^.*uppermem.*/uppermem 819200/g’ -e ‘s/mem=.*M/mem=800M/g’ /boot/grub/grub.conf

# VMimages and some other network file shares stuff
#mkdir -p /vmimages/isos

#echo “:/isos /vmimages/isos nfs soft,timeo=20,rsize=8192,wsize=8192 0 0″ >> /etc/fstab

# MOTD
MOTD=”Esta maquina es propiedad de PEPITO y cualquier uso debe estar autorizado por el departamento correspondiente. Cualquier otro uso sera perseguido y castigado de acuerdo a la legislacion vigente. Cualquier actividad realizada en, desde o hacia este sistema esta sujeta a monitorizacion sin previo aviso.”
echo $MOTD > /etc/motd
chmod 644 /etc/motd

# Enhace the prompt to show hostname in red
echo “export PS1=\”[\u@\e[31;1m\h\e[0m:\w]\\\\\$ \”" >> /etc/profile

# Some cron stuff
# TIP: Test it!
# http://www.jules.fm/Logbook/files/add_cron_job_vmware.html

cat << EOF >/tmp/crontab.root
# Run “X” script
30 5 3 * * /root/X
EOF

# Add cron stuff to crontab
crontab /tmp/crontab.root
rm /tmp/crontab.root

# Reboot/shutdown confirmation
# It doesn’t work, find some other solution
#cat << EOF >/usr/local/bin/confirm
##!/bin/bash
#prompt()
#{
# while true
# do
# echo -n “\$* s/n? ”
# read reply
# if [ "\$reply" = s -o "\$reply" = S ]
# then
# return 0
# elif [ "\$reply" = n -o "\$reply" = N ]
# then
# echo “Accion cancelada”
# exit 1
# else
# echo “Por favor, introduce ‘s’ o ‘n’”
# fi
# done
#}
#
#echo “Se va a realizar \$1″
#if prompt “Esta seguro de continuar”
#then
# prompt “Confirmelo por favor”
# \$@
#fi
#EOF
#
#chmod 755 /usr/local/bin/confirm
#
#echo “alias reboot=\”/usr/local/bin/confirm reboot\”" >> /etc/bashrc
#echo “alias shutdown=\”/usr/local/bin/confirm shutdown\”" >> /etc/bashrc
#echo “alias init=\”/usr/local/bin/confirm init\”" >> /etc/bashrc
#echo “alias halt=\”/usr/local/bin/confirm halt\”" >> /etc/bashrc

# Shell timeout after 5 min. inactivity
esxcfg-advcfg -s 300 /UserVars/TSMTimeOut

# Remove unused Port Groups
esxcfg-vswitch -D “VM Network” vSwitch0
esxcfg-vswitch -D “Service Console” vSwitch0

echo “ssh stream tcp nowait root /sbin/dropbearmulti dropbear ++min=0,swap,group=shell -i -K60″ >> /etc/inetd.conf
echo “ssh stream tcp6 nowait root /sbin/dropbearmulti dropbear ++min=0,swap,group=shell -i -K60″ >> /etc/inetd.conf

# Reboot
reboot

Post to Twitter Post to Facebook Send Gmail Post to LinkedIn

No Comments »

minWi on diciembre 1st 2011 in sysadmin, VMware

Trackback URI | Comments RSS

Leave a Reply

  • RSS
  • Facebook
  • Google+
  • LinkedIn
  • Twitter
  • Picasa
  • Flickr
  • YouTube