How To: Sample kickstart file for VMware ESXi 4.1

Posted: September 11, 2010 in How-to, VMware

This is a sample kickstart file for VMware ESXi 4.1 installations.

PXE environment is setup under CentOS 5.5-x86_64, with restricted dhcpd (i.e. no free leases), tftp-server and httpd (for hosting installation and some configuration files). Instructions for setting up PXE environment for VMware ESXi 4.1 can be founded here. Here, the typical VMware scripted installation processe has slightly been modified to automatically install multiple hosts simultaneously without any user interaction. The host needs to be *manually* PXE boot. Then it will install OS according to the ks.cfg file and reboot. After the reboot the %firstboot section will execute. During the %firstboot execution, it will look for file, post_install.cfg which includes all the post installation configurations. post_install.cfg requires a file called arp_table to grab the correct IPv4 addresses and hostname(based on vmnic0 MAC address). After executing all post configurations, the host will enter into the maintenance mode and reboots.

According to this setup, all files, ks.cfg, post_install.cfg and arp_table, should be placed under http://<pxe_server>/kickstart directory.

Note: At the time of this writing, in VMware ESXi 4.1 scripted installation, %post section changes are only applied to the pre-boot environment. i.e. the changes you made in %post section will be lost after the first reboot. So %firstboot section is used to make the post installation changes.

ks file

vmaccepteula
autopart –firstdisk=local –overwritevmfs
install url http://<pxe_server>/install
network –bootproto=dhcp –device=vmnic0 –addvmportgroup=1
rootpw –iscrypted <encrypted_root_password>

# Reboot after the installation
reboot

%firstboot –unsupported –interpreter=busybox

cd /tmp
wget http://<pxe_server>/kickstart/arp_table
wget http://<pxe_server>/kickstart/post_install.cfg
chmod +x post_install.cfg
ash post_install.cfg

# Reboot after the post configuration
reboot

post_install.cfg

################### Start: Date & Time

# NTP
cat >> /etc/ntp.conf << EOF
server <ntp_server>
EOF

chkconfig ntpd on

#################### End: Date & Time

#################### Start: Networking

# Searching vmnic0 MAC address
VMNIC0_MAC=`vim-cmd hostsvc/net/pnic_info vmnic0|grep mac| awk {‘print $NF’}|sed -e ‘s/[“,]//g’`
# Searching the correct hostname
HOSTNAME=`grep $VMNIC0_MAC arp_table | awk -F “;” {‘print $3’}`
# Searching the correct IP address
IPADDR=`grep $VMNIC0_MAC arp_table | awk -F “;” {‘print $2’}`
# Setting the hostname and DNS
vim-cmd hostsvc/net/dns_set –hostname=$HOSTNAME –domainname=<domain> –ip-addresses=<ns1>,<ns2> –searchdomain=<search_domain>
# Setting up IP address for vmkernel
esxcfg-vmknic –ip $IPADDR –netmask 255.255.255.0 “Management Network”
# Setting default route
esxcfg-route <default_route>

# Refresh network information
vim-cmd  hostsvc/net/refresh

# Enable vMotion on vmk0
vim-cmd hostsvc/vmotion/vnic_set vmk0

# Set NIC to auto
NICs=`esxcfg-nics -l|grep vmnic|awk {‘print $1’}`
for i in $NICs; do esxcfg-nics -a $i; done;

# Refresh network information
vim-cmd  hostsvc/net/refresh

# Add vmnic to vSwitch0
esxcfg-vswitch -L vmnic1 vSwitch0
esxcfg-vswitch -L vmnic2 vSwitch0

# Add port groups vSwitch0
esxcfg-vswitch -A “Virtual Machine Network” vSwitch0
esxcfg-vswitch -A “VM Network 10” vSwitch0
esxcfg-vswitch -A “VM Network 64” vSwitch0
esxcfg-vswitch -A “VM Network 65” vSwitch0

# Add VLAN ID to port groups
esxcfg-vswitch -p “Virtual Machine Network” -v 10 vSwitch0
esxcfg-vswitch -p “VM Network” -v 10 vSwitch0
esxcfg-vswitch -p “VM Network 10” -v 10 vSwitch0
esxcfg-vswitch -p “VM Network 64” -v 64 vSwitch0
esxcfg-vswitch -p “VM Network 65” -v 65 vSwitch0

# Refresh network information
vim-cmd  hostsvc/net/refresh

#################### End: Networking

#################### Start: Storage

# Change local disk label
vim-cmd hostsvc/datastore/rename datastore1 local_$(hostname -s)

# Rescan HBAs
HBAs=`esxcfg-info | grep vmkernel -i | grep hba | awk -F. {‘print $29’}`
for i in $HBAs; do esxcfg-rescan $i; done;

# Some advanced configurations
esxcfg-advcfg -s 0 /Disk/UseDeviceReset
esxcfg-advcfg -s 1 /Disk/UseLunReset

# Set RR as default PSP for VMW_SATP_ALUA
esxcli nmp satp setdefaultpsp –satp VMW_SATP_ALUA –psp VMW_PSP_RR
# Find HP LUNs
HP_DEVICEs=`esxcli nmp device list | grep ‘HP Fibre Channel Disk’| awk  {‘print $NF’}| sed -e ‘s/[()]//g’`
# Set RR multipath policy
for i in $HP_DEVICEs; do esxcli nmp device setpolicy -d $i -P VMW_PSP_RR; done;
# Set IOPS to 1
for i in $HP_DEVICEs; do esxcli nmp roundrobin setconfig –type “iops” –iops=1 –device $i; done;

#################### End: Storage

# Enter maintenance mode
vim-cmd hostsvc/maintenance_mode_enter
sleep 30

arp_table

<MAC_address_1>;<ip_address_1>;<hostname_1>
<MAC_address_2>;<ip_address_2>;<hostname_2>

Advertisements
Comments
  1. […] ZenHat : How To: Sample kickstart file for VMware ESXi 4.1 […]

  2. […] # for Windows TS see http://kb.vmware.com/kb/1318 for details # found the orginal idea for this at http://zenhat.org/2010/09/11/how-to-sample-kickstart-file-for-vmware-esxi-4-1/ cat >> /etc/ntp.conf << EOF server $MyNTPServerOne server $MyNTPServerTwo EOF chkconfig […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s