WilliamLam.com

  • About
    • About
    • Privacy
  • VMware Cloud
  • Tanzu
    • Application Modernization
    • Tanzu services
    • Tanzu Community Edition
    • Tanzu Kubernetes Grid
    • vSphere with Tanzu
  • Home Lab
  • Nested Virtualization
  • 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!

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

%include /tmp/networkconfig

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

################################################################################
# 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 sure keyboard comes with us
###############################################################################
exec < /dev/tty1 > /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

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. Mourad 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
    • Scott 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
      • Santhosh 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
    • Sagi says

      06/08/2022 at 8:32 am

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

      Reply
  2. Mark 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. Zeev 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. Stacey 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. Stacey 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
      • Zeev says

        11/09/2019 at 1:21 pm

        Hi Stacey,

        I successfully tested it as well. Thanks!

        Reply
  6. Dr.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
      • Dr.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. Dr.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. Dr.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. Sagi 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. cudd 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

Author

William Lam is a Senior Staff Solution Architect working in the VMware Cloud team within the Cloud Infrastructure Business Group (CIBG) at VMware. He focuses on Cloud Native technologies, Automation, Integration and Operation for the VMware Cloud based Software Defined Datacenters (SDDC)

Connect

  • Email
  • GitHub
  • LinkedIn
  • RSS
  • Twitter
  • Vimeo

Recent

  • vSphere with Tanzu using Intel Arc GPU 01/26/2023
  • Quick Tip - Automating allowed and not allowed Datastores for use with vSphere Cluster Services (vCLS) 01/25/2023
  • ESXi with Intel Arc 750 / 770 GPU 01/24/2023
  • How to bootstrap vSAN Express Storage Architecture (ESA) on unsupported hardware? 01/19/2023
  • Automating Virtual Machine screenshots in vSphere 01/18/2023

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 © 2023

 

Loading Comments...