Ubuntu – Howto start an interactive script at ubuntu startup

bootinteractivescriptttyUbuntu

Based on Ubuntu core 12.04, I have prepared a bootable DVD. After booting (to console only), I can login as a user and start a script for installation of an embedded device:

sudo install_script

In order to execute this script already at startup, I've added the following to /etc/rc.local in the image of the root filesystem on the DVD:

/bin/bash -ic install_script

Since this script is executed unconditionally, I'd like to give the user some opportunity to bypass installation and get on to a login prompt. To that end, I'd like to use read in the install_script. Unfortunately, the script does not react to keyboard input when run from /etc/rc.local. (There is no problem with the same script started from a shell after login).

How can I get some user input at startup?

(Some thoughts:

  • Maybe, I can somehow detect and connect a tty to read or to the script? I tried /bin/bash -ic install_script </dev/console to no avail.
  • Maybe, there are more suitable options to /bin/bash or to read?
  • Maybe, I could boot into a single shell of a certain user (maybe root, without logging in?) with .bashrc calling sudo install_script (avoiding password check for sudo?)?
  • Maybe, there exists a better place for calling the script?
  • I would not like to separate the interaction (to occur earlier) and the install_script (e.g., by providing different boot options via isolinux and examining /proc/cmdline in the script) for the following reason: Before asking the user, I'd like to examine the system and give an overview of what exactly would happen during the install. At earlier stages of the boot process, the necessary information for the examination of the system may not yet be easily available.

)

Best Answer

In my current solution, I'm using openvt to start install_script by adding the following line to \etc\rc.local:

openvt -s -w /path/to/install_script
  • It opens a new virtual terminal (besides the seven others available in Ubuntu Core 12.04 via Alt-F[1-7]).
  • The switch -s tells openvt to switch to the new virtual terminal (without pressing Alt-F8).
  • The Switch -w lets openvt wait for completion of the command /path/to/install_script given to openvt.
  • Started this way, the script can get input from the user as usually by calling read.
  • After the script has finished, the virtual terminal is closed (no more switching to it using Alt-F8) and control is returned to the virtual terminal that was active before.
Related Question