ESXi 5.0 Scripted Install


Here is a nice ESXi 5 install script I use in my own environment; it does most of the job for you. If you want to install ESX host with PXE boot please use a very good guide from Ivo Beerens.

So what does this script do?

  • Install ESXi 5.0 hypervisor
  • Enable and start SSH and ESXi shell
  • Open ports in firewall for vCenter Update Manager, NTP Client and Software iSCSI Client
  • Configures NTP settings
  • Creates and configures Management vSwitch with two nics
  • Creates and configures vMotion vSwitch with two nics
  • Creates and configures iSCSI vSwitch with two nics
  • Enables iSCSI Software Adapter
  • Bonds each VMkernel NICs to the Software iSCSI Adapter
  • Sets CHAP authentication
  • Adds SAN to Dynamic Discovery on iSCSI Software Adapter
  • Enables and sets the default native VMware multipathing driver (Round Robin) for all iSCSI volumes
  • Creates and configures Virtual Machine vSwitch with two nics
  • Add a couple of Virtual Machines Portgroups with different VLANS
  • Renames the local DataStore

Please modify the script after your host configuration but it’s a good template that does most of the job for you.

############# Host Installation #############

# Accept the VMware End User License Agreement

vmaccepteula

# Set the root password

rootpw FreworMate01

# Install on the first local available disk

install –firstdisk –overwritevmfs

# Set the network configuration on the first network adapter

network –bootproto=static –ip=10.150.1.10 –gateway=10.150.1.1 –nameserver=10.150.1.23,10.150.1.22 –netmask=255.255.255.0 –hostname=cen-sv-esx-01.domain.com –device=vmnic0 –addvmportgroup=0

# Reboots the host after the scripted installation is completed

reboot

# Runs second part of the installation after the reboot

%firstboot –interpreter=busybox

################################### Host Configuration ##################################

# Enter maintenance mode

vim-cmd hostsvc/maintenance_mode_enter

# Set DNS names

esxcli system hostname set –fqdn=cen-sv-esx-01.domain.com

esxcli network ip dns search add –domain=domain.com

# Set DNS server addresses

esxcli network ip dns server add –server=10.150.1.23

esxcli network ip dns server add –server=10.150.1.22

# Enable and start SSH and ESXi shell

vim-cmd hostsvc/enable_ssh

vim-cmd hostsvc/start_ssh

vim-cmd hostsvc/enable_esx_shell

vim-cmd hostsvc/start_esx_shell

# Enable vCenter Update Manager, NTP Client and Software iSCSI Client in the firewall

esxcli network firewall ruleset set –ruleset-id=”updateManager” –enabled yes

esxcli network firewall ruleset set –ruleset-id=”iSCSI” –enabled yes

esxcli network firewall ruleset set –ruleset-id=”ntpClient” –enabled yes

# Suppress ESXi Shell shell warning

esxcli system settings advanced set -o /UserVars/SuppressShellWarning -i 1

# Configure NTP settings (Takes in effect after a reboot)

echo restrict default kod nomodify notrap noquerynopeer > /etc/ntp.conf

echo restrict 127.0.0.1 >> /etc/ntp.conf

echo server se.pool.ntp.org>> /etc/ntp.conf

echo server europe.pool.ntp.org >> /etc/ntp.conf

echo driftfile /etc/ntp.drift >> /etc/ntp.conf

/sbin/chkconfig ntpd on

sleep 10

############################# Management Network Configuration ###########################

# Add nic to Management vSwitch

esxcli network vswitch standard uplink add –uplink-name=vmnic4 –vswitch-name=vSwitch0

# Set (vmnic0 and vmnic4) as active on Management vSwitch

esxcli network vswitch standard policy failover set -a=vmnic0,vmnic4 -v=vSwitch0

# Set failback policy to no on Management vSwitch

esxcli network vswitch standard policy failover set -b=no -v=vSwitch0

# Set failback policy to no on Management Network portgroup

esxcli network vswitch standard portgroup policy failover set –failback no –portgroup-name=”Management Network”

# Set NIC failover order for Management Portgroup

vim-cmd hostsvc/net/portgroup_set –nicorderpolicy-active=vmnic0 –nicorderpolicy-standby=vmnic4 vSwitch0 “Management Network”

sleep 10

############################# vMotion Network Configuration #############################

# Add new vMotion vSwitch

esxcli network vswitch standard add –vswitch-name=vSwitch1-vMotion

# Add nics to vMotion vSwitch

esxcli network vswitch standard uplink add –uplink-name=vmnic1 –vswitch-name=vSwitch1-vMotion

esxcli network vswitch standard uplink add –uplink-name=vmnic9 –vswitch-name=vSwitch1-vMotion

# Set (vmnic1 and vmnic9) as active vMotion vSwitch

esxcli network vswitch standard policy failover set -a=vmnic1,vmnic9 -v=vSwitch1-vMotion

# Set failback policy to no on vMotion vSwitch

esxcli network vswitch standard policy failover set -b=no -v=vSwitch1-vMotion

# Add vMotion Portgroups to vMotion vSwitch, assign it VLAN ID 3000 and set IP addresses

esxcli network vswitch standard portgroup add –portgroup-name=vMotion-1 –vswitch-name=vSwitch1-vMotion

esxcli network vswitch standard portgroup set –portgroup-name=vMotion-1 –vlan-id=3000

esxcli network ip interface add –interface-name=vmk1 –portgroup-name=vMotion-1

esxcli network ip interface ipv4 set –interface-name=vmk1 –ipv4=10.150.255.10 –netmask=255.255.255.0 –type=static

esxcli network vswitch standard portgroup add –portgroup-name=vMotion-2 –vswitch-name=vSwitch1-vMotion

esxcli network vswitch standard portgroup set –portgroup-name=vMotion-2 –vlan-id=3000

esxcli network ip interface add –interface-name=vmk2 –portgroup-name=vMotion-2

esxcli network ip interface ipv4 set –interface-name=vmk2 –ipv4=10.150.255.11 –netmask=255.255.255.0 –type=static

# Set NIC failover order for vMotion Portgroups

vim-cmd hostsvc/net/portgroup_set –nicorderpolicy-active=vmnic1 –nicorderpolicy-standby=vmnic9 vSwitch1-vMotion “vMotion-1”

vim-cmd hostsvc/net/portgroup_set –nicorderpolicy-active=vmnic9 –nicorderpolicy-standby=vmnic1 vSwitch1-vMotion “vMotion-2”

# Set MTU to 9000 for jumbo frames vMotion vSwitch

esxcli network vswitch standard set -m 9000 -v vSwitch1-vMotion

# Set MTU to 9000 for jumbo frames on vMotion portgroups

esxcli network ip interface set -m 9000 -i vmk1

esxcli network ip interface set -m 9000 -i vmk2

# Enable vMotion on vMotion Portgroups

vim-cmd hostsvc/vmotion/vnic_set vmk1

vim-cmd hostsvc/vmotion/vnic_set vmk2

sleep 10

############################## iSCSI Network Configuration ##############################

# Add new iSCSI vSwitch

esxcli network vswitch standard add –vswitch-name=vSwitch2-iSCSI

# Add nics to iSCSI vSwitch

esxcli network vswitch standard uplink add –uplink-name=vmnic5 –vswitch-name=vSwitch2-iSCSI

esxcli network vswitch standard uplink add –uplink-name=vmnic7 –vswitch-name=vSwitch2-iSCSI

# Set (vmnic5 and vmnic7) as active on iSCSI vSwitch

esxcli network vswitch standard policy failover set -a=vmnic5,vmnic7 -v=vSwitch2-iSCSI

# Set failback policy to no on iSCSI vSwitch

esxcli network vswitch standard policy failover set -b=no -v=vSwitch2-iSCSI

# Add iSCSI Portgroups to iSCSI vSwitch and set IP addresses

esxcli network vswitch standard portgroup add –portgroup-name=iSCSI-1 –vswitch-name=vSwitch2-iSCSI

esxcli network ip interface add –interface-name=vmk3 –portgroup-name=iSCSI-1

esxcli network ip interface ipv4 set –interface-name=vmk3 –ipv4=10.150.252.150 –netmask=255.255.255.0 –type=static

esxcli network vswitch standard portgroup add –portgroup-name=iSCSI-2 –vswitch-name=vSwitch2-iSCSI

esxcli network ip interface add –interface-name=vmk4 –portgroup-name=iSCSI-2

esxcli network ip interface ipv4 set –interface-name=vmk4 –ipv4=10.150.252.151 –netmask=255.255.255.0 –type=static

sleep10

# Set NIC failover order for iSCSI Portgroups

vim-cmd hostsvc/net/portgroup_set –nicorderpolicy-active=vmnic5 vSwitch2-iSCSI “iSCSI-1”

vim-cmd hostsvc/net/portgroup_set –nicorderpolicy-active=vmnic7 vSwitch2-iSCSI “iSCSI-2”

# Set MTU to 9000 for jumbo frames iSCSI vSwitch

esxcli network vswitch standard set -m 9000 -v vSwitch2-iSCSI

#esxcfg-vswitch -m 9000 vSwitch2-iSCSI (esxcfg commands are deprecated)

# Set MTU to 9000 for jumbo frames on iSCSI portgroups

esxcli network ip interface set -m 9000 -i vmk3

esxcli network ip interface set -m 9000 -i vmk4

# Enable Software iSCSI Adapter on the ESXi host

esxcli iscsi software set –enabled=true

sleep 10

# Bond each of the VMkernel NICs to the Software iSCSI Adapter (Adapter will be found automatically)

varvmhba=”$(esxcfg-scsidevs -a | grep iscsi | awk ‘{print $1}’)”

esxcli iscsi networkportal add -A $varvmhba -n vmk3

esxcli iscsi networkportal add -A $varvmhba -n vmk4

sleep 10

# Set CHAP authentication

esxcli iscsi adapter auth chap set –adapter=$varvmhba –authname=cen-sa-chap-01 –secret=4F3Um5p-z5g3Zqn6_ –level=required

# Add EqualLogic SAN to Dynamic Discovery on iSCSI Software Adapter

esxcli iscsi adapter discovery sendtarget add -A $varvmhba -a 10.150.252.100

sleep 10

# Enabling Round Robin VMware Native Multipathing as default

esxcli storage nmp satp set –default-psp=VMW_PSP_RR –satp=VMW_SATP_EQL

esxcli storage core claimrule load

esxcli storage core claimrule run

############################### VMs Network Configuration ###############################

# Add new Virtual Machines vSwitch

esxcli network vswitch standard add –vswitch-name=vSwitch3-VMs

# Add nics to Virtual Machines vSwitch

esxcli network vswitch standard uplink add –uplink-name=vmnic2 –vswitch-name=vSwitch3-VMs

esxcli network vswitch standard uplink add –uplink-name=vmnic6 –vswitch-name=vSwitch3-VMs

# Set (vmnic2 and vmnic6) as active Virtual Machines vSwitch

esxcli network vswitch standard policy failover set -a=vmnic2,vmnic6 -v=vSwitch3-VMs

# Set failback policy to no on Virtual Machines vSwitch

esxcli network vswitch standard policy failover set -b=no -v=vSwitch3-VMs

# Add Virtual Machines Portgroups to Virtual Machines vSwitch and assign VLANs

esxcli network vswitch standard portgroup add –portgroup-name=Production –vswitch-name=vSwitch3-VMs

esxcli network vswitch standard portgroup set –portgroup-name=Production –vlan-id=0

esxcli network vswitch standard portgroup add –portgroup-name=DMZ –vswitch-name=vSwitch3-VMs

esxcli network vswitch standard portgroup set –portgroup-name=DMZ –vlan-id=10

esxcli network vswitch standard portgroup add –portgroup-name=DMZ2 –vswitch-name=vSwitch3-VMs

esxcli network vswitch standard portgroup set –portgroup-name=DMZ2 –vlan-id=11

esxcli network vswitch standard portgroup add –portgroup-name=LAB1 –vswitch-name=vSwitch3-VMs

esxcli network vswitch standard portgroup set –portgroup-name=LAB1 –vlan-id=20

esxcli network vswitch standard portgroup add –portgroup-name=LAB2 –vswitch-name=vSwitch3-VMs

esxcli network vswitch standard portgroup set –portgroup-name=LAB2 –vlan-id=21

esxcli network vswitch standard portgroup add –portgroup-name=LAB3 –vswitch-name=vSwitch3-VMs

esxcli network vswitch standard portgroup set –portgroup-name=LAB3 –vlan-id=22

esxcli network vswitch standard portgroup add –portgroup-name=LAB4 –vswitch-name=vSwitch3-VMs

esxcli network vswitch standard portgroup set –portgroup-name=LAB4 –vlan-id=23

esxcli network vswitch standard portgroup add –portgroup-name=Staging –vswitch-name=vSwitch3-VMs

esxcli network vswitch standard portgroup set –portgroup-name=Staging –vlan-id=24

sleep 10

# Rename local datastore name

vim-cmd hostsvc/datastore/rename datastore1 “$(hostname -s)-vmfs5-vol1”

# Copy %first boot script logs and installation log to persisted datastore

cp /var/log/hostd.log “/vmfs/volumes/$(hostname -s)-vmfs5-vol1/firstboot-hostd.log”

cp /var/log/esxi_install.log “/vmfs/volumes/$(hostname -s)-vmfs5-vol1/firstboot-esxi_install.log”

# Reboots the host after the configuration is completed

sleep 30

reboot

Advertisements
This entry was posted in VMware and tagged , , , , , , , , , , , , , , , , , , , . Bookmark the permalink.

2 Responses to ESXi 5.0 Scripted Install

  1. Georgie says:

    Great. This is a big help for me! Thx

  2. Pingback: per script Konfigurationen setzten « Rprengel's Blog

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