TurnKey Linux Virtual Appliance Library

Firstboot script not getting input

Hi guys, I'm giving the final touchs to an appliance, and copied a script to /usr/lib/inithooks/firstboot.d/myscript

myscript reads information from the user to finish configuring the system. 

The problem is that when the systems boots the first time, the scripts get executed, but when it ask the first question, it doesn't receive any input. So the appliance hangs there. I'm not getting input from the keyboard. The script works normally if I execute manually in the console. Any ideas?

It could be VirtualBox

I've just confirmed that on firstboot of an appliance in virtualbox, at the time those scripts are being executed, there is no keyboard input! 

This affects those using virtualbox as hypervisor. Let me check with vmware if this happens...

Liraz Siri's picture

Not a good idea to make firstboot scripts interactive

You should have keyboard input in firstboot. We used that to allow users to opt out of installing security updates on the first boot.

However you should keep in mind there isn't always a user behind the console ready to answer your questions. So for the script that installs security updates we implemented a 5 second timeout. If you don't answer by then it defaults to installing them.

cat /usr/lib/inithooks/firstboot.d/95cronapt

...
# allow cancellation (ask again if not blank/Y/y/N/n)
while true; do
    echo -e "\n================================================================="
    TEXT="First boot detected: Install security updates? (timeout: 5) [Y/n] "
    read -t 5 -p "$TEXT" VAL || true
    [ $VAL ] || VAL=Y
    case "$VAL" in
        y|Y) echo -e "\nAttempting to install security updates" && break ;;
        n|N) echo -e "\nNot installing security updates" && exit 3 ;;
    esac
done
When there is no "reasonable" default what we've done instead is either created a di-live installer hook or added a configuration script to /usr/local/bin...

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <p> <span> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area> <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <em> <b> <u> <i> <strong> <font> <del> <ins> <sub> <sup> <quote> <blockquote> <pre> <address> <code> <cite> <strike> <caption>

More information about formatting options

Leave this field empty. It's part of a security mechanism.
(Dear spammers: moderators are notified of all new posts. Spam is deleted immediately)