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
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.
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
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
I have the same issue..
Did you find a solution?
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
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
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?
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.
Stacey,
Thanks for the catch. I've just updated the KS example
Hi Stacey,
I successfully tested it as well. Thanks!
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
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!
You are right, my code only works in esxi 7+. Going forward, using tty3 or tty4 for user input is much more comfortable :). Cheers!
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
########################################
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
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
#############################
.
.
.
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.