How to kick-start scripts to automate VMware's ESXi installation via USB

Rolling out hundreds of VMware's ESXi hypervisors is a time-consuming project with the chance for errors. Learn how to use a USB flash drive to automate the ESXi install.

istock-816062320.jpg

Image: Wavebreakmedia, Getty Images/iStockphoto

VMware is arguably the standard when it comes to virtualizing infrastructure, despite growing support for other virtualization models such as Docker, Amazon's AWS, and Microsoft's Azure. But the focus of this article isn't market share or what's the best solution for your organization--it's to share a simple, effective way to automate the installation of the ESXi hypervisor onto bare metal hardware in order to facilitate the virtual deployment of servers with as light a touch as possible on the part of the technicians/admins. One method that provides a self-contained and fully scripted process that is easy to replicate is via USB flash drive (UFD).

Learn how to create a UFD that will install ESXi, apply basic network settings, and configure the host for remote management. Before we dive in, there are requirements necessary to make this work with little to no error.

SEE: Server virtualization: Best (and worst) practices (free PDF) (TechRepublic)

Requirements

  • VMware vSphere Hypervisor (ESXi ISO) image (Latest supported version for your hardware)
  • UNetbootin (Mac/Linux/Windows)
  • 4 GB USB flash drive (or larger)

How to create the bootable USB installer

  1. Insert your USB flash drive into an available port on your computer.
  2. Open UNetbootin and select the Diskimage radio button, then click the "…" button to navigate to the location where the VMware ESXi ISO is located.
  3. The USB drive should be identified automatically next to the Drive: section. Click the OK button to proceed, creating the installer and making the drive bootable.
  4. Once it's created, close UNetbootin, but leave the installer drive plugged in.

How to configure the boot.cfg file for unattended installation

Open the newly created USB installer drive and locate the boot.cfg file. Open the file in the text editor of your choice and locate the following line:

kernelopt=

Append the following text to it after the "=" sign to instruct the installer to look for the kickstart file, or the answer file that it should use for unattended installation:

ks=usb:/KS.CFG

How to configure the kickstart (KS) answer file

  1. From the text editor, close the boot.cfg file and open a new, blank page.
  2. Copy and paste the following script into the text editor:

# Base kickstart script install

vmaccepteula

clearpart --firstdisk --overwritevmfs

install --firstdisk --overwritevmfs

network --bootproto=static --ip= XXX.XXX.XXX.XXX --netmask= XXX.XXX.XXX.XXX --gateway=XXX.XXX.XXX.XXX--hostname=HOSTNAME --nameserver= XXX.XXX.XXX.XXX --addvmportgroup=1

rootpw PASSWORD

reboot

%firstboot --interpreter=busybox

# DNS settings

esxcli system hostname set --fqdn=HOSTNAME.DOMAIN.EXT

esxcli network ip dns search add --domain=DOMAIN.EXT

esxcli network ip dns server add --server= XXX.XXX.XXX.XXX

esxcli network ip dns server add --server= XXX.XXX.XXX.XXX

# enable & start SSH

vim-cmd hostsvc/enable_ssh

vim-cmd hostsvc/start_ssh 

# enable & start ESXi Shell

vim-cmd hostsvc/enable_esx_shell

vim-cmd hostsvc/start_esx_shell

# Suppress ESXi Shell warning

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

# SNTP configuration

cat > /etc/ntp.conf << __NTP_CONFIG__

restrict default kod nomodify notrap noquerynopeer

restrict 127.0.0.1 

server 0.fr.pool.ntp.org

server 1.fr.pool.ntp.org 

__NTP_CONFIG__ 

/sbin/chkconfig ntpd on

The script is merely a template that will need to be edited in order for it to work for your organization's environment. Specifically, the entries that are CAPITALIZED or contain XXX.XXX.XXX.XXX, should be modified to reflect the hostname, domain, and network settings information that will be unique to that ESXi server.

After that information is entered, save the file as KS.CFG, and place the file at the root of the USB installer drive. Safely eject the drive, and your USB-based installer is ready to deploy ESXi hypervisors unattended.

Important changes made by the script

Besides the aforementioned network and hostname configuration, the script auto accepts the VMware EULA and identifies the first storage disk(s) on the server and formats them before installing the ESXi system files on them. The script sets the root account password, as well as setting the SSH and ESXi Shell services to be enabled for remote management. Lastly, the script configures SNTP so that the time/date is set correctly and enables the NTP service.

Also see