VMware Cloud Community
mossko
Contributor
Contributor

Creating a new TTY in ESXi 4.1

Hi Guys

I have an automated deployment system which relies on using a console TTY to display a menu so the engineer can choose a hostname/SC IP/netmask etc

So far I have had no luck under ESXi creating a new terminal device (tty).

There are 2 active TTYs: tty1 and tty2.

tty1 is the Tech Support Mode and sends/receives user input.

tty2 is the installation menu which also sends/receives user input

Running the mknod command "mknod /dev/tty3 c 4 3" produces the error message"mknod: /dev/tty3: Function not implemented"

Running the same command and placing the device in the /tmp directory the command succeeds " mknod /tmp/tty3 c 4 3"

As far as I understand, the boot loader and underlying O/S is Busybox, compiled up by VMware.

I wonder if anyone else out there has managed to create a new TTY?

I have looked in to the Midwife / PBOOT parameters but it seems like a lot more work than re-using my existing build infrastructure from ESX 4/4.1

Reply
0 Kudos
12 Replies
illvilja
Hot Shot
Hot Shot

Hi,

Just one thought, what makes the local gui not enough?



VCP3/VCP4/VTSP/VSP/MCTS: Virtualization

Reply
0 Kudos
Exwork
Enthusiast
Enthusiast

Employee training would be my guess. If you've got your staff used to using an automated install system, having to train them on how to use another one requires you to deviate from your normal method.

Reply
0 Kudos
illvilja
Hot Shot
Hot Shot

Hi again,

I talked to a VMware engineer about this and the only solution he had was: "You'd have to rebuild the base tgz and edit /etc/inittab"



VCP3/VCP4/VTSP/VSP/MCTS: Virtualization

mossko
Contributor
Contributor

Hi

We're talking about ESXi here with a text-only screen.

Both TTY1 (alt-F1) and TTY2 (alt-F2) are interactive screens already, so popping up a menu system which responds to keystrokes on top of another interactive screen will cause the keystrokes to be sent to the wrong screen randomly

You can test this yourself with the following kickstart script

-


rootpw password

install nfs --server=10.0.0.x --dir=/pxeboot/media/esxi41u0

network --device=vmnic0 --bootproto=dhcp

reboot

autopart --firstdisk=local --overwritevmfs

accepteula

###############################

%pre --unsupported --interpreter=busybox

exec </dev/tty1 >/dev/tty1

chvt 1

echo "Type something in"

while read something

do

echo "You typed $something"

done

chvt 2

-


The reason why I would like to present a menu to choose the ESXi server identity is because that is how my deployment system works

I write out all the hosts/ip addresses/netmasks/gateways/vlans to a CSV file to the PXEboot / deployment server, then PXEboot the new server and choose which ESXi server from the menu and from there it's a hands-off automated install with postinstall config and network setup

Alternatively, if I could shut down the Tech Support Mode while ESXi is booting up then I could use that TTY

Reply
0 Kudos
cacheman
Contributor
Contributor

Hi....

I'm not sure if it helps, but I was in the same situation. I was trying to PXE install ESXi (v5.0 in my case) via kickstart and I wanted to have the user presented with some initial questions on an unused virtual console using the 'dialog' command to provide text based menus.

I wasn't able to create a new TTY but what I was able to do is modify /etc/inittab so it didn't start the termsupport.sh on /dev/tty1. What I did was:

1. Got a copy of /etc/inittab and commented out that line for techsupport.sh

2. Put it into a directory called /somedir/etc

3. Cd'ed to /somedir

4. Ran tar czf extras.tgz etc

5. Copied extras.tgz to the same directory as the boot.cfg on our PXE server (or you could do same on a CD)

6. Edited boot.cfg to add '--- extras.tgz'

...and that was it....once you boot up, the /etc/inittab from extras.tgz overwrites the one that comes with the OS installer and you don't get techsupport.sh running on /dev/tty1 so you can use it.

Not an ideal solution, but it does the job for me.

Like you though, I'd prefer to have a /dev/tty3 for this, so I could keep the login shell on /dev/tty1. Its been almost 18 months since your last post....I don't suppose since then you found a way to create a /dev/tty3?

Anyway, hope this helps a little.

Cacheman.

Reply
0 Kudos
Tom1193
Contributor
Contributor

...

Just one thought, what makes the local gui not enough?

(ESXi 5.1 acts the same way so I think this is still a relevant question)

If I run a command that locks up the shell, it would be convenient to have another local TTY available to kill the offending command from.

Reply
0 Kudos
cacheman
Contributor
Contributor

Hi....

It's been a while since my original hacked solution back in 2012. As some may have noticed my solution from back then stopped working around v6.5 of ESXi.

As far as I can tell, it appears that more recent versions of ESXi (from at least 6.5 onwards) start the init process before the extras.tgz file containing the modified /etc/inittab is unpacked. As a result, when init starts, it reads the /etc/inittab that comes with ESXi and not the modified one in /etc/inittab with the 'techsuport.sh' line commented out and so a login process is started on tty1 and it becomes unusable for kickstart scripted user input prompts.

It is possible to make init re-read /etc/inittab by doing a kill -HUP on the PID of the init process, and then killing the techsupport.sh and getty processes. However, I found when I did this, I was able to run commands which displayed a prompt for user input on tty1, but it appeared that I couldn't type anything in response to the prompt.

The solution I found for this was to not comment out the line in /etc/inittab, but replace it with a line which starts /bin/sh:

  • 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'

Now when you boot up the ESXi installer it will still start a login prompt on tty1 (via techsupport.sh + getty). However, via your kickstart script you can do a kill -HUP on the init process to get it to re-read /etc/inittab (which will now contain the line shown above), and then kill the existing techsupport.sh and getty processes. Now when you run commands on tty1 to prompt for user input they work properly.

If this were standard UNIX/Linux, making init re-read /etc/inittab would simply require the command kill -1 1 (or kill -HUP 1). However, it seems in ESXi that init is does not have PID=1, so you have to extract the PID.

The basic code of the %pre section of the kickstart script I use is at the end of this post....the commands to do a kill -HUP on the init process, and kill techsupport.sh + getty are the first things to run and must run before any commands which are intended to prompt for user input.

Anyway, hope this helps someone a little.

Cacheman.

KICKSTART SCRIPT %pre SECTION

###############################################################################

# 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

###############################################################################

<Code for User Prompts>

Reply
0 Kudos
Korstiaan201110
Contributor
Contributor

Hi,

I tried this on a HPE BL460c blade server (boot.cfg is in directory EFI for me) and used the .ISO file via the HPE ILO remote console.

I could not change the initial file.

I solved it by adding this in the kickstart script. (see below)

I create a new inittab file instead of adding modules. (+sleep 10)

This is tested on 6.7U1, ISO, HPE virtual CD-ROM

I now only have to create an ISO with only the ks-script inside. (no need for making extras.tgz)

The only problem is that if you mistype an entry, the kickstart script see this as a wrong character (the backspace gets wrong interpreted).
This means you may not mistype anything during entering of the parameters?

Maybe someone know how to solve this?

Thanks anyway for the code!

###############################################################################

# Pre-installation section

###############################################################################

%pre --interpreter=busybox

#

# Change the inittab file by removing the techsupport.sh line and changing by another tty1

# We do this by creating a new inittab file

#

cp /etc/inittab /etc/inittab.ori

rm /etc/inittab

echo "::sysinit:/usr/lib/vmware/secureboot/bin/secureBoot.py" > /tmp/inittab

echo "::sysinit:/usr/lib/vmware/firstboot/bin/firstboot.py -e" >> /tmp/inittab

echo "::sysinit:/usr/lib/vmware/rp/bin/configRP init" >> /tmp/inittab

echo "#" >> /tmp/inittab

echo "::sysinit:/usr/lib/vmware/misc/bin/timeoutConsole.sh tty4 &" >> /tmp/inittab

echo "::sysinit:/bin/init-launcher" >> /tmp/inittab

echo "::wait:/usr/lib/vmware/firstboot/bin/firstboot.py ++group=host/vim/vmvisor/boot -l" >> /tmp/inittab

echo "::wait:/bin/services.sh start" >> /tmp/inittab

echo "::wait:/usr/lib/vmware/misc/bin/ucode_workarounds.py" >> /tmp/inittab

echo "::wait:/bin/apply-host-profiles" >> /tmp/inittab

echo "::wait:/usr/lib/vmware/secureboot/bin/secureBoot.py ++group=host/vim/vmvisor/boot -a" >> /tmp/inittab

echo "::wait:/usr/lib/vmware/vmksummary/log-bootstop.sh boot" >> /tmp/inittab

echo "::wait:/usr/lib/vmware/coredump/collect-coredump-at-boot.sh" >> /tmp/inittab

echo "::wait:/bin/vmdumper -g 'Boot Successful'" >> /tmp/inittab

echo "::wait:/usr/lib/vmware/misc/bin/killTimeoutConsole.sh" >> /tmp/inittab

echo "::wait:/bin/sh ++min=0,group=host/vim/vimuser/terminal/shell /etc/rc.local" >> /tmp/inittab

echo "::wait:/bin/esxcfg-init --set-boot-progress done" >> /tmp/inittab

echo "::wait:/bin/vmware-autostart.sh start" >> /tmp/inittab

echo "#Following line has been commented out by skor and replaced for Kickstart" >> /tmp/inittab

echo "#tty1::respawn:/bin/initterm.sh tty1 /bin/techsupport.sh" >> /tmp/inittab

echo "tty1::respawn:/bin/initterm.sh tty1 /bin/sh" >> /tmp/inittab

echo "tty2::respawn:-/bin/initterm.sh tty2 /bin/dcuiweasel" >> /tmp/inittab

echo "::restart:/bin/init" >> /tmp/inittab

echo "::shutdown:/usr/lib/vmware/vmksummary/log-bootstop.sh stop" >> /tmp/inittab

echo "::shutdown:/bin/shutdown.sh" >> /tmp/inittab

echo "::shutdown:/usr/lib/vmware/random-seed/bin/storeRandomSeed.sh" >> /tmp/inittab

echo "::shutdown:/bin/vmware-autostart.sh stop" >> /tmp/inittab

echo "::shutdown:/bin/services.sh stop" >> /tmp/inittab

echo "::shutdown:/bin/backup.sh 1" >> /tmp/inittab

echo "#This call sets up the next fast boot, but does not perform a reboot," >> /tmp/inittab

echo "#and must be called after backup.sh" >> /tmp/inittab

echo "::shutdown:/usr/lib/vmware/loadesx/bin/loadESXShutdown.sh prepare" >> /tmp/inittab

echo "#No logging after this point" >> /tmp/inittab

echo "::shutdown:/usr/lib/vmware/vmsyslog/bin/shutdown.sh" >> /tmp/inittab

cp /tmp/inittab /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 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

echo "network --bootproto=static --addvmportgroup=0 --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

Korstiaan201110
Contributor
Contributor

Hi,

Or even shorter; replace the correct line in the inittab file:

#

# Change the inittab file by removing the techsupport.sh line and changing by another tty1

#

cp /etc/inittab /etc/inittab.ori

sed -i 's/tty1::respawn:\/bin\/initterm.sh tty1 \/bin\/techsupport.sh/tty1::respawn:\/bin\/initterm.sh tty1 \/bin\/sh/g' /etc/inittab

# Wait for techsupport to start

sleep 10

...

Reply
0 Kudos
DLally
Enthusiast
Enthusiast

Any idea to do if it gets stuck on this below?

Shutting down firmware services...

Relocating modules and starting up the kernel...

Reply
0 Kudos
weisenberg
Contributor
Contributor

Hi,

When I use this method when installing ESXi 6.5, I get an error on the screen before the reboot, "Warning: network command not specified. Defaulting to DHCP". Because we're substituting the shell on the first vty, you can't use it to look at the logs or troubleshoot the process. Any ideas what this message means or how to fix it?

Thanks!

Reply
0 Kudos
mobinn
Contributor
Contributor

HI

I found a solution for working Backspace key, you can add "stty erase ^H" right before While in your code.

Thanks for code!

hope this helps a little.

Mobin

Reply
0 Kudos