I ran into a situation where I wanted to run a custom bash on first launch of a VM built from template.  I wanted this script to be able to ask for certain variables from the user in order to configure the systems DNS, NTP, Red Hat Satellite activation key, IP address and hostname.

In order for the script to run on boot, I added the script location into rc.local

When booting however, keyboard response was poor and there was no response/echo of the typed characters from the read (even though -s wasn’t specified).

Found this problem to be with plymouth running during boot startup for GIU fluidity.

Simply adding “plymouth quit” in my script solved this issue.  Below is a sample of the script for clarity:

#!/bin/bash
# are we a template?
if [[ -f "/etc/rhev_template" ]]
then
  echo "[*] I am a template, not performing customisation"
  exit 9
fi
#enable read through rc.local by disabling plymouth
plymouth quit

# network config
  NET_CORRECT="n"
  while [[ "$NET_CORRECT" != "y" ]]
  do
    read -p "[*] hostname: " HOST_NAME
    read -p "[*] ip address: " NET_IP
    read -p "[*] subnet mask: " NET_MASK
    read -p "[*] gateway: " NET_GW

    echo
    echo "    --------------------"
    echo "    hostname: $HOST_NAME"
    echo "    ip address: $NET_IP"
    echo "    subnet mask: $NET_MASK"
    echo "    gateway: $NET_GW"
    echo "    --------------------"
    echo -n "[*] Are these network settings correct (y to proceed) ? "
    read NET_CORRECT
  done
[script cut off]


Tagged with →  
Share →

Leave a Reply

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