Solved bsdinstall - remove interactive prompts and logs

I utilize bsdinstall to rebuild my systems indirectly, but I'd like to replace the logging and dialogs entirely.

Right now, I'm launching the install essentially as:
bsdinstall -D /tmp/bsdinstall.log script.custom bootstrap

I have my own script.custom which modifies the stock script file under: /usr/libexec/bsdinstall/script. It automatically sets up networking, my framework for installing shell apps, my freebsd-installer app (wrapper around bsdinstall), sets up a package cache, and others.

I use ZFS on top of GELI for all of my installs and I utilize the zfsboot script under /usr/libexec/bsdinstall. Previously, I used my own script which differed slightly to remove the dialogs. I reverted back because I want to minimize the amount of code I'm maintaining.

While I'd like to minimize all of the dialogs and echo statements, I want to also minimize how much I deviate from the main bsdinstall and thus have to maintain myself.

I was thinking that perhaps what I might do is overwrite the files under /usr/share/bsdconfig and overwrite the functions defined there. But, I also don't like that approach. Ideally, I'd like to just be able to say:

Code:
NON_INTERACTIVE=1
REQUIRED_VARIABLE_1=1234
REQUIRED_VARIABLE_2=abcd

Ideally, I'd like the script to be simplified to something like - this isn't necessarily in the right order with all the args, but it intent is that it is self-contained, automatically sets up logging or the interactive prompts if needed.
Code:
bsdinstall config
bsdinstall zfsboot
bsdinstall mount
bsdinstall chroot

Since I use zfsboot for all of my systems and that is interactive, at least for the password prompt, I am stuck with that, but are there any other approaches?
 
My hack was to stop using bsdinstall so that I may better control logging. If a future version of FreeBSD has significant changes, then I'll need to update my scripts accordingly.

I would prefer to utilize bsdinstall, but for me, it is difficult to untangle the logging. One might merely replace the f_* functions with his or her own, but it is still tightly coupled to an interactive console.
 
I would prefer to utilize bsdinstall, but for me, it is difficult to untangle the logging. One might merely replace the f_* functions with his or her own, but it is still tightly coupled to an interactive console.
That's not true, for the most part (for example, encrypted Root-on-ZFS requires a passphrase entered manually. I haven't looked into "ZFSBOOT_GELI_KEY_FILE").

bsdinstall(8) is capable of a full unattended, scripted, non-interactive installation. This happens when the /etc/installerconfig file is present on the installer image.

Normally, the installer media is read-only, but this is no problem with an .img. When copied on a USB pendrive, it can be read-write mounted, or before copy on USB, the downloaded image attached as a mdconfig(8) memory disk.

A .iso can be extracted, the custom script added, and recreated easily. See "BUILDING AUTOMATIC INSTALL MEDIA" of bsdinstall(8).

On installer media boot, /etc/rc.local is read, and from there /usr/libexec/bsdinstall/startbsdinstall is executed (that's the "Welcome to FreeBSD" menu). If /etc/installerconfig is present, the menu is skipped, the script executed instead.

bsdinstall(8) has many "ENVIRONMENT VARIABLES", which manipulate the installation scripted. Creation of the partition table, UFS, ZFS (with the standard zfsboot dataset creation) system installation, boot code installation, all automatically. This happens in the so called "PREAMBLE" of installerconfig. The system configuration is done in the "SETUP SCRIPT" part.

The user can add additional random custom configuration to the script.

Here an example of such a configuration from my notes I collected over the years:
Code:
# request an IP from a DHCP server for the host (installer media)
dhclient em0

# begin system installation
# PREAMBLE

DISTRIBUTIONS="kernel.txz base.txz"
export ZFSBOOT_VDEV_TYPE=stripe
export ZFSBOOT_DISKS=ada0
export BSDINSTALL_LOG=/var/log/bsdinstall_log
export nonInteractive=YES

# This part happens in the chroot environment of the installed system
# SETUP SCRIPT

#!/bin/sh

cat << EOF > /boot/loader.conf
kern.geom.label.disk_ident.enable="0"
kern.geom.label.gptid.enable="0"
zfs_load="YES"
EOF


sysrc hostname="example.com"
sysrc ifconfig_DEFAULT="DHCP"
sysrc dumpdev="AUTO"
sysrc sshd_enable="YES"
sysrc zfs_enable="YES"

mkdir -p /usr/local/etc/pkg/repos

cat << EOF > /usr/local/etc/pkg/repos/local.conf
FreeBSD: { enabled: no }

FreeBSD-latest: {
  url: "pkg+http://pkg.FreeBSD.org/${ABI}/latest",
  mirror_type: "srv",
  signature_type: "fingerprints",
  fingerprints: "/usr/share/keys/pkg",
  enabled: yes
}
EOF

# install 3rd party applications on new system

export ASSUME_ALWAYS_YES=yes
pkg bootstrap
pkg install neovim
After the installation is completed, the system reboots automatically with a 10 second delay. Or poweroff the system from installerconfig.
 
Thanks, I will give that a try.

Yes, the complexity of it is a bit overwhelming. I stumbled upon some variables on my own, but it didn't get me too far. I think that would be the ideal route because it would require less maintenance on my end by leveraging existing code.
 
Back
Top