WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud Foundation
  • VKS
  • Homelab
    • Resources
    • Nested Virtualization
  • VMware Nostalgia
  • Apple
You are here: Home / Automation / Revisiting prompting for user input during an interactive or scripted install of ESXi

Revisiting prompting for user input during an interactive or scripted install of ESXi

01.10.2019 by William Lam // 17 Comments

For those that have a need to prompt for additional user input during an installation of ESXi, whether that is an interactive session or using a scripted install (Kickstart) may have noticed the solution posted in my 2015 blog post no longer works with recent releases of ESXi (newer than 6.0).


I was recently contacted by VMTN community cacheman, who authored the original snippet after my 2011 post with an updated solution that would work with newer releases of ESXi (e.g. 6.5 or newer). Thanks to Chris, he discovered the following after taking another look at the initial hack:

It seems that the tty1 techsupport.sh which I had commented out in /etc/inittab is having no effect in these versions and the login prompt is starting on tty1. As far as I can tell this is because for versions >= 6.5, the init process starts before the extras.tgz is unpacked, so it reads the /etc/inittab that comes natively with ESXi rather than the modified one in extras.tgz.

Chris was kind enough to provide me with the updated code and I have integrated that into a complete working kickstart example which you can find below. Thanks for your contribution (again) Chris!

Pre-ESXi 7.x

accepteula
install --firstdisk --overwritevmfs
rootpw VMware1!
reboot

%include /tmp/networkconfig

########################################
# Pre-installation section
########################################
%pre --interpreter=busybox

# Start interactive session
cp /etc/inittab /etc/inittab.org
sed -i 's/\/bin\/techsupport.sh/\/bin\/sh/g' /etc/inittab

# Wait for techsupport to start
sleep 10

# Force init to re-read /etc/inittab
init_pid=$(ps -c|grep '\/bin\/init'|awk '{ print $1 }')
kill -1 ${init_pid}

# Kill /bin/techsupport.sh and associated getty process
techsupp_pid=$(ps -c|grep '\/bin\/techsupport\.sh'|awk '{ print $1 }')
kill -9 ${techsupp_pid}
getty_pid=$(ps -c|grep 'getty.*tty1'|awk '{ print $1 }')
kill -9 ${getty_pid}

# Change to virtual terminal 2
/usr/bin/chvt 1

# Make backspace/erase work again
stty erase ^?

# Make sure keyboard comes with us
exec /dev/tty1 2>&1

# Clear screen
clear

###############################################################################
# INSERT YOUR CODE HERE
###############################################################################
HOSTNAME=""
IPADDR=""
NETMASK=""
GATEWAY=""
DNS=""

while [[ "$HOSTNAME" == "" ]] || [[ "${IPADDR}" == "" ]] || [[ "${NETMASK}" == "" ]] || [[ "${GATEWAY}" == "" ]] || [[ "${DNS}" == "" ]] ; do
    echo
    echo " *** Please enter the following details: *** "
    echo
    read -p "Hostname: " HOSTNAME
    read -p "IP Address: " IPADDR
    read -p "Netmask: " NETMASK
    read -p "Gateway: " GATEWAY
    read -p "DNS: " DNS
done
clear

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

echo -e "Applying the following configuration: \n"
echo "Hostname = ${HOSTNAME}"
echo "IP Address = ${IPADDR}"
echo "Netmask = ${NETMASK}"
echo "Gateway = ${GATEWAY}"
echo -e "DNS = ${DNS}\n"
sleep 5
/usr/bin/chvt 2

%firstboot --interpreter=busybox

vim-cmd hostsvc/enable_ssh
vim-cmd hostsvc/start_ssh
vim-cmd hostsvc/enable_esx_shell
vim-cmd hostsvc/start_esx_shell

ESXi 7.x and later

accepteula
install --firstdisk --overwritevmfs
rootpw VMware1!
reboot

%include /tmp/networkconfig

########################################
# Pre-installation section
########################################
%pre --interpreter=busybox

# Change to virtual terminal 3
/usr/bin/chvt 3

# Colorize input message
Cyan='\033[0;36m'
Yellow='\033[0;33m'
Green='\033[0;32m'
Color_Off='\033[0m'

# Make backspace work again
stty erase ^?

# Clear screen
clear

########################################
# INSERT YOUR CODE HERE
########################################
HOSTNAME=""
IPADDR=""
NETMASK=""
GATEWAY=""
DNS=""

while [[ "$HOSTNAME" == "" ]] || [[ "${IPADDR}" == "" ]] || [[ "${NETMASK}" == "" ]] || [[ "${GATEWAY}" == "" ]] || [[ "${DNS}" == "" ]] ; do
    echo -e "\n\n${Cyan}*** Please enter the following details: ***${Color_Off}\n\n"> /dev/tty3
    echo -e -n "${Yellow}Hostname: ${Color_Off}"> /dev/tty3; read HOSTNAME < /dev/tty3
    echo -e -n "${Yellow}IP Address: ${Color_Off}"> /dev/tty3; read IPADDR < /dev/tty3
    echo -e -n "${Yellow}Netmask: ${Color_Off}"> /dev/tty3; read NETMASK < /dev/tty3
    echo -e -n "${Yellow}Gateway: ${Color_Off}"> /dev/tty3; read GATEWAY < /dev/tty3
    echo -e -n "DNS: ${Color_Off}"> /dev/tty3; read DNS < /dev/tty3
done

echo -e "${Green}\n\nPress any key to continue...\n${Color_Off}"> /dev/tty3; read -n 1 -s < /dev/tty3
echo "network --bootproto=static --hostname=${HOSTNAME} --ip=${IPADDR} --netmask=${NETMASK} --gateway=${GATEWAY} --nameserver=${DNS} --device=vmnic0" > /tmp/networkconfig

sleep 5
/usr/bin/chvt 2

%firstboot --interpreter=busybox

vim-cmd hostsvc/enable_ssh
vim-cmd hostsvc/start_ssh
vim-cmd hostsvc/enable_esx_shell
vim-cmd hostsvc/start_esx_shell

More from my site

  • How to prevent physical CD-ROM from ejecting after installing or upgrading ESXi?
  • Automated ESXi Installation to USB using Kickstart
  • How to prompt for user input during an interactive or scripted install of ESXi?
  • How to create custom ESXi boot menu to support multiple Kickstart files?
  • How to automate VM deployment from large USB keys using ESXi Kickstart?

Categories // Automation, ESXi Tags // ESXi, kickstart, ks.cfg

Comments

  1. *protectedMourad says

    01/21/2019 at 8:49 am

    Hello William,

    Thank-you for providing the code.
    This intermediate ESXi custom install image is part of the request that customers have :
    All the default parameter’s like keyboard, password, advanced parameters are set from KS and the, the user need only to enter the ESXi Network Info’s.

    Unfortunately I was unsuccessful with my first tests (Nested ESXi with HP ISO ESXi 6.5U2 image) :
    - I need to enter the console root logging and blank password (initial KS password is ignored),
    - Then the keyboard is extremely slow (similar to what was with the previous solution).

    I am going to investigate the issue.

    In the mean-time if you have any suggestions?

    Regards.

    Reply
    • *protectedScott says

      01/22/2019 at 12:00 pm

      There are a few steps missing, in order to get this to work you also need to do the following:

      Get a copy of /etc/inittab and instead of commenting out the line for techsupport.sh, replace it with:
      tty1::respawn:/bin/initterm.sh tty1 /bin/sh
      Put it into a directory called /somedir/etc
      Cd to /somedir
      Run 'tar czf extras.tgz etc'
      Copy extras.tgz to the same directory as the boot.cfg on our PXE server (or you could do same on a CD)
      Edit boot.cfg to add '--- extras.tgz'

      I can confirm this is a working solution on 6.7U1

      I found this information on a recent cacheman post here https://communities.vmware.com/thread/278723

      Reply
      • *protectedSanthosh Kumar says

        05/14/2020 at 12:23 am

        Hello William

        I followed the above steps created custom esxi iso yet after booting with ISO the keyboard inputs not accepted.

        Any guidance on this will be very helpful.

        Thanks

        Reply
    • *protectedSagi says

      06/08/2022 at 8:32 am

      I have the same issue..
      Did you find a solution?

      Reply
  2. *protectedMark says

    09/20/2019 at 1:01 am

    When i attempt to do this, i get a network error during installation where it says it can't apploy network settings and it'll revert to DHCP

    Ever had this issue?

    Regards

    Reply
  3. *protectedZeev Eisenberg says

    11/01/2019 at 6:41 pm

    Hi Mark,

    I get the same error ("Warning: network command not specified. Defaulting to DHCP") when installing ESXi 6.5.

    William, has anyone found a solution for this?

    Thanks

    Reply
  4. *protectedStacey says

    11/08/2019 at 12:12 pm

    I got the same error as above, defaulting to DHCP as if it isn't substituting the variables for the input. Has anyone responded with a fix?

    Reply
  5. *protectedStacey says

    11/08/2019 at 1:48 pm

    I found the resolution for the "defaulting to DHCP" error. At the end of the network line, the redirect is writing to > /tmp/networkconfig. This isn't defined anywhere in the script. After the reboot command, the line %include /tmp/networkconfig needs to be added like your original ks.cfg script from 4.1.

    Reply
    • William Lam says

      11/09/2019 at 1:05 pm

      Stacey,

      Thanks for the catch. I've just updated the KS example

      Reply
      • *protectedZeev says

        11/09/2019 at 1:21 pm

        Hi Stacey,

        I successfully tested it as well. Thanks!

        Reply
  6. *protectedDr.Socrates says

    09/06/2020 at 5:43 am

    Hi Will,

    Why don't you simply use free tty like 3 or 4, instead of coping with already used tty1/2? I use tty3 and it works like a charm even in esxi 7.0. Try something like this:

    ########################################
    %pre --interpreter=busybox

    /usr/bin/chvt 3
    clear

    while [[ "$HOSTNAME" == "" ]] || [[ "${IPADDR}" == "" ]] || [[ "${NETMASK}" == "" ]] || [[ "${GATEWAY}" == "" ]] || [[ "${DNS}" == "" ]] ; do
    echo -e "\n\n*** Please enter the following details: ***\n\n"> /dev/tty3;
    echo -n "Hostname: "> /dev/tty3; read HOSTNAME /dev/tty3; read IPADDR /dev/tty3; read NETMASK /dev/tty3; read GATEWAY /dev/tty3; read DNS /dev/tty3; read -n 1 -s < /dev/tty3

    sleep 5
    /usr/bin/chvt 2
    ########################################

    This way we can avoid touching init and existing shell/terminal processes. It is clean and simple.

    Dr.Socrates

    Reply
    • William Lam says

      09/07/2020 at 5:56 am

      When I had looked into several years ago and even most recently with 6.7, only tty1/tty2 was possible. It sounds like this may have changed with 7.0, so good to know!

      Reply
      • *protectedDr.Socrates says

        09/09/2020 at 3:17 am

        You are right, my code only works in esxi 7+. Going forward, using tty3 or tty4 for user input is much more comfortable :). Cheers!

        Reply
  7. *protectedDr.Socrates says

    09/06/2020 at 5:53 am

    Something weird happened to my code, trying again:

    ########################################
    %pre –interpreter=busybox

    /usr/bin/chvt 3
    clear

    while [[ "$HOSTNAME” == "" ]] || [[ "${IPADDR}" == "" ]] || [[ "${NETMASK}" == "" ]] || [[ "${GATEWAY}" == "" ]] || [[ "${DNS}" == "" ]] ; do
    echo -e "\n\n*** Please enter the following details: ***\n\n"> /dev/tty3
    echo -n "Hostname: "> /dev/tty3; read HOSTNAME /dev/tty3
    echo -n "IP Address: "> /dev/tty3; read IPADDR /dev/tty3
    echo -n "Netmask: "> /dev/tty3; read NETMASK /dev/tty3
    echo -n "Gateway: "> /dev/tty3; read GATEWAY /dev/tty3
    echo -n "DNS: "> /dev/tty3; read DNS /dev/tty3
    done
    echo -e "\n\nPress any key to continue...\n"> /dev/tty3; read -n 1 -s < /dev/tty3

    sleep 5
    /usr/bin/chvt 2
    ########################################

    Reply
  8. *protectedDr.Socrates says

    09/06/2020 at 6:27 am

    I don't know why my code is being eaten when posted, or don't know how to post it properly. In all "read" statements, a "<" is missing before /dev/tty3, e.g this is correct: read HOSTNAME < /dev/tty3

    Reply
  9. *protectedSagi Pael says

    07/10/2022 at 4:02 am

    I have finally solved all issues.
    - backspace working again
    - solve "slow keyboard" - adding sleep 10, and kill initab
    - techsupport isnt started, and not login needed (by remove techsupport from initab

    ###############################################################################
    # Pre-installation section
    ###############################################################################
    %pre --interpreter=busybox

    ###### Start interactive session
    cp /etc/inittab /etc/inittab.org
    sed -i 's/\/bin\/techsupport.sh/\/bin\/sh/g' /etc/inittab

    # Wait for techsupport to start
    sleep 10

    # Force init to re-read /etc/inittab
    init_pid=`ps -c|grep '\/bin\/init'|awk '{ print $1 }'`
    kill -1 ${init_pid}

    # Kill /bin/techsupport.sh and associated getty process
    techsupp_pid=`ps -c|grep '\/bin\/techsupport\.sh'|awk '{ print $1 }'`
    kill -9 ${techsupp_pid}
    getty_pid=`ps -c|grep 'getty.*tty1'|awk '{ print $1 }'`
    kill -9 ${getty_pid}

    # Change to virtual terminal 2
    /usr/bin/chvt 1

    # Make backspace work again
    stty erase ^H

    # Make sure keyboard comes with us
    exec /dev/tty1 2>&1

    # Clear screen
    clear

    #############################
    ####### your code
    #############################
    .
    .
    .

    Reply
  10. *protectedcudd says

    10/23/2022 at 7:58 am

    Hello William,
    User inputs is not working on esxi 7.0. I searched how can ask user input 7.0 kickstart file, however i couldn't find.

    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

 

Loading Comments...