Bug 203777

Summary: bsdinstall(8) zfsboot script unusable for unattended installs, unless "internal" variable nonInteractive is set
Product: Base System Reporter: fre.fbsdpr
Component: binAssignee: freebsd-bugs mailing list <bugs>
Status: New ---    
Severity: Affects Some People CC: dteske
Priority: ---    
Version: 10.2-RELEASE   
Hardware: Any   
OS: Any   

Description fre.fbsdpr 2015-10-14 19:09:13 UTC
Unattended installs with the bsdinstall zfsboot script will default to
interactive mode and get stuck in the main menu loop, the script need to be
interrupted and run manually to confirm choices.

> Failure:
>      - ZFSBOOT_DISKS, ZFSBOOT_VDEV_TYPE not picked up
>      - Asks for ZFS configuration interactively

Quote from and more details in,

  https://lists.freebsd.org/pipermail/freebsd-stable/2015-June/082438.html

Workaround:
  Set 'export nonInteractive="YES"' in bsdinstall(8) installerconfig.
  Also, ZFSBOOT_* variables need to be exported in installerconfig to be
  picked up by the zfsboot script.
Comment 1 fre.fbsdpr 2015-10-15 18:47:02 UTC
(In reply to fre.fbsdpr from comment #0)

Ah, upon looking more at the bsdinstall(8) scripts (/usr/libexec/bsdinstall/*) and subroutines (/usr/share/bsdconfig/*) I found that the "input" variable is called VAR_NONINTERACTIVE, not NONINTERACTIVE, as mentioned by the mail I previously referred to.

Still, if not set, this should be set in /usr/libexec/bsdinstall/script, perhaps something like,

  if [ "$ZFSBOOT_DISKS" ]; then
          case "$VAR_NONINTERACTIVE" in
                  0|[Nn][Oo]|[Oo][Ff][Ff]|[Ff][Aa][Ll][Ss][Ee]) : do nothing ;;
                  *) export VAR_NONINTERACTIVE="YES"
          esac
          bsdinstall zfsboot
  else
          bsdinstall scriptedpart "$PARTITIONS"
  fi
Comment 2 fre.fbsdpr 2015-10-16 18:20:51 UTC
(In reply to fre.fbsdpr from comment #1)

Ok, I'll take part of that last comment back.

I noticed that i exported the nonInteractive variable in my /etc/rc.local script (on my mfsBSD image) that issues the 'bsdinstall script /etc/installerconfig' command.

The subject of this PR stands.
Comment 3 Devin Teske freebsd_committer 2016-11-24 20:49:54 UTC
You are intended to set this variable in /etc/installerconfig of your scripted install. Is it ineffectual there? Or are you saying that you wish to not have to set it?

Some people *want* interactive scripted installs.

For example, I once worked at a company where it was hard to get installation media out to people. Networks were untrusted and we had to mail installers to people (be they CD, DVD, USB, etc.). In such a case, leaving interactive prompts enabled by NOT setting nonInteractive=1 meant that the install media could be wielded through a combination of telephone and e-mail instructions to get through the interactive bits.

Concretely, one case was where we had to instruct the installer to get the distribution sets from an alternate server (if nonInteractive=1 then you simply get an error and you die, there is no prompt to allow you to select an alternate media source).

So not every script should be setting nonInteractive=1. I think each script should make its own decisions.

The standard way of creating a script for me (an author) is to enable debugging, watch the debug log to see which variables are being prompted-for when an interactive screen pops up, go code that variable into the answer-file (/etc/installerconfig), and move on. When all the variables that are required have been given default values, I may or may-not then disable debug=1 in the script (I think we turned it on by default some long time ago, anyway).

Either way, nonInteractive=1 is actually not designed to make a script unattended. To make an install unattended, you have to pre-answer all the questions. The nonInteractive nob is just to tell the code that nobody is there to drive an interactive interface (e.g, a menu to select a media source) should given information not be sufficient.

In other words, nonInteractive is there to tell the code "you cannot ``prompt for more'' when information is lacking". It does not disable msgbox's when errors occur, and it does not magically given answers to required questions (such as "what disk should I partition" -- which would be uber dangerous to make it answer itself when nonInteractive=1; you'd essentially have an installer that wreaks havoc on any/all hardware simply by booting it).

For example, as has been the case for over 20 years, you set the network interface to igb1 but there is no such interface; if nonInteractive is set, that's the end of your journey (but if unset, you'll get a prompt to select your network interface).