diff --git a/usr.sbin/bsdinstall/bsdinstall.8 b/usr.sbin/bsdinstall/bsdinstall.8 index c8bf143322ae..50c8948a7989 100644 --- a/usr.sbin/bsdinstall/bsdinstall.8 +++ b/usr.sbin/bsdinstall/bsdinstall.8 @@ -1,705 +1,722 @@ .\"- .\" Copyright (c) 2011-2013 Nathan Whitehorn All rights reserved. .\" Copyright (c) 2018 Roberto Fernandez Cueto +.\" Copyright (c) 2024 The FreeBSD Foundation +.\" +.\" Portions of this documentation were written by Björn Zeeb +.\" under sponsorship from the FreeBSD Foundation. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE .\" DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, .\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES .\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR .\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, .\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN .\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd November 18, 2023 +.Dd November 4, 2024 .Dt BSDINSTALL 8 .Os .Sh NAME .Nm bsdinstall .Nd system installer .Sh SYNOPSIS .Nm .Op Ar options .Op Ar target .Op Ar ... .Sh DESCRIPTION .Nm is used for installation of new systems, both for system setup from installation media, e.g., CD-ROMs, and for use on live systems to prepare VM images and jails. .Pp Much like .Xr make 1 , Nm takes a target and possible parameters of the target as arguments. If invoked with no arguments, it will invoke the .Cm auto target, which provides a standard interactive installation, invoking the others in sequence. To perform a scripted installation, these subtargets can be invoked separately by an installation script. .Sh OPTIONS .Nm supports the following options, global to all targets: .Bl -tag -width indent+ .It Fl D Ar file Provide a path for the installation log file .Pq overrides Ev BSDINSTALL_LOG . See .Sx ENVIRONMENT VARIABLES for more information on .Ev BSDINSTALL_LOG . .El .Sh TARGETS Most of the following targets are only useful for scripting the installer. For interactive use, most users will be interested only in the .Cm auto , .Cm jail , and .Cm script targets. .Bl -tag -width "jail destination" .It Cm auto Run the standard interactive installation, including disk partitioning. .It Cm jail Ar destination Sets up a new chroot system at .Pa destination , suitable for use with .Xr jail 8 . Behavior is generally similar to .Cm auto , except that disk partitioning and network setup are skipped and a kernel is not installed into the new system. .It Cm script Ar script Runs the installation script at .Pa script . See .Sx SCRIPTING for more information on this target. .It Cm keymap If the current controlling TTY is a .Xr syscons 4 or .Xr vt 4 console, asks the user to set the current keymap, and saves the result to the new system's .Pa rc.conf . .It Cm hostname Prompts the user for a host name for the new system and saves the result to the new system's .Pa rc.conf . If .Ev BSDINSTALL_CONFIGCURRENT is set, also sets the host name of the current system. .It Cm netconfig Interactively configures network interfaces (first invoking .Cm wlanconfig on wireless interfaces), saving the result to the new system's .Pa rc.conf and .Pa resolv.conf . If .Ev BSDINSTALL_CONFIGCURRENT is set, also configures the network interfaces of the current system to match. .It Cm autopart Provides the installer's interactive guided disk partitioner for single-disk installations. Defaults to UFS. .It Cm bootconfig Detects an appropriate partition and installs UEFI boot loader files. .It Cm zfsboot Provides a ZFS-only automatic interactive disk partitioner. Creates a single .Ic zpool with separate datasets for .Pa /home , .Pa /tmp , .Pa /usr , .Pa /usr/ports , .Pa /usr/src , and .Pa /var . Optionally can set up .Xr geli 8 to encrypt the disk. .It Cm partedit Provides the installer's interactive manual disk partitioner with an interface identical to .Xr sade 8 . Supports multiple disks as well as UFS, ZFS, and FAT file systems. ZFS is set up with one pool and dataset per partition. .It Cm scriptedpart Ar parameters Sets up disks like .Cm autopart and .Cm partedit , but non-interactively according to the disk setup specified in .Ar parameters . Each disk setup is specified by a three-part argument: .Pp .Ar disk .Op Ar scheme .Op Ar {partitions} .Pp Multiple disk setups are separated by semicolons. The .Ar disk argument specifies the disk on which to operate (which will be erased), or the special value .Em DEFAULT , which will result in either a selection window (as in .Cm autopart ) for the destination disk or, if there is only one possible disk, will automatically select it. The .Ar scheme argument specifies the .Xr gpart 8 partition scheme to apply to the disk. If .Ar scheme is unspecified, .Cm scriptedpart will apply the default bootable scheme on your platform. The .Ar partitions argument is also optional and specifies how to partition .Ar disk . It consists of a comma-separated list of partitions to create enclosed in curly braces. Each partition declaration takes the form .Pp .Ar size .Ar type .Op Ar mount point .Pp .Ar size specifies the partition size to create in bytes (K, M, and G suffixes can be appended to specify kilobytes, megabytes, and gigabytes respectively), while the .Em auto keyword causes the partition to take all the remaining space on the disk. The .Ar type option chooses the .Xr gpart 8 filesystem type, e.g., freebsd-ufs, freebsd-zfs, or freebsd-swap. The optional .Ar mount point argument sets where the created partition is to be mounted in the installed system. As an example, a typical invocation looks like: .Pp bsdinstall scriptedpart ada0 { 20G freebsd-ufs /, 4G freebsd-swap, 20G freebsd-ufs /var, auto freebsd-ufs /usr } .Pp Note that the list of partitions should .Em not include boot partitions (e.g. EFI system partitions), which will be created automatically on whatever disk includes /. .Pp A shorter invocation to use the default partitioning (as .Cm autopart would have used) on the same disk: .Pp bsdinstall scriptedpart ada0 .Pp or, even shorter: .Pp bsdinstall scriptedpart DEFAULT .It Cm mount Mounts the file systems previously configured by .Cm autopart , .Cm partedit , or .Cm scriptedpart under .Ev BSDINSTALL_CHROOT . .It Cm distfetch Fetches the distributions in .Ev DISTRIBUTIONS to .Ev BSDINSTALL_DISTDIR from .Ev BSDINSTALL_DISTSITE . .It Cm checksum Verifies the checksums of the distributions listed in .Ev DISTRIBUTIONS against the distribution manifest. .It Cm distextract Extracts the distributions listed in .Ev DISTRIBUTIONS into .Ev BSDINSTALL_CHROOT . +.It Cm firmware +executes +.Xr fwget 8 +inside the +.Ev BSDINSTALL_CHROOT +to install any needed and available firmware for the new system. .It Cm rootpass Interactively invokes .Xr passwd 1 in the new system to set the root user's password. .It Cm adduser Interactively invokes .Xr adduser 8 in the new system. .It Cm time Interactively sets the time, date, and time zone of the new system. .It Cm services Queries the user for the system daemons to begin at system startup, writing the result into the new system's .Pa rc.conf . .It Cm entropy Reads a small amount of data from .Pa /dev/random and stores it in a file in the new system's root directory. .It Cm config Installs the configuration files destined for the new system, e.g., .Xr rc.conf 5 fragments generated by .Cm netconfig , etc.) onto the new system. .El .Sh ENVIRONMENT VARIABLES The following environment variables control various aspects of the installation process. Many are used internally during installation and have reasonable default values for most installation scenarios. Others are set by various interactive user prompts, and can be usefully overridden when making scripted or customized installers. .Bl -tag -width "BSDINSTALL_DISTSITE" .It Ev TMPDIR The directory to use for temporary files. Default: .Dq Pa /tmp .It Ev DISTRIBUTIONS The set of distributions to install, e.g., "base.txz kernel.txz ports.txz". Default: unset .It Ev PARTITIONS The partitioning of the disk onto which the system is being installed. See .Cm scriptedpart of the .Sx TARGETS section for format details. If this variable is unset, the installer will use the default partitioning as in .Cm autopart . Default: unset .It Ev BSDINSTALL_DISTDIR The directory in which the distribution files can be found (or to which they should be downloaded). Default: .Dq Pa /usr/freebsd-dist .It Ev BSDINSTALL_DISTSITE URL from which the distribution files should be downloaded if they are not already present in the directory defined by .Ev BSDINSTALL_DISTDIR . This should be a full path to the files, including architecture and release names. Most targets, e.g., .Cm auto and .Cm jail , that prompt for a .Fx mirror will skip that step if this variable is already defined in the environment. Example: .Pa https://download.freebsd.org/ftp/releases/powerpc/powerpc64/13.1-RELEASE/ or .Pa http://ftp-archive.freebsd.org/pub/FreeBSD-Archive/old-releases/amd64/12.2-RELEASE/ . .It Ev BSDINSTALL_CHROOT The directory into which the distribution files should be unpacked and the directory at which the root file system of the new system should be mounted. Default: .Dq Pa /mnt .It Ev BSDINSTALL_LOG Path to a log file for the installation. Default: .Dq Pa $TMPDIR/bsdinstall_log +.It Ev BSDINSTALL_SKIP_FIRMWARE +If not empty, the +.Cm auto +target +will not invoke the +.Cm firmware +target. .It Ev BSDINSTALL_SKIP_HARDENING If not empty, the .Cm auto target will not invoke the .Cm hardening target. .It Ev BSDINSTALL_SKIP_HOSTNAME If not empty, the .Cm auto target will not invoke the .Cm hostname target. .It Ev BSDINSTALL_SKIP_KEYMAP If not empty, the .Cm auto target will not invoke the .Cm keymap target. .It Ev BSDINSTALL_SKIP_MANUAL If not empty, the .Cm auto target will not offer to open a shell in the new system for final manual modifications. .It Ev BSDINSTALL_SKIP_SERVICES If not empty, the .Cm auto target will not invoke the .Cm services target. .It Ev BSDINSTALL_SKIP_TIME If not empty, the .Cm auto target will not invoke the .Cm time target. .It Ev BSDINSTALL_SKIP_USERS If not empty, the .Cm auto target will not invoke the .Cm adduser target. .It Ev BSDINSTALL_SKIP_FINALCONFIG If not empty, the .Cm auto target will not show the final configuration dialog, where earlier configuration choices can be revisited. .It Ev BSDINSTALL_TMPETC Directory where files destined for the new system's .Pa /etc will be stored until the .Cm config target is executed. If this directory does not already exist, it will be created. Default: .Dq Pa $TMPDIR/bsdinstall_etc .It Ev BSDINSTALL_TMPBOOT Directory where files destined for the new system's .Pa /boot will be stored until the .Cm config target is executed. If this directory does not already exist, it will be created. Default: .Dq Pa $TMPDIR/bsdinstall_boot .It Ev ROOTPASS_ENC Encrypted string to set the root password to in the format expected by .Xr pw 8 .Fl H Ar 0 . This option is used if both it and .Ev ROOTPASS_PLAIN are set. .It Ev ROOTPASS_PLAIN Plain text string to set the root password to. .It Ev ZFSBOOT_POOL_NAME Name for the pool containing the base system. Default: .Dq zroot .It Ev ZFSBOOT_POOL_CREATE_OPTIONS Options to be used when creating the base system's pool. Each option must be preceded by the -O flag to be taken into consideration or the pool will not be created due to errors using the command .Cm zpool . Default: .Dq Li "-O compress=lz4 -O atime=off" .It Ev ZFSBOOT_BEROOT_NAME Name for the boot environment parent dataset. This is a non-mountable dataset meant to be a parent dataset where different boot environment are going to be created. Default: .Dq ROOT .It Ev ZFSBOOT_BOOTFS_NAME Name for the primary boot environment, which will be the default boot environment for the system. Default: .Dq default .It Ev ZFSBOOT_VDEV_TYPE The type of pool to be created for the base system. This variable can take one of this values: stripe (No redundancy), mirror (n-Way mirroring), raid10 (RAID 1+0 - n x 2-Way Mirrors), raidz1 (RAID-Z1 - Single Redundancy RAID), raidz2 (RAID-Z2 - Double Redundancy RAID) or raidz3 (RAID-Z3 Triple Redundancy RAID). Default: .Dq stripe .It Ev ZFSBOOT_FORCE_4K_SECTORS Controls the minimum sector size of the pool. If this variable is not empty, the minimum sector size is 4K. If this variable is empty, the minimum sector size is 512. Note that the sector size of the pool will always be at least the sector size of the backing disks. Default: .Dq 1 .It Ev ZFSBOOT_GELI_ENCRYPTION If this variable is not empty, it will use .Xr geli 8 to encrypt the root pool, enabling automatically the .Ev ZFSBOOT_BOOT_POOL variable. Default: .Dq "" .It Ev ZFSBOOT_GELI_KEY_FILE Path to the .Xr geli 8 keyfile used to encrypt the pool where the base system is stored. Default: .Dq Pa /boot/encryption.key .It Ev ZFSBOOT_BOOT_POOL If set, a separated boot pool will be created for the kernel of the system and .Xr loader 8 . Default: unset .It Ev ZFSBOOT_BOOT_POOL_CREATE_OPTIONS Options to use when creating the boot pool, when enabled (See .Ev ZFSBOOT_BOOT_POOL ). Default: unset .It Ev ZFSBOOT_BOOT_POOL_NAME Name for the optional boot pool when it is enabled, (See .Ev ZFSBOOT_BOOT_POOL ). Default: .Dq bootpool .It Ev ZFSBOOT_BOOT_POOL_SIZE Size of the boot pool when it is enabled (See .Ev ZFSBOOT_BOOT_POOL ). Default: .Dq 2g .It Ev ZFSBOOT_DISKS Disks to be used for the base system, including the boot pool. This variable must only be used on a scripted installation. See .Sx SCRIPTING for more information. Default: unset .It Ev ZFSBOOT_SWAP_SIZE Size of the swap partition on each block device. This variable will be passed to .Xr gpart 8 ; which supports SI unit suffixes. Default: .Dq 2g .It Ev ZFSBOOT_SWAP_ENCRYPTION If set, enables the encryption of the swap partition using .Xr geli 8 . Default: "" .It Ev ZFSBOOT_SWAP_MIRROR If set, enables a swap mirroring using .Xr gmirror 8 . Default: unset .It Ev ZFSBOOT_DATASETS ZFS datasets to be created on the root zpool, it requires the following datasets: .Pa /tmp , .Pa /var/tmp , .Pa /$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOTFS_NAME . See .Sx ZFS DATASETS for more information about how to populate this variable and its default value. .It Ev ZFSBOOT_CONFIRM_LAYOUT If set and the installation is interactive, allow the user to confirm the layout before continuing with the installation. Default: .Dq 1 .El .Sh SCRIPTING .Nm supports unattended, or minimally-attended, installations using scripting. This can be used with either modified physical installation media or with .Xr diskless 8 installations over the network; information on preparing such media can be found in .Sx BUILDING AUTOMATIC INSTALL MEDIA .Pp Scripted installations follow an essentially identical path to interactive installations, though with some minor feature differences (for example, scripted installations do not support fetching of remote distribution files since scripted installations normally install the same files and the distributions can be added directly to the installation media). .Nm scripts consist of two parts: a .Em preamble and a .Em setup script . The preamble sets up the options for the installation (how to partition the disk[s], which distributions to install, etc.) and the optional second part is a shell script run under .Xr chroot 8 in the newly installed system before .Nm exits. The two parts are separated by the usual script header (#!), which also sets the interpreter for the setup script. .Pp 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" #!/bin/sh sysrc ifconfig_DEFAULT=DHCP sysrc sshd_enable=YES pkg install 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" export ZFSBOOT_VDEV_TYPE=stripe export ZFSBOOT_DISKS="ada0 ada1" export nonInteractive="YES" #!/bin/sh echo "ifconfig_DEFAULT=DHCP" >> /etc/rc.conf echo "sshd_enable=YES" >> /etc/rc.conf pkg install puppet .Ed .Pp On .Fx release media, such a script placed at .Pa /etc/installerconfig will be run at boot time and the system will be rebooted automatically after the installation has completed. This can be used for unattended network installation of new systems; see .Xr diskless 8 for details. .Ss PREAMBLE The preamble consists of installer settings. These control global installation parameters (see .Sx ENVIRONMENT VARIABLES ) as well as disk partitioning. The preamble is interpreted as a .Xr sh 1 script run at the very beginning of the install. If more complicated behavior than setting these variables is desired, arbitrary commands can be run here to extend the installer. In addition to the variables in .Sx ENVIRONMENT VARIABLES , in particular .Ev DISTRIBUTIONS , the preamble can contain a variable .Ev PARTITIONS which is passed to the .Cm scriptedpart target to control disk setup. .Pp Alternatively, to use .Cm zfsboot instead of .Cm partedit , the preamble can contain the variable .Ev ZFSBOOT_DATASETS instead of .Ev PARTITIONS (see below). If using .Cm zfsboot , the variables .Ev ZFSBOOT_DISKS and .Ev ZFSBOOT_VDEV_TYPE must be set to create the pool of disks for the base system. Usually, for a mirrored booting disk, these two variables look like this: .Bd -literal -offset indent ZFSBOOT_DISKS="ada0 ada1" ZFSBOOT_VDEV_TYPE=mirror .Ed .Pp Remember to export all the variables for the .Cm zfsboot command, otherwise installation will fail. .Ss SETUP SCRIPT Following the preamble is an optional shell script, beginning with a #! declaration. This script will be run at the end of the installation process inside a .Xr chroot 8 environment in the newly installed system and can be used to set up configuration files, install packages, etc. Note that newly configured system services, e.g., networking have not been started in the installed system at this time and only installation host services are available. .Ss ZFS DATASETS If using .Cm zfsboot in an installation script, the .Cm zfsboot partitioning tool takes the .Ev ZFSBOOT_DATASETS variable to create the ZFS datasets on the base system. This variable definition can become large if the pool contains many datasets. The default value of .Ev ZFSBOOT_DATASETS is: .Bd -literal -offset indent # DATASET OPTIONS (comma or space separated; or both) # Boot Environment [BE] root and default boot dataset /$ZFSBOOT_BEROOT_NAME mountpoint=none /$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOTFS_NAME mountpoint=/ # Home directories separated so they are common to all BEs /home mountpoint=/home # Compress /tmp, allow exec but not setuid /tmp mountpoint=/tmp,exec=on,setuid=off # Do not mount /usr so that 'base' files go to the BEROOT /usr mountpoint=/usr,canmount=off # Ports tree /usr/ports setuid=off # Source tree (compressed) /usr/src # Create /var and friends /var mountpoint=/var,canmount=off /var/audit exec=off,setuid=off /var/crash exec=off,setuid=off /var/log exec=off,setuid=off /var/mail atime=on /var/tmp setuid=off .Ed .Pp The first column is the name of the dataset to be created as part of the .Ev ZFSBOOT_POOL_NAME pool and the remainder of each line contains the options to be set on each dataset. If multiple options are given, they can be separated by either commas or whitespace; everything following a pound/hash character is ignored as a comment. .Ss BUILDING AUTOMATIC INSTALL MEDIA If building automatic install media, use tar to extract a release ISO: .Dl mkdir release-media .Dl tar -C release-media -xvf FreeBSD-13.0-RELEASE-amd64-disc1.iso .Pp Then place a script as above in .Pa etc/installerconfig .Pp This directory can then be used directly as an NFS root for .Xr diskless 8 installations or it can be rebuilt into an ISO image using the release scripts in .Pa /usr/src/release . For example, on amd64: .Dl sh /usr/src/release/amd64/mkisoimages.sh -b '13_0_RELEASE_AMD64_CD' output.iso release-media .Sh HISTORY This version of .Nm first appeared in .Fx 9.0 . .Sh AUTHORS .An Nathan Whitehorn Aq Mt nwhitehorn@FreeBSD.org .An Devin Teske Aq Mt dteske@FreeBSD.org .An Allan Jude Aq Mt allanjude@FreeBSD.org diff --git a/usr.sbin/bsdinstall/scripts/Makefile b/usr.sbin/bsdinstall/scripts/Makefile index 0ac511120103..f3b9f07ed376 100644 --- a/usr.sbin/bsdinstall/scripts/Makefile +++ b/usr.sbin/bsdinstall/scripts/Makefile @@ -1,31 +1,32 @@ SCRIPTS=auto \ adduser \ bootconfig \ checksum \ config \ docsinstall \ entropy \ fetchmissingdists \ finalconfig \ + firmware \ hardening \ hostname \ jail \ keymap \ mirrorselect \ mount \ netconfig \ netconfig_ipv4 \ netconfig_ipv6 \ rootpass \ script \ services \ time \ umount \ wlanconfig \ zfsboot BINDIR= ${LIBEXECDIR}/bsdinstall MAN= .include diff --git a/usr.sbin/bsdinstall/scripts/auto b/usr.sbin/bsdinstall/scripts/auto index 9f4b5b52fe5d..7d041be015e7 100755 --- a/usr.sbin/bsdinstall/scripts/auto +++ b/usr.sbin/bsdinstall/scripts/auto @@ -1,404 +1,405 @@ #!/bin/sh #- # Copyright (c) 2011 Nathan Whitehorn # Copyright (c) 2013-2018 Devin Teske # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # ############################################################ INCLUDES BSDCFG_SHARE="/usr/share/bsdconfig" . $BSDCFG_SHARE/common.subr || exit 1 f_include $BSDCFG_SHARE/dialog.subr ############################################################ GLOBALS # # Strings that should be moved to an i18n file and loaded with f_include_lang() # hline_arrows_tab_enter="Press arrows, TAB or ENTER" hline_arrows_tab_space_enter="Press arrows, TAB, SPACE or ENTER" msg_abort="Abort" msg_an_installation_step_has_been_aborted="An installation step has been aborted. Would you like\nto restart the installation or exit the installer?" msg_auto_ufs="Auto (UFS)" msg_auto_ufs_desc="Guided UFS Disk Setup" msg_auto_ufs_help="Menu options help choose which disk to setup using UFS and standard partitions" msg_auto_zfs="Auto (ZFS)" msg_auto_zfs_desc="Guided Root-on-ZFS" msg_auto_zfs_help="To use ZFS with less than 8GB RAM, see https://wiki.freebsd.org/ZFSTuningGuide" msg_exit="Exit" msg_freebsd_installer="$OSNAME Installer" msg_gpt_active_fix="Your hardware is known to have issues booting in CSM/Legacy/BIOS mode from GPT partitions that are not set active. Would you like the installer to apply this workaround for you?" msg_lenovo_fix="Your model of Lenovo is known to have a BIOS bug that prevents it booting from GPT partitions without UEFI. Would you like the installer to apply a workaround for you?" msg_manual="Manual" msg_manual_desc="Manual Disk Setup (experts)" msg_manual_help="Create customized partitions from menu options" msg_no="NO" msg_restart="Restart" msg_shell="Shell" msg_shell_desc="Open a shell and partition by hand" msg_shell_help="Create customized partitions using command-line utilities" msg_yes="YES" ############################################################ FUNCTIONS # error [$msg] # # Display generic error message when a script fails. An optional message # argument can preceed the generic message. User is given the choice of # restarting the installer or exiting. # error() { local title="$msg_abort" local btitle="$msg_freebsd_installer" local prompt="${1:+$1\n\n}$msg_an_installation_step_has_been_aborted" local hline="$hline_arrows_tab_space_enter" [ -f "$PATH_FSTAB" ] && bsdinstall umount local height width f_dialog_buttonbox_size height width \ "$title" "$btitle" "$prompt" "$hline" if $DIALOG \ --title "$title" \ --backtitle "$btitle" \ --hline "$hline" \ --no-label "$msg_exit" \ --yes-label "$msg_restart" \ --yesno "$prompt" $height $width then exec $0 # NOTREACHED fi exit 1 } # dialog_workaround # # Ask the user if they wish to apply a workaround # dialog_workaround() { local passed_msg="$1" local title="$DIALOG_TITLE" local btitle="$DIALOG_BACKTITLE" local prompt # Calculated below local hline="$hline_arrows_tab_enter" local height=8 width=50 prefix=" " local plen=${#prefix} list= line= local max_width=$(( $width - 3 - $plen )) local yes no defaultno extra_args format if [ "$USE_XDIALOG" ]; then yes=ok no=cancel defaultno=default-no extra_args="--wrap --left" format="$passed_msg" else yes=yes no=no defaultno=defaultno extra_args="--cr-wrap" format="$passed_msg" fi # Add height for Xdialog(1) [ "$USE_XDIALOG" ] && height=$(( $height + $height / 5 + 3 )) prompt=$( printf "$format" ) f_dprintf "%s: Workaround prompt" "$0" $DIALOG \ --title "$title" \ --backtitle "$btitle" \ --hline "$hline" \ --$yes-label "$msg_yes" \ --$no-label "$msg_no" \ $extra_args \ --yesno "$prompt" $height $width } ############################################################ MAIN f_dprintf "Began Installation at %s" "$( date )" rm -rf $BSDINSTALL_TMPETC mkdir $BSDINSTALL_TMPETC [ -f /usr/libexec/bsdinstall/local.pre-everything ] && f_dprintf "Running local.pre-everything" && sh /usr/libexec/bsdinstall/local.pre-everything "$BSDINSTALL_CHROOT" trap true SIGINT # This section is optional [ -z "$BSDINSTALL_SKIP_KEYMAP" ] && bsdinstall keymap trap error SIGINT # Catch cntrl-C here if [ -z "$BSDINSTALL_SKIP_HOSTNAME" ]; then bsdinstall hostname || error "Set hostname failed"; fi export DISTRIBUTIONS="${DISTRIBUTIONS:-base.txz kernel.txz}" if [ -f $BSDINSTALL_DISTDIR/MANIFEST ]; then DISTMENU=`awk -F'\t' '!/^(kernel\.txz|base\.txz)/{print $1,$5,$6}' $BSDINSTALL_DISTDIR/MANIFEST` DISTMENU="$(echo ${DISTMENU} | sed -E 's/\.txz//g')" if [ -n "$DISTMENU" ]; then exec 5>&1 EXTRA_DISTS=$( eval bsddialog \ --backtitle \"$OSNAME Installer\" \ --title \"Distribution Select\" --nocancel --separate-output \ --checklist \"Choose optional system components to install:\" \ 0 0 0 $DISTMENU \ 2>&1 1>&5 ) for dist in $EXTRA_DISTS; do export DISTRIBUTIONS="$DISTRIBUTIONS $dist.txz" done fi fi FETCH_DISTRIBUTIONS="" for dist in $DISTRIBUTIONS; do if [ ! -f $BSDINSTALL_DISTDIR/$dist ]; then FETCH_DISTRIBUTIONS="$FETCH_DISTRIBUTIONS $dist" fi done if [ -n "$FETCH_DISTRIBUTIONS" -a -n "$BSDINSTALL_CONFIGCURRENT" ]; then bsddialog --backtitle "$OSNAME Installer" --title "Network Installation" --msgbox "Some installation files were not found on the boot volume. The next few screens will allow you to configure networking so that they can be downloaded from the Internet." 0 0 bsdinstall netconfig || error NETCONFIG_DONE=yes fi rm -f $PATH_FSTAB touch $PATH_FSTAB [ -f /usr/libexec/bsdinstall/local.pre-partition ] && f_dprintf "Running local.pre-partition" && sh /usr/libexec/bsdinstall/local.pre-partition "$BSDINSTALL_CHROOT" # # Try to detect known broken platforms and apply their workarounds # if f_interactive; then sys_maker=$( kenv -q smbios.system.maker ) f_dprintf "smbios.system.maker=[%s]" "$sys_maker" sys_model=$( kenv -q smbios.system.product ) f_dprintf "smbios.system.product=[%s]" "$sys_model" sys_version=$( kenv -q smbios.system.version ) f_dprintf "smbios.system.version=[%s]" "$sys_version" sys_mb_maker=$( kenv -q smbios.planar.maker ) f_dprintf "smbios.planar.maker=[%s]" "$sys_mb_maker" sys_mb_product=$( kenv -q smbios.planar.product ) f_dprintf "smbios.planar.product=[%s]" "$sys_mb_product" # # Laptop Models # case "$sys_maker" in "LENOVO") case "$sys_version" in "ThinkPad X220"|"ThinkPad T420"|"ThinkPad T520"|"ThinkPad W520"|"ThinkPad X1") dialog_workaround "$msg_lenovo_fix" retval=$? f_dprintf "lenovofix_prompt=[%s]" "$retval" if [ $retval -eq $DIALOG_OK ]; then export ZFSBOOT_PARTITION_SCHEME="GPT + Lenovo Fix" export WORKAROUND_LENOVO=1 fi ;; esac ;; "Dell Inc.") case "$sys_model" in "Latitude E6330"|"Latitude E7440"|"Latitude E7240"|"Precision Tower 5810") dialog_workaround "$msg_gpt_active_fix" retval=$? f_dprintf "gpt_active_fix_prompt=[%s]" "$retval" if [ $retval -eq $DIALOG_OK ]; then export ZFSBOOT_PARTITION_SCHEME="GPT + Active" export WORKAROUND_GPTACTIVE=1 fi ;; esac ;; "Hewlett-Packard") case "$sys_model" in "HP ProBook 4330s") dialog_workaround "$msg_gpt_active_fix" retval=$? f_dprintf "gpt_active_fix_prompt=[%s]" "$retval" if [ $retval -eq $DIALOG_OK ]; then export ZFSBOOT_PARTITION_SCHEME="GPT + Active" export WORKAROUND_GPTACTIVE=1 fi ;; esac ;; esac # # Motherboard Models # case "$sys_mb_maker" in "Intel Corporation") case "$sys_mb_product" in "DP965LT"|"D510MO") dialog_workaround "$msg_gpt_active_fix" retval=$? f_dprintf "gpt_active_fix_prompt=[%s]" "$retval" if [ $retval -eq $DIALOG_OK ]; then export ZFSBOOT_PARTITION_SCHEME="GPT + Active" export WORKAROUND_GPTACTIVE=1 fi ;; esac ;; "Acer") case "$sys_mb_product" in "Veriton M6630G") dialog_workaround "$msg_gpt_active_fix" retval=$? f_dprintf "gpt_active_fix_prompt=[%s]" "$retval" if [ $retval -eq $DIALOG_OK ]; then export ZFSBOOT_PARTITION_SCHEME="GPT + Active" export WORKAROUND_GPTACTIVE=1 fi ;; esac ;; esac fi PMODES=" '$msg_auto_ufs' '$msg_auto_ufs_desc' '$msg_auto_ufs_help' '$msg_manual' '$msg_manual_desc' '$msg_manual_help' '$msg_shell' '$msg_shell_desc' '$msg_shell_help' " # END-QUOTE CURARCH=$( uname -m ) case $CURARCH in amd64|arm64|i386|riscv) # Booting ZFS Supported PMODES=" '$msg_auto_zfs' '$msg_auto_zfs_desc' '$msg_auto_zfs_help' $PMODES " # END-QUOTE ;; *) # Booting ZFS Unsupported ;; esac exec 5>&1 PARTMODE=`echo $PMODES | xargs -o bsddialog --backtitle "$OSNAME Installer" \ --title "Partitioning" \ --item-help \ --menu "How would you like to partition your disk?" \ 0 0 0 2>&1 1>&5` || exit 1 exec 5>&- case "$PARTMODE" in "$msg_auto_zfs") # ZFS bsdinstall zfsboot || error "ZFS setup failed" bsdinstall mount || error "Failed to mount filesystem" ;; "$msg_auto_ufs") # Guided UFS bsdinstall autopart || error "Partitioning error" bsdinstall mount || error "Failed to mount filesystem" ;; "$msg_shell") # Shell clear echo "Use this shell to set up partitions for the new system. When finished, mount the system at $BSDINSTALL_CHROOT and place an fstab file for the new system at $PATH_FSTAB. Then type 'exit'. You can also enter the partition editor at any time by entering 'bsdinstall partedit'." sh 2>&1 ;; "$msg_manual") # Manual if f_isset debugFile; then # Give partedit the path to our logfile so it can append BSDINSTALL_LOG="${debugFile#+}" bsdinstall partedit || error "Partitioning error" else bsdinstall partedit || error "Partitioning error" fi bsdinstall mount || error "Failed to mount filesystem" ;; *) error "Unknown partitioning mode" ;; esac [ -f /usr/libexec/bsdinstall/local.pre-fetch ] && f_dprintf "Running local.pre-fetch" && sh /usr/libexec/bsdinstall/local.pre-fetch "$BSDINSTALL_CHROOT" if [ -n "$FETCH_DISTRIBUTIONS" ]; then exec 5>&1 export BSDINSTALL_DISTDIR=$(`dirname $0`/fetchmissingdists 2>&1 1>&5) FETCH_RESULT=$? exec 5>&- [ $FETCH_RESULT -ne 0 ] && error "Could not fetch remote distributions" fi bsdinstall checksum || error "Distribution checksum failed" bsdinstall distextract || error "Distribution extract failed" # Set up boot loader bsdinstall bootconfig || error "Failed to configure bootloader" [ -f /usr/libexec/bsdinstall/local.pre-configure ] && f_dprintf "Running local.pre-configure" && sh /usr/libexec/bsdinstall/local.pre-configure "$BSDINSTALL_CHROOT" bsdinstall rootpass || error "Could not set root password" trap true SIGINT # This section is optional if [ "$NETCONFIG_DONE" != yes ]; then bsdinstall netconfig # Don't check for errors -- the user may cancel fi [ -z "$BSDINSTALL_SKIP_TIME" ] && bsdinstall time [ -z "$BSDINSTALL_SKIP_SERVICES" ] && bsdinstall services [ -z "$BSDINSTALL_SKIP_HARDENING" ] && bsdinstall hardening +[ -z "$BSDINSTALL_SKIP_FIRMWARE" ] && bsdinstall firmware [ -z "$BSDINSTALL_SKIP_USERS" ] && bsddialog --backtitle "$OSNAME Installer" \ --title "Add User Accounts" --yesno \ "Would you like to add users to the installed system now?" 0 0 && \ bsdinstall adduser # Allow user to change his mind [ -z "$BSDINSTALL_SKIP_FINALCONFIG" ] && bsdinstall finalconfig trap error SIGINT # SIGINT is bad again bsdinstall config || error "Failed to save config" if [ ! -z "$BSDINSTALL_FETCHDEST" ]; then rm -rf "$BSDINSTALL_FETCHDEST" fi [ -f /usr/libexec/bsdinstall/local.post-configure ] && f_dprintf "Running local.post-configure" && sh /usr/libexec/bsdinstall/local.post-configure "$BSDINSTALL_CHROOT" if [ -z "$BSDINSTALL_SKIP_MANUAL" ]; then bsddialog --backtitle "$OSNAME Installer" --title "Manual Configuration" \ --default-no --yesno \ "The installation is now finished. Before exiting the installer, would you like to open a shell in the new system to make any final manual modifications?" 0 0 if [ $? -eq 0 ]; then clear echo This shell is operating in a chroot in the new system. \ When finished making configuration changes, type \"exit\". chroot "$BSDINSTALL_CHROOT" /bin/sh 2>&1 fi fi bsdinstall entropy bsdinstall umount f_dprintf "Installation Completed at %s" "$( date )" ################################################################################ # END ################################################################################ diff --git a/usr.sbin/bsdinstall/scripts/finalconfig b/usr.sbin/bsdinstall/scripts/finalconfig index d7c4a1569d39..68ee16a5330d 100755 --- a/usr.sbin/bsdinstall/scripts/finalconfig +++ b/usr.sbin/bsdinstall/scripts/finalconfig @@ -1,82 +1,86 @@ #!/bin/sh #- # Copyright (c) 2011 Nathan Whitehorn # Copyright (c) 2013-2018 Devin Teske # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # $FreeBSD$ BSDCFG_SHARE="/usr/share/bsdconfig" . $BSDCFG_SHARE/common.subr || exit 1 : ${BSDDIALOG_OK=0} while true; do exec 5>&1 REVISIT=$(bsddialog --backtitle "$OSNAME Installer" \ --title "Final Configuration" --ok-label "Select" \ --cancel-label "Finish" --default-no --menu \ "Setup of your $OSNAME system is nearly complete. You can now modify your configuration choices. After this screen, you will have an opportunity to make more complex changes using a shell." 0 0 0 \ "Add User" "Add a user to the system" \ "Root Password" "Change root password" \ "Hostname" "Set system hostname" \ "Network" "Networking configuration" \ "Services" "Set daemons to run on startup" \ "System Hardening" "Set security options" \ "Time Zone" "Set system timezone" \ + "Firmware" "Install Firmware (requires network)" \ "Handbook" "Install $OSNAME Handbook (requires network)" 2>&1 1>&5) retval=$? exec 5>&- if [ $retval -ne $BSDDIALOG_OK ]; then break fi case "$REVISIT" in "Add User") bsdinstall adduser ;; "Root Password") bsdinstall rootpass ;; "Hostname") bsdinstall hostname ;; "Network") bsdinstall netconfig ;; "Services") bsdinstall services ;; "System Hardening") bsdinstall hardening ;; "Time Zone") bsdinstall time ;; + "Firmware") + bsdinstall firmware + ;; "Handbook") bsdinstall docsinstall ;; esac done diff --git a/usr.sbin/bsdinstall/scripts/firmware b/usr.sbin/bsdinstall/scripts/firmware new file mode 100644 index 000000000000..a563f0e578e4 --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/firmware @@ -0,0 +1,125 @@ +#!/bin/sh +#- +# SPDX-License-Identifier: BSD-2-Clause +# +# Copyright (c) 2024 The FreeBSD Foundation +# +# This software was developed by Björn Zeeb +# under sponsorship from the FreeBSD Foundation. +# + +BSDCFG_SHARE="/usr/share/bsdconfig" +. $BSDCFG_SHARE/common.subr || exit 1 + +f_dprintf "%s: loading includes..." "$0" +f_include $BSDCFG_SHARE/dialog.subr +f_include $BSDCFG_SHARE/mustberoot.subr +f_include $BSDCFG_SHARE/packages/packages.subr + +msg_freebsd_firmware_installation="$OSNAME Firmware Installation" +msg_freebsd_installer="$OSNAME Installer" +msg_firmware_menu_text="This menu allows you to install firmware packages for your system" +hline_arrows_space_tab_enter="Use arrows, SPACE, TAB or ENTER" +hline_ok="Press OK to continue" + +dialog_menu_main() +{ + local title="$DIALOG_TITLE" + local btitle="$DIALOG_BACKTITLE" + local prompt="$msg_firmware_menu_text" + local hline + local check_list= # Empty; filled below + local fwlist _fw + + fwlist=`chroot $BSDINSTALL_CHROOT fwget -q -n` + case "${fwlist}" in + "") # No firmware to install + # Print a dialog with OK and a 3 line timeout bar. + local height width rows msg + + msg="No firmware to install, continuing..." + hline="$hline_ok" + + eval f_dialog_checklist_size height width rows \ + \"\$title\" \ + \"\$btitle\" \ + \"\$msg\" \ + \"-\" \ + \"n\" \ + \"-\" \ + \"\$hline\" + + ${DIALOG} --title "${title}" --backtitle "${btitle}" \ + --hline "${hline}" \ + --nocancel --pause "${msg}" $height $width 5 + f_dialog_menutag_store -s "" + return $DIALOG_OK + ;; + *) + local desc status height width rows selected retval + hline="$hline_arrows_space_tab_enter" + + for _fw in ${fwlist}; do + desc="${_fw}" + f_shell_escape "$desc" desc + # install each firmware package by default. + check_list="$check_list + '$_fw' '$desc' 'on' + " + done + + eval f_dialog_checklist_size height width rows \ + \"\$title\" \ + \"\$btitle\" \ + \"\$prompt\" \ + \"\$hline\" \ + $check_list + + selected=$( eval $DIALOG \ + --title \"\$title\" \ + --backtitle \"\$btitle\" \ + --separate-output \ + --hline \"\$hline\" \ + --ok-label \"\$msg_ok\" \ + --cancel-label \"\$msg_cancel\" \ + --checklist \"\$prompt\" \ + $height $width $rows \ + $check_list \ + 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD + ) + retval=$? + f_dialog_menutag_store -s "$selected" + return $retval + ;; + esac +} + +# Initialize +f_dialog_title "$msg_freebsd_firmware_installation" +f_dialog_backtitle "$msg_freebsd_installer" + +# Gather the firmware files and present them to the user +dialog_menu_main || f_die +f_dialog_menutag_fetch selected + +# Nothing to install? +if [ "${selected}" == "" ]; then + exit 0 +fi + +f_mustberoot_init + +# pkg(8) needs name servers (unless we could use a local repo in the future). +f_quietly cp -f $BSDINSTALL_TMPETC/resolv.conf $BSDINSTALL_CHROOT/etc/ + +${DIALOG} --title "$DIALOG_TITLE" --backtitle "$DIALOG_BACKTITLE" \ + --infobox "Installing firmware. This may take a moment." 0 0 + +# Install each of the selected firmware packages +for fw in ${selected}; do + # We install one at a time in case one is not avail. + # pkg-install.8 needs an option to skip unavail. + ASSUME_ALWAYS_YES=YES chroot $BSDINSTALL_CHROOT pkg install -qy ${fw} +done + +# end