Skip to content

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.

21 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.

  4. Hi Florian,
    This is really amazing but im hitting a small error im hoping you can advise on.

    We are using the VMWare Custom ISOs we create in vCenter which already has all of our drivers/tools/FW in it. When I use your custom ks injector when mounting the ISO instead of rolling directly to the installed im getting a "mounting from CD ROM with 2x images, which image 0/1? which defaults to 0. But does not time it self out so I have to open a console to select 0. Is there a function I can set to make it auto-select 0?

    Thank you for the guide it is really awesome!

    -Jess

    1. I also have the same issue, can't figure out what I'm doing wrong. I have the iso on a Flashdrive but it's not finding the Kickstart file, if you've figured it out, am I supposed to have the kickstart file also on the flashdrive?

  5. Hello !
    great work but doesn't seem to work on my specific server, and that shitbox doesn't have ANY video output so I don't know why or where it fails (my company bought 50 of them, so that was 50 times 100€ cheaper. yeah... I've been 3 solid days on this, i'll promise my salary will eat up that savings ^^)

    any way to output a logfile on a USB Key ?
    thanks.

    1. Systems without Remote KVM or Video Output sounds like a real nightmare to troubleshoot. As far as i know, the only option in ESXi is Serial Port logging, see https://kb.vmware.com/s/article/1033888

      Are you even sure that it is configured to boot from USB? If you are sure that it boots, but the installation fails you can try to plug in a usb drive with ESXi preinstalled (Just use any another system with video output to install ESXi and switch the usb drive).

      1. Hello Florian.
        when tested with a VM on the same vlan, she does PXE boot an auto install (until failing because sh'es hosted on ESXi 6.5 which doesn't have the option to allow nested esxi server, but taht's already far in the install process, and she does it automatically.)
        I'm a reviewing my KS.CFG file to simplify it (no vSwitches and so on) and my boot.cfg to try something like this :
        kernelopt=runweasel debugLogToSerial=1 text nofb com1_baud=115200 com1_Port=0x3f8 tty2Port=com1 gdbPort=none logPort=com1 ks=cdrom:KS.CFG

      2. OK, I can confirm this did the trick :

        boot.cfg :
        kernelopt=runweasel debugLogToSerial=1 text nofb com1_baud=115200 com1_Port=0x3f8 tty2Port=com1 gdbPort=none logPort=none ks=cdrom:KS.CFG

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

        now i can play with the KS file, the install didn't run unattended, but I can now try to understand why :)

  6. Hi. I had the same issues when using HPE iLO virtual media.
    It seems that iLO virtual media ejects the ISO after first reboot (stage 1) during ESXi installation.
    (Re)Mounting the ISO before 2nd stage of ESXi install started worked for me.

  7. Hi. I had the same issues "failed to find kickstart file on cd-rom /KS.CFG" when using HPE iLO virtual media.

    It seems that iLO virtual media ejects the ISO after first reboot (stage 1) during ESXi installation.
    (Re)Mounting the ISO before 2nd stage of ESXi installation starts worked for me.

    ... and by the way ... Thanks for the great instructions, helped me a lot :-)

Leave a Reply

Your email address will not be published. Required fields are marked *