Automated ESXi Installation - Inject Kickstart File to ESXi ISO

VMware ESXi Installation can be automated by leveraging kickstart configurations. The kickstart configuration is a simple script that tells the Installer how to Install and configure ESXi.

A Kickstart configuration is commonly used for PXE boot installations and copied from the network. Another installation option is to create a bootable flash drive and copy the kickstart file to that drive. In some cases, when your infrastructure does not support PXE and you can only mount ISO files using remote management, you might want to inject the kickstart file into the ESXi Installation ISO.

This article explains how to inject a Kickstart scripted installation configuration to an official VMware ESXi ISO.

Prerequisites

  • Linux system (or WSL) with root permissions and the genisoimage package.
  • ESXi Installer ISO (Download from vmware.com)
  • esxi_ks_injector scripts from my GitHub Repository
  • Kickstart Configuration File (Examples are provided with the esxi_ks_injector repo)

Inject Static Kickstart Configuration to ESXi ISO

The first option is very simple. You have a static Kickstart Configuration and ESXi ISO and just inject the configuration to the ISO.

If not already available, install git and genisoimage. The following commands are for Debian but the packages are available with all common Distros.

# apt install genisoimage git

Get esxi_ks_injector scripts, wich are part of my virten-scripts repository at GitHub.

# git clone https://github.com/fgrehl/virten-scripts.git

Change to the esxi_ks_injector directory.

# cd virten-scripts/bash/esxi_ks_injector/

Copy an ESXi ISO to the script directory. You can use any ESXi ISO you want. The directory should look like this:

Edit KS.CFG to fit your needs. The following example is a basic configuration including network settings, ssh/console and NTP. This will result in an ESXi host that can be directly added to a vCenter Server.

vmaccepteula
install --firstdisk --overwritevmfs --novmfsondisk

network --bootproto=static --ip=192.168.0.10 --netmask=255.255.255.0 --gateway=192.168.0.1 --hostname=esx1.virten.lab --nameserver=192.168.0.1
rootpw VMware1!
keyboard German

reboot

%firstboot --interpreter=busybox

# Enable SSH
vim-cmd hostsvc/enable_ssh
vim-cmd hostsvc/start_ssh

# Enable ESXi Shell
vim-cmd hostsvc/enable_esx_shell
vim-cmd hostsvc/start_esx_shell

# Suppress Shell warning
esxcli system settings advanced set -o /UserVars/SuppressShellWarning -i 1

# NTP
esxcli system ntp set -s de.pool.ntp.org
esxcli system ntp set -e 1

Run esxi_ks_iso.sh with the options -i (Installer ISO) and -k (Kickstart File). The script uses /dev/shm/ as the working directory. This is in-memory, so the build process is very fast. You can change the working directory with the -w or --working-dir option.

# ./esxi_ks_iso.sh -i VMware-VMvisor-Installer-7.0U2-17630552.x86_64.iso -k KS.CFG
ISO saved at /dev/shm/esxibuilder/esxi-ks.iso

That's it! Copy esxi-ks.iso from the host and mount it to your server to perform the automated installation.

Inject Template-Based Kickstart Configuration to ESXi ISO

The second option is suitable when you want to install multiple ESXi hosts. It uses a Kickstart Template and Parameters to create custom ISO files for each ESXi Host you want to install.

If not already available, install git and genisoimage. The following commands are for Debian but the packages are available with all common Distros.

# apt install genisoimage git

Get esxi_ks_injector scripts, wich are part of my virten-scripts repository at GitHub.

# git clone https://github.com/fgrehl/virten-scripts.git

Change to the esxi_ks_injector directory.

# cd virten-scripts/bash/esxi_ks_injector/

Copy an ESXi ISO to the script directory. You can use any ESXi ISO you want. The directory should look like this:

Now have a look at KS-TEMPLATE.CFG. This file is nearly identical to the static version (KS.CFG) but uses variables for options that are different on each ESXi host like IP addresses and hostnames. Feel free to edit the configuration to fit your needs.

vmaccepteula
install --firstdisk --overwritevmfs --novmfsondisk

network --bootproto=static --ip=KSIPADDRESS --netmask=KSNETMASK --gateway=KSGATEWAY --hostname=KSHOSTNAME --vlanid=KSVLAN --nameserver=KSNAMESERVER
rootpw VMware1!
keyboard German

reboot

%firstboot --interpreter=busybox

# Enable SSH
vim-cmd hostsvc/enable_ssh
vim-cmd hostsvc/start_ssh

# Enable ESXi Shell
vim-cmd hostsvc/enable_esx_shell
vim-cmd hostsvc/start_esx_shell

# Suppress Shell warning
esxcli system settings advanced set -o /UserVars/SuppressShellWarning -i 1

# NTP
esxcli system ntp set -s de.pool.ntp.org
esxcli system ntp set -e 1

Now run esxi_customks_iso.sh with the following options:

  • -i, --iso: Base ISO File
  • -k, --ks: Kickstart Configuration File
  • -w, --working-dir: Working directory (Optional)
  • -a, --ip-address: ESXi IP Address
  • -m, --netmask: ESXi Subnet Mask
  • -g, --gateway: ESXi Gateway
  • -n, --hostname: ESXi Hostname
  • -v, --vlan: ESXi VLAN ID (0 for None)
  • -d, --dns: ESXi DNS Server

Example:

# ./esxi_customks_iso.sh -i VMware-VMvisor-Installer-7.0U2-17630552.x86_64.iso \
  -k KS-TEMPLATE.CFG \
  -a 192.168.0.10 \
  -m 255.255.255.0 \
  -g 192.168.0.1 \
  -n esx1.virten.lab \
  -v 0 \
  -d 192.168.0.1

=== Base ISO: VMware-VMvisor-Installer-7.0U2-17630552.x86_64.iso ===
=== ESXi KS Configuration ===
IP Address: 192.168.0.10
Netmask: 255.255.255.0
Gateway: 192.168.0.1
Hostname: esx1.virten.lab
VLAN: 0
ISO saved at /dev/shm/esxibuilder/esx1.virten.lab.iso

The ISO is automatically saved with the hostname as filename so you can create multiple images at once. Copy the ISO and mount it to your server to perform the automated installation.

7 thoughts on “Automated ESXi Installation - Inject Kickstart File to ESXi ISO”

  1. works well when deploying straight from ISO, for example in VMware Workstation.
    Does not work when extracting ISO to USB using Rufus, fails on my NUC8 with "failed to find kickstart file on cd-rom /KS.CFG"

    1. It's not intended to work with USB flash drives. When you are using Rufus you can simply copy the kickstart file to the drive afterward.
      kernelopts for flash drive boot is "ks=usb:/KS.CFG"

    2. Thanks for the writeup!
      Had to modify the .sh script a bit as loop devices are not available in WSL (for the mount) and the script also tries to modify files having a lowercase filename which are in uppercase for my baseimage.

    3. This script very useful. I used the script on ansible and automated physical server installation. I have a question Can I use the script for Esxi 6.X to 7 upgrade. Which parameter required for the upgrade process..

      Thanks.

Leave a Reply to Totty Cancel reply

Your email address will not be published.

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