1
0
mirror of https://git.FreeBSD.org/src.git synced 2026-06-02 11:24:32 +00:00

bsdinstall: do pkgbase installations with the "script" command

"bsdinstall script" will now do a pkgbase installation by default.  The
system components to install can be specified in the COMPONENTS
variable, and have the same names as those used in the interactive
installer.  bsdinstall will still do a legacy distset installation if
DISTRIBUTIONS is defined in the installerconfig file.

MFC:		1 week
PR:		290375
Sponsored by:	ConnectWise
Reviewed by:	ziaee, ivy, jduran
Differential Revision: https://reviews.freebsd.org/D56717
This commit is contained in:
Alan Somers
2026-04-28 11:27:17 -06:00
parent dab8138e13
commit dc14ae4217
4 changed files with 96 additions and 42 deletions
+5
View File
@@ -27,6 +27,11 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 16.x IS SLOW:
world, or to merely disable the most expensive debugging functionality
at runtime, run "ln -s 'abort:false,junk:false' /etc/malloc.conf".)
20260512:
"bsdinstall script" will now do a pkgbase installation by default. To
revert to the legacy distset installation, set "DISTRIBUTIONS" in
your installerconfig.
20260412:
The /etc/rc.d/NETWORKING script no longer provides the legacy
NETWORK alias. Third-party or local RC scripts that still use
+35 -10
View File
@@ -29,7 +29,7 @@
.\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd April 20, 2026
.Dd May 12, 2026
.Dt BSDINSTALL 8
.Os
.Sh NAME
@@ -109,9 +109,12 @@ for more information on this target.
.Pp
The
.Ev DISTRIBUTIONS
environment variable is set to
.Dq base.txz kernel.txz
by default for this target.
environment variable is unset by default for this target.
Instead, the
.Ev COMPONENTS
environment variable is effectively set to
.Dq base kernel kernel-dbg
for this target.
.It Cm keymap
If the current controlling TTY is a
.Xr syscons 4
@@ -321,8 +324,17 @@ overridden when making scripted or customized installers.
The directory to use for temporary files.
Default:
.Dq Pa /tmp
.It Ev COMPONENTS
The set of components to install for scripted installations using
base system packages, e.g.,
.Dq base lib32 kernel-dbg tests .
Default: "base kernel-dbg"
.It Ev DISTRIBUTIONS
The set of distributions to install, e.g., "base.txz kernel.txz ports.txz".
The set of distributions to install for traditional installations, e.g.,
.Dq base.txz kernel.txz ports.txz .
If unset, then
.Nm
will install using base system packages.
Default: unset unless noted otherwise in the
.Sx TARGETS
section.
@@ -609,18 +621,18 @@ A typical bsdinstall script, using the default filesystem layout and the UFS
filesystem, looks like this:
.Bd -literal -offset indent
PARTITIONS=DEFAULT
DISTRIBUTIONS="kernel.txz base.txz"
COMPONENTS="base debug"
#!/bin/sh
sysrc ifconfig_DEFAULT=DHCP
sysrc sshd_enable=YES
pkg install puppet
pkg install -y puppet
.Ed
.Pp
For a scripted installation involving a ZFS pool spanning multiple disks,
the script instead looks like this:
.Bd -literal -offset indent
DISTRIBUTIONS="kernel.txz base.txz"
COMPONENTS="base debug"
export ZFSBOOT_VDEV_TYPE=stripe
export ZFSBOOT_DISKS="ada0 ada1"
export nonInteractive="YES"
@@ -628,7 +640,20 @@ export nonInteractive="YES"
#!/bin/sh
echo "ifconfig_DEFAULT=DHCP" >> /etc/rc.conf
echo "sshd_enable=YES" >> /etc/rc.conf
pkg install puppet
pkg install -y puppet
.Ed
.Pp
To install using traditional distributions sets instead of packages, set
.Ev DISTRIBUTIONS
to the list of distribution sets to install, like this:
.Bd -literal -offset indent
PARTITIONS=DEFAULT
DISTRIBUTIONS="kernel.txz base.txz"
#!/bin/sh
sysrc ifconfig_DEFAULT=DHCP
sysrc sshd_enable=YES
pkg install -y puppet
.Ed
.Pp
On
@@ -653,7 +678,7 @@ arbitrary commands can be run here to extend the installer.
In addition to the variables in
.Sx ENVIRONMENT VARIABLES ,
in particular
.Ev DISTRIBUTIONS ,
.Ev COMPONENTS ,
the preamble can contain a variable
.Ev PARTITIONS
which is passed to the
+14 -1
View File
@@ -180,7 +180,18 @@ local function select_components(components, options)
}
append_list(bsddialog_args, checklist_items)
local exit_code, output = bsddialog(bsddialog_args)
local exit_code = 0
local output = ""
if options.non_interactive then
local env_components = os.getenv("COMPONENTS")
if env_components then
output = env_components:gsub(" ", "\n")
else
output = "base\nkernel-dbg"
end
else
exit_code, output = bsddialog(bsddialog_args)
end
-- This should only be possible if bsddialog is killed by a signal
-- or buggy, we disable the cancel option and esc key.
-- If this does happen, there's not much we can do except exit with a
@@ -300,6 +311,8 @@ local function parse_options()
for _, a in ipairs(arg) do
if a == "--jail" then
options.jail = true
elseif a == "--non-interactive" then
options.non_interactive = true
else
io.stderr:write("Error: unknown option " .. a .. "\n")
os.exit(1)
+24 -13
View File
@@ -40,6 +40,7 @@ f_include $BSDCFG_SHARE/variable.subr
# PARTITIONS
# DISTRIBUTIONS
# BSDINSTALL_DISTDIR
# COMPONENTS
#
# Default name of the ZFS boot-pool
@@ -97,7 +98,6 @@ awk 'BEGIN {pathb=ARGV[2]; ARGV[2]=""} /^#!/{b=1} {
>$TMPDIR/bsdinstall-installscript-preamble
. $TMPDIR/bsdinstall-installscript-preamble
: ${DISTRIBUTIONS="kernel.txz base.txz"}; export DISTRIBUTIONS
export BSDINSTALL_DISTDIR
# Re-initialize a new log if preamble changed BSDINSTALL_LOG
@@ -118,6 +118,14 @@ else
fi
bsdinstall mount
if [ -n "$COMPONENTS" -a -n "$DISTRIBUTIONS" ]; then
error "Cannot set both COMPONENTS and DISTRIBUTIONS"
elif [ -z "$DISTRIBUTIONS" ]; then
# If COMPONENTS is set, or neither is, install with pkgbase
bsdinstall pkgbase --non-interactive
else
# Otherwise, unpack distsets
# Fetch missing distribution files, if any
exec 5>&1
export BSDINSTALL_DISTDIR=$(`dirname $0`/fetchmissingdists 2>&1 1>&5)
@@ -126,30 +134,33 @@ exec 5>&-
[ $FETCH_RESULT -ne 0 ] && error "Could not fetch remote distributions"
# Unpack distributions
bsdinstall checksum
if [ -t 0 ]; then
# If install is a tty, use distextract as normal
bsdinstall distextract
else
# Otherwise, we need to use tar (see https://reviews.freebsd.org/D10736)
# Otherwise, we need to use tar (see
# https://reviews.freebsd.org/D10736)
for set in $DISTRIBUTIONS; do
f_dprintf "Extracting $BSDINSTALL_DISTDIR/$set"
# XXX: The below fails if any mountpoints are FAT, due to
# inability to set ctime/mtime on the root of FAT partitions,
# which is needed to support e.g. EFI system partitions. tar has
# no option to ignore this (distextract ignores them internally
# through a hack), and returns 1 on any warning or error,
# effectively turning all warnings into fatal errors.
# XXX: The below fails if any mountpoints are FAT, due
# to inability to set ctime/mtime on the root of FAT
# partitions, which is needed to support e.g. EFI
# system partitions. tar has no option to ignore this
# (distextract ignores them internally through a hack),
# and returns 1 on any warning or error, effectively
# turning all warnings into fatal errors.
#
# Work around this in an extremely lame way for the specific
# case of EFI system partitions only. This *ONLY WORKS* if
# /boot/efi is empty and does not handle analogous problems on
# other systems (ARM, PPC64).
# Work around this in an extremely lame way for the
# specific case of EFI system partitions only. This
# *ONLY WORKS* if /boot/efi is empty and does not
# handle analogous problems on other systems (ARM,
# PPC64).
tar -xf "$BSDINSTALL_DISTDIR/$set" -C $BSDINSTALL_CHROOT --exclude boot/efi
mkdir -p $BSDINSTALL_CHROOT/boot/efi
done
fi
fi
# Configure bootloader if needed
bsdinstall bootconfig