WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud Foundation
  • VKS
  • Homelab
    • Resources
    • Nested Virtualization
  • VMware Nostalgia
  • Apple
You are here: Home / Automation / ESXi 5.5 Kickstart script for setting up VSAN

ESXi 5.5 Kickstart script for setting up VSAN

07.21.2014 by William Lam // 12 Comments

In my lab, when I need to provision a new or rebuild an existing ESXi host, I still prefer to use the true and tried method of an unattended/scripted installation also known as Kickstart. Below is a handy ESXi 5.5 Kickstart that I have been using to setup a basic VSAN environment. I figure this might come in handy for anyone looking to automate their ESXi 5.5 deployment and include some of the VSAN configurations like creating a VSAN Disk Group or enabling VSAN Traffic type on a particular VMkernel interface. For more details about this Kickstart, refer to the bottom of the file where I break down the file in more detail.

# Sample kickstart for ESXi 5.5 configuring VSAN Disk Groups
# William Lam
# www.virtuallyghetto.com
#########################################

accepteula
install --firstdisk --overwritevmfs
rootpw vmware123
reboot

%include /tmp/networkconfig
%pre --interpreter=busybox

# extract network info from bootup
VMK_INT="vmk0"
VMK_LINE=$(localcli network ip interface ipv4 get | grep "${VMK_INT}")
IPADDR=$(echo "${VMK_LINE}" | awk '{print $2}')
NETMASK=$(echo "${VMK_LINE}" | awk '{print $3}')
GATEWAY=$(esxcfg-route | awk '{print $5}')
DNS="172.30.0.100"
HOSTNAME=$(nslookup "${IPADDR}" "${DNS}" | grep Address | grep "${IPADDR}" | awk '{print $4}')

echo "network --bootproto=static --addvmportgroup=true --device=vmnic0 --ip=${IPADDR} --netmask=${NETMASK} --gateway=${GATEWAY} --nameserver=${DNS} --hostname=${HOSTNAME}" > /tmp/networkconfig

%firstboot --interpreter=busybox

vsan_syslog_key = "VSAN-KS"

logger $vsan_syslog_key " Enabling & Starting SSH"
vim-cmd hostsvc/enable_ssh
vim-cmd hostsvc/start_ssh

logger $vsan_syslog_key " Enabling & Starting ESXi Shell"
vim-cmd hostsvc/enable_esx_shell
vim-cmd hostsvc/start_esx_shell

logger $vsan_syslog_key " Suppressing ESXi Shell Warning"
esxcli system settings advanced set -o /UserVars/SuppressShellWarning -i 1

logger $vsan_syslog_key " Reconfiguring VSAN Default Policy"
esxcli vsan policy setdefault -c vdisk -p "((\"hostFailuresToTolerate\" i1) (\"forceProvisioning\" i1))"
esxcli vsan policy setdefault -c vmnamespace -p "((\"hostFailuresToTolerate\" i1) (\"forceProvisioning\" i1))"

logger $vsan_syslog_key "Enabling VSAN Traffic on vmk0"
esxcli vsan network ipv4 add -i vmk0

# assign license
vim-cmd vimsvc/license --set AAAAA-BBBBB-CCCCC-DDDDD-EEEEE

%firstboot --interpreter=python

import commands, os, uuid, syslog

vsan_syslog_key = "VSAN-KS"
debug = False

# Build VSAN Disk Group command based on vdq -q output
def createVsanDiskGroup():
	vdqoutput = eval(commands.getoutput("/sbin/vdq -q"))
	md = []
	ssd = ''
	for i in vdqoutput:
		if i['State'] == 'Eligible for use by VSAN':
			if i['Reason'] == 'Non-local disk':
				syslog.syslog(vsan_syslog_key + " Setting enable_local and reclaiming " + i['Name'])
				if debug == False:
					os.system("esxcli storage nmp satp rule add -s VMW_SATP_LOCAL -o enable_local -d " + i['Name'])
					os.system("esxcli storage core claiming reclaim -d " + i['Name'])
			if i['IsSSD'] == '1':
				ssd = i['Name']
			else:
				md.append(i['Name'])

	diskgroup_cmd = 'esxcli vsan storage add -s ' + ssd + ' -d ' + ' -d '.join(md)
	syslog.syslog(vsan_syslog_key + " Creating VSAN Disk Group using SSD: " + ssd +  " MD: " + ', '.join(md))
	if debug == False:
		os.system(diskgroup_cmd)

# Create VSAN Cluster (required only for first ESXi node)
def createVsanCluster():
	# generate UUID for VSAN Cluster
	vsan_uuid = str(uuid.uuid4())

	syslog.syslog(vsan_syslog_key + " Creating VSAN Cluster using UUID: " + vsan_uuid)
	if debug == False:
		os.system("esxcli vsan cluster join -u " + vsan_uuid)

createVsanDiskGroup()
createVsanCluster()

If you would like to see more details on creating ESXi Kickstart, make sure to check out my ESXi 4.x & 5.x examples here.

Line 6-9 This is generic Kickstart configurations specifying EULA, how to install, password, etc. You can refer to VMware's scripted install documentation.

Line 11-25 This extracts the DHCP IP Address (static allocation) and re-creates the network configuration in Line 25 for statically assigning the IP Address to the ESXi host

Line 27 This starts the firstboot script and assumes "Busybox" as the interpreter which means basic shell commands

Line 30 I create a custom key which will be logged in syslog for our installation

Line 32-41 Basic ESXi configurations leveraging vim-cmd and ESXCLI

Line 43-45 Configure the VSAN default storage policy, please refer to this article for more details.

Line 47-38 Configure the VSAN Traffic type on vmk0

Line 35 This starts a second firstboot script, but now using "Python"

Line 50-51 Assign a license to ESXi host

Line 53 Importing the appropriate libraries that will be used in the Python script

Line 58 Using the same custom key that I created earlier for logging to syslog

Line 61-81 A method for creating VSAN Disk Group by inspecting vdq CLI and marking disks as local

Line 83-90 A method for creating VSAN Cluster, please refer to this article for more details.

Line 92-93 Invoking the two Python methods. You can either create a custom Kickstart for your "first" ESXi node if you decide to bootstrap your VSAN Cluster onto a single ESXi host. You can also use custom boot options to specify whether the ESXi host being provisioned is the first or additional nodes. This topic is a bit advanced, but if you are interested, take a look at this article here.

More from my site

  • How to create custom ESXi boot menu to support multiple Kickstart files?
  • A killer custom Apple Mac Mini setup running VSAN
  • Does VSAN work with Free ESXi?
  • Does reinstalling ESXi with an existing VSAN Datastore wipe your data?
  • Quick Tip - Steps to shutdown/startup VSAN Cluster w/vCenter running on VSAN Datastore

Categories // Automation, ESXCLI, ESXi, VSAN, vSphere, vSphere 5.5 Tags // ESXi 5.5, kickstart, ks.cfg, VSAN, vSphere 5.5

Comments

  1. *protectedwojan says

    01/14/2015 at 12:29 pm

    William,
    Most valueable blog post as all you share on the Web. And the quality is one of the best!
    BTW, can you tell me which tool are you using to insert into your blog the above kickstart file text with all the nice fetures it brings (copy/line numlbers toggle, new window etc...)?
    Thanks

    Reply
    • William Lam says

      01/14/2015 at 4:35 pm

      Thanks for the kinds words!

      I'm using Crayon Syntax Highlighter WP plugin

      Reply
      • *protectedsunil patil says

        04/09/2016 at 1:19 pm

        Hi William, hope you are good, so nice scripting on Virtualization tech, hope you are very familiar about how to perform scripting installation over more than 100 ESXI hosts, please let me know if so, many thanks! in advance

        Reply
  2. *protectedTiran Efrat says

    05/09/2016 at 1:38 pm

    Hi William,
    will this ks work for vsan 6.2?
    thx.

    Reply
    • William Lam says

      05/13/2016 at 9:49 am

      Yes, there maybe couple of changes required depending if you're doing an all-flash but core of the KS is still applicable

      Reply
  3. *protectedBee Kay says

    09/07/2016 at 4:01 pm

    And for the newbie - how does one identify 1) if they even have VSAN available to them? and 2) What version is running/available?

    Reply
  4. *protectedpzi123 says

    11/04/2016 at 12:49 pm

    Judging from your diligence and devotion to automation a strange silence on the ESXi 6 is suspicious 🙂

    Have you had any luck with kickstarting ESXi 6?

    I see a general failure of ESXi 6 kickstart with infamous "No NIC found with MAC address ..." reported widely with no responses from VMware gurus.

    see: https://communities.vmware.com/thread/545001?start=0&tstart=0

    Reply
    • William Lam says

      11/04/2016 at 1:45 pm

      There's no changes from a Kickstart standpoint between 5.5/6.0, so its not needed. Also, I don't have infinite amount of time to cover every single topic 🙂 Kickstart for 6.x works and haven't had any issues and this is true for 6.5 as well

      Reply
  5. *protectedpzi123 says

    11/04/2016 at 8:39 pm

    This is all I wanted to hear - I assume you have no issues kickstarting nested ESXi 6u2 with basic E1000E Ethernet interface. I and others tried that and other common hardware combinations of Ethernet with the same result. Can somebody in this blog confirm that they succeeded in nested or other ESXi kickstart in vSphere 6u2.

    Reply
  6. *protectedLogan says

    02/03/2019 at 9:15 am

    William, I'm curious if you have an updated script for VSAN 6.6 or higher on ESXi 6.5 or higher?

    Reply
    • William Lam says

      02/03/2019 at 9:44 am

      There’s no changes to how KS works in newer releases 🙂

      Reply
      • *protectedLogan Spencer says

        02/03/2019 at 11:28 am

        Apologies... I wasn't referring to the KS portion, but rather the VSAN portion at the very bottom (line 61 and onward). As this article was written in 2014, and references earlier versions, I'm wondering if you have updated it to reflect the new (6.6+) commands, as referenced within this post: https://www.williamlam.com/2013/09/how-to-bootstrap-vcenter-server-onto_9.html

        I've got my ESXi and Windows DNS/AD bootstrap working flawlessly, but the only break I have yet to solve is the ability to have my windows VM programatically deploy the VCSA via the JSON config file AND do so on top of a VSAN datastore. Any help would be appreciated! If you'd prefer email, I can be reached at *protected email*

        Thank you in advance!

        Reply

Thanks for the comment!Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Search

Thank Author

Author

William is Distinguished Platform Engineering Architect in the VMware Cloud Foundation (VCF) Division at Broadcom. His primary focus is helping customers and partners build, run and operate a modern Private Cloud using the VMware Cloud Foundation (VCF) platform.

Connect

  • Bluesky
  • Email
  • GitHub
  • LinkedIn
  • Mastodon
  • Reddit
  • RSS
  • Twitter
  • Vimeo

Recent

  • Programmatically accessing the Broadcom Compatibility Guide (BCG) 05/06/2025
  • Quick Tip - Validating Broadcom Download Token  05/01/2025
  • Supported chipsets for the USB Network Native Driver for ESXi Fling 04/23/2025
  • vCenter Identity Federation with Authelia 04/16/2025
  • vCenter Server Identity Federation with Kanidm 04/10/2025

Advertisment

Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy

Copyright WilliamLam.com © 2025