1cd88b886SDevin Teske#!/bin/sh 2cd88b886SDevin Teske#- 37e3ebc5bSAllan Jude# Copyright (c) 2013-2015 Allan Jude 4febd9e9cSDevin Teske# Copyright (c) 2013-2015 Devin Teske 5cd88b886SDevin Teske# All rights reserved. 6cd88b886SDevin Teske# 7cd88b886SDevin Teske# Redistribution and use in source and binary forms, with or without 8cd88b886SDevin Teske# modification, are permitted provided that the following conditions 9cd88b886SDevin Teske# are met: 10cd88b886SDevin Teske# 1. Redistributions of source code must retain the above copyright 11cd88b886SDevin Teske# notice, this list of conditions and the following disclaimer. 12cd88b886SDevin Teske# 2. Redistributions in binary form must reproduce the above copyright 13cd88b886SDevin Teske# notice, this list of conditions and the following disclaimer in the 14cd88b886SDevin Teske# documentation and/or other materials provided with the distribution. 15cd88b886SDevin Teske# 16cd88b886SDevin Teske# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17cd88b886SDevin Teske# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18cd88b886SDevin Teske# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19cd88b886SDevin Teske# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20cd88b886SDevin Teske# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21cd88b886SDevin Teske# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22cd88b886SDevin Teske# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23cd88b886SDevin Teske# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24cd88b886SDevin Teske# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25cd88b886SDevin Teske# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26cd88b886SDevin Teske# SUCH DAMAGE. 27cd88b886SDevin Teske# 28cd88b886SDevin Teske# $FreeBSD$ 29cd88b886SDevin Teske# 30cd88b886SDevin Teske############################################################ INCLUDES 31cd88b886SDevin Teske 32cd88b886SDevin TeskeBSDCFG_SHARE="/usr/share/bsdconfig" 33cd88b886SDevin Teske. $BSDCFG_SHARE/common.subr || exit 1 34cd88b886SDevin Teskef_dprintf "%s: loading includes..." "$0" 35cd88b886SDevin Teskef_include $BSDCFG_SHARE/device.subr 36cd88b886SDevin Teskef_include $BSDCFG_SHARE/dialog.subr 37cd88b886SDevin Teskef_include $BSDCFG_SHARE/password/password.subr 38cd88b886SDevin Teskef_include $BSDCFG_SHARE/variable.subr 39cd88b886SDevin Teske 40cd88b886SDevin Teske############################################################ CONFIGURATION 41cd88b886SDevin Teske 42cd88b886SDevin Teske# 43cd88b886SDevin Teske# Default name of the boot-pool 44cd88b886SDevin Teske# 45cd88b886SDevin Teske: ${ZFSBOOT_POOL_NAME:=zroot} 46cd88b886SDevin Teske 47cd88b886SDevin Teske# 4847206692SDevin Teske# Default options to use when creating zroot pool 4947206692SDevin Teske# 5047206692SDevin Teske: ${ZFSBOOT_POOL_CREATE_OPTIONS:=-O compress=lz4 -O atime=off} 5147206692SDevin Teske 5247206692SDevin Teske# 53cd88b886SDevin Teske# Default name for the boot environment parent dataset 54cd88b886SDevin Teske# 5567635c19SDevin Teske: ${ZFSBOOT_BEROOT_NAME:=ROOT} 56cd88b886SDevin Teske 57cd88b886SDevin Teske# 58cd88b886SDevin Teske# Default name for the primany boot environment 59cd88b886SDevin Teske# 60cd88b886SDevin Teske: ${ZFSBOOT_BOOTFS_NAME:=default} 61cd88b886SDevin Teske 62cd88b886SDevin Teske# 63cd88b886SDevin Teske# Default Virtual Device (vdev) type to create 64cd88b886SDevin Teske# 65cd88b886SDevin Teske: ${ZFSBOOT_VDEV_TYPE:=stripe} 66cd88b886SDevin Teske 67cd88b886SDevin Teske# 68b4843bd6SSteven Hartland# Should we use sysctl(8) vfs.zfs.min_auto_ashift=12 to force 4K sectors? 69cd88b886SDevin Teske# 70b4843bd6SSteven Hartland: ${ZFSBOOT_FORCE_4K_SECTORS:=1} 71cd88b886SDevin Teske 72cd88b886SDevin Teske# 73cd88b886SDevin Teske# Should we use geli(8) to encrypt the drives? 747cae6aabSDevin Teske# NB: Automatically enables ZFSBOOT_BOOT_POOL 75cd88b886SDevin Teske# 76bc4a673fSDevin Teske: ${ZFSBOOT_GELI_ENCRYPTION=} 77cd88b886SDevin Teske 78cd88b886SDevin Teske# 79cd88b886SDevin Teske# Default path to the geli(8) keyfile used in drive encryption 80cd88b886SDevin Teske# 81cd88b886SDevin Teske: ${ZFSBOOT_GELI_KEY_FILE:=/boot/encryption.key} 82cd88b886SDevin Teske 83cd88b886SDevin Teske# 847cae6aabSDevin Teske# Create a separate boot pool? 857cae6aabSDevin Teske# NB: Automatically set when using geli(8) or MBR 867cae6aabSDevin Teske# 877cae6aabSDevin Teske: ${ZFSBOOT_BOOT_POOL=} 887cae6aabSDevin Teske 897cae6aabSDevin Teske# 9047206692SDevin Teske# Options to use when creating separate boot pool (if any) 9147206692SDevin Teske# 9247206692SDevin Teske: ${ZFSBOOT_BOOT_POOL_CREATE_OPTIONS:=} 9347206692SDevin Teske 9447206692SDevin Teske# 957cae6aabSDevin Teske# Default name for boot pool when enabled (e.g., geli(8) or MBR) 967cae6aabSDevin Teske# 977cae6aabSDevin Teske: ${ZFSBOOT_BOOT_POOL_NAME:=bootpool} 987cae6aabSDevin Teske 997cae6aabSDevin Teske# 1007cae6aabSDevin Teske# Default size for boot pool when enabled (e.g., geli(8) or MBR) 1017cae6aabSDevin Teske# 1027cae6aabSDevin Teske: ${ZFSBOOT_BOOT_POOL_SIZE:=2g} 1037cae6aabSDevin Teske 1047cae6aabSDevin Teske# 105cd88b886SDevin Teske# Default disks to use (always empty unless being scripted) 106cd88b886SDevin Teske# 107cd88b886SDevin Teske: ${ZFSBOOT_DISKS:=} 108cd88b886SDevin Teske 109cd88b886SDevin Teske# 110cd88b886SDevin Teske# Default partitioning scheme to use on disks 111cd88b886SDevin Teske# 112cd88b886SDevin Teske: ${ZFSBOOT_PARTITION_SCHEME:=GPT} 113cd88b886SDevin Teske 114cd88b886SDevin Teske# 115cd88b886SDevin Teske# How much swap to put on each block device in the boot zpool 116cd88b886SDevin Teske# NOTE: Value passed to gpart(8); which supports SI unit suffixes. 117cd88b886SDevin Teske# 118cd88b886SDevin Teske: ${ZFSBOOT_SWAP_SIZE:=2g} 119cd88b886SDevin Teske 120cd88b886SDevin Teske# 1212875e59fSOllivier Robert# Should we use geli(8) to encrypt the swap? 1222875e59fSOllivier Robert# 1232875e59fSOllivier Robert: ${ZFSBOOT_SWAP_ENCRYPTION=} 1242875e59fSOllivier Robert 1252875e59fSOllivier Robert# 1262875e59fSOllivier Robert# Should we use gmirror(8) to mirror the swap? 1272875e59fSOllivier Robert# 1282875e59fSOllivier Robert: ${ZFSBOOT_SWAP_MIRROR=} 1292875e59fSOllivier Robert 1302875e59fSOllivier Robert# 131bc4a673fSDevin Teske# Default ZFS datasets for root zpool 132cd88b886SDevin Teske# 133cd88b886SDevin Teske# NOTE: Requires /tmp, /var/tmp, /$ZFSBOOT_BOOTFS_NAME/$ZFSBOOT_BOOTFS_NAME 134cd88b886SDevin Teske# NOTE: Anything after pound/hash character [#] is ignored as a comment. 135cd88b886SDevin Teske# 136cd88b886SDevin Teskef_isset ZFSBOOT_DATASETS || ZFSBOOT_DATASETS=" 137cd88b886SDevin Teske # DATASET OPTIONS (comma or space separated; or both) 138cd88b886SDevin Teske 139cd88b886SDevin Teske # Boot Environment [BE] root and default boot dataset 140cd88b886SDevin Teske /$ZFSBOOT_BEROOT_NAME mountpoint=none 141cd88b886SDevin Teske /$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOTFS_NAME mountpoint=/ 142cd88b886SDevin Teske 143cd88b886SDevin Teske # Compress /tmp, allow exec but not setuid 144ed8690e3SOllivier Robert /tmp mountpoint=/tmp,exec=on,setuid=off 145cd88b886SDevin Teske 146cd88b886SDevin Teske # Don't mount /usr so that 'base' files go to the BEROOT 147cd88b886SDevin Teske /usr mountpoint=/usr,canmount=off 148cd88b886SDevin Teske 149cd88b886SDevin Teske # Home directories separated so they are common to all BEs 150bc4a673fSDevin Teske /usr/home # NB: /home is a symlink to /usr/home 151cd88b886SDevin Teske 152cd88b886SDevin Teske # Ports tree 153ed8690e3SOllivier Robert /usr/ports setuid=off 154cd88b886SDevin Teske 155cd88b886SDevin Teske # Source tree (compressed) 156ed8690e3SOllivier Robert /usr/src 157cd88b886SDevin Teske 158cd88b886SDevin Teske # Create /var and friends 1591aec0f4fSAllan Jude /var mountpoint=/var,canmount=off 1601bc08043SAllan Jude /var/audit exec=off,setuid=off 161ed8690e3SOllivier Robert /var/crash exec=off,setuid=off 162ed8690e3SOllivier Robert /var/log exec=off,setuid=off 163ed8690e3SOllivier Robert /var/mail atime=on 164ed8690e3SOllivier Robert /var/tmp setuid=off 165cd88b886SDevin Teske" # END-QUOTE 166cd88b886SDevin Teske 167bc4a673fSDevin Teske# 168bc4a673fSDevin Teske# If interactive and the user has not explicitly chosen a vdev type or disks, 169bc4a673fSDevin Teske# make the user confirm scripted/default choices when proceeding to install. 170bc4a673fSDevin Teske# 171bc4a673fSDevin Teske: ${ZFSBOOT_CONFIRM_LAYOUT:=1} 172bc4a673fSDevin Teske 173cd88b886SDevin Teske############################################################ GLOBALS 174cd88b886SDevin Teske 175cd88b886SDevin Teske# 176bc4a673fSDevin Teske# Format of a line in printf(1) syntax to add to fstab(5) 177bc4a673fSDevin Teske# 178bc4a673fSDevin TeskeFSTAB_FMT="%s\t\t%s\t%s\t%s\t\t%s\t%s\n" 179bc4a673fSDevin Teske 180bc4a673fSDevin Teske# 181bc4a673fSDevin Teske# Command strings for various tasks 182bc4a673fSDevin Teske# 183bc4a673fSDevin TeskeCHMOD_MODE='chmod %s "%s"' 184bc4a673fSDevin TeskeDD_WITH_OPTIONS='dd if="%s" of="%s" %s' 185bc4a673fSDevin TeskeECHO_APPEND='echo "%s" >> "%s"' 186bc4a673fSDevin TeskeGELI_ATTACH='geli attach -j - -k "%s" "%s"' 187a622223fSDevin TeskeGELI_DETACH_F='geli detach -f "%s"' 188bc4a673fSDevin TeskeGELI_PASSWORD_INIT='geli init -b -B "%s" -e %s -J - -K "%s" -l 256 -s 4096 "%s"' 18969e4b249SAllan JudeGPART_ADD_ALIGN='gpart add %s -t %s "%s"' 19069e4b249SAllan JudeGPART_ADD_ALIGN_INDEX='gpart add %s -i %s -t %s "%s"' 19169e4b249SAllan JudeGPART_ADD_ALIGN_INDEX_WITH_SIZE='gpart add %s -i %s -t %s -s %s "%s"' 19269e4b249SAllan JudeGPART_ADD_ALIGN_LABEL='gpart add %s -l %s -t %s "%s"' 19369e4b249SAllan JudeGPART_ADD_ALIGN_LABEL_WITH_SIZE='gpart add %s -l %s -t %s -s %s "%s"' 194bc4a673fSDevin TeskeGPART_BOOTCODE='gpart bootcode -b "%s" "%s"' 195bc4a673fSDevin TeskeGPART_BOOTCODE_PART='gpart bootcode -b "%s" -p "%s" -i %s "%s"' 196bc4a673fSDevin TeskeGPART_CREATE='gpart create -s %s "%s"' 197a622223fSDevin TeskeGPART_DESTROY_F='gpart destroy -F "%s"' 198bc4a673fSDevin TeskeGPART_SET_ACTIVE='gpart set -a active -i %s "%s"' 1997059fa6fSAllan JudeGPART_SET_LENOVOFIX='gpart set -a lenovofix "%s"' 2007059fa6fSAllan JudeGPART_SET_PMBR_ACTIVE='gpart set -a active "%s"' 201a622223fSDevin TeskeGRAID_DELETE='graid delete "%s"' 202bc4a673fSDevin TeskeLN_SF='ln -sf "%s" "%s"' 203bc4a673fSDevin TeskeMKDIR_P='mkdir -p "%s"' 204bc4a673fSDevin TeskeMOUNT_TYPE='mount -t %s "%s" "%s"' 205bc4a673fSDevin TeskePRINTF_CONF="printf '%s=\"%%s\"\\\n' %s >> \"%s\"" 206bc4a673fSDevin TeskePRINTF_FSTAB='printf "$FSTAB_FMT" "%s" "%s" "%s" "%s" "%s" "%s" >> "%s"' 207bc4a673fSDevin TeskeSHELL_TRUNCATE=':> "%s"' 2082875e59fSOllivier RobertSWAP_GMIRROR_LABEL='gmirror label swap %s' 209b4843bd6SSteven HartlandSYSCTL_ZFS_MIN_ASHIFT_12='sysctl vfs.zfs.min_auto_ashift=12' 210a622223fSDevin TeskeUMOUNT='umount "%s"' 211bc4a673fSDevin TeskeZFS_CREATE_WITH_OPTIONS='zfs create %s "%s"' 212bc4a673fSDevin TeskeZFS_SET='zfs set "%s" "%s"' 213bc4a673fSDevin TeskeZFS_UNMOUNT='zfs unmount "%s"' 214bc4a673fSDevin TeskeZPOOL_CREATE_WITH_OPTIONS='zpool create %s "%s" %s %s' 215a88393ceSDevin TeskeZPOOL_DESTROY='zpool destroy "%s"' 216bc4a673fSDevin TeskeZPOOL_EXPORT='zpool export "%s"' 217bc4a673fSDevin TeskeZPOOL_IMPORT_WITH_OPTIONS='zpool import %s "%s"' 218a622223fSDevin TeskeZPOOL_LABELCLEAR_F='zpool labelclear -f "%s"' 219bc4a673fSDevin TeskeZPOOL_SET='zpool set %s "%s"' 220bc4a673fSDevin Teske 221bc4a673fSDevin Teske# 222cd88b886SDevin Teske# Strings that should be moved to an i18n file and loaded with f_include_lang() 223cd88b886SDevin Teske# 224cd88b886SDevin Teskehline_alnum_arrows_punc_tab_enter="Use alnum, arrows, punctuation, TAB or ENTER" 225cd88b886SDevin Teskehline_arrows_space_tab_enter="Use arrows, SPACE, TAB or ENTER" 226cd88b886SDevin Teskehline_arrows_tab_enter="Press arrows, TAB or ENTER" 227bc4a673fSDevin Teskemsg_an_unknown_error_occurred="An unknown error occurred" 228cd88b886SDevin Teskemsg_back="Back" 229cd88b886SDevin Teskemsg_cancel="Cancel" 230bc4a673fSDevin Teskemsg_change_selection="Change Selection" 231cd88b886SDevin Teskemsg_configure_options="Configure Options:" 232cd88b886SDevin Teskemsg_detailed_disk_info="gpart(8) show %s:\n%s\n\ncamcontrol(8) inquiry %s:\n%s\n\n\ncamcontrol(8) identify %s:\n%s\n" 233cd88b886SDevin Teskemsg_disk_info="Disk Info" 234cd88b886SDevin Teskemsg_disk_info_help="Get detailed information on disk device(s)" 235695a612fSOllivier Robertmsg_disk_singular="disk" 236695a612fSOllivier Robertmsg_disk_plural="disks" 237bc4a673fSDevin Teskemsg_encrypt_disks="Encrypt Disks?" 238bc4a673fSDevin Teskemsg_encrypt_disks_help="Use geli(8) to encrypt all data partitions" 239bc4a673fSDevin Teskemsg_error="Error" 240cd88b886SDevin Teskemsg_force_4k_sectors="Force 4K Sectors?" 24169e4b249SAllan Judemsg_force_4k_sectors_help="Align partitions to 4K sector boundries and set vfs.zfs.min_auto_ashift=12" 242cd88b886SDevin Teskemsg_freebsd_installer="FreeBSD Installer" 243cd88b886SDevin Teskemsg_geli_password="Enter a strong passphrase, used to protect your encryption keys. You will be required to enter this passphrase each time the system is booted" 2447a434c5cSDevin Teskemsg_geli_setup="Initializing encryption on selected disks,\n this will take several seconds per disk" 245bc4a673fSDevin Teskemsg_install="Install" 246bc4a673fSDevin Teskemsg_install_desc="Proceed with Installation" 247bc4a673fSDevin Teskemsg_install_help="Create ZFS boot pool with displayed options" 2487cae6aabSDevin Teskemsg_invalid_boot_pool_size="Invalid boot pool size \`%s'" 249bc4a673fSDevin Teskemsg_invalid_disk_argument="Invalid disk argument \`%s'" 250bc4a673fSDevin Teskemsg_invalid_index_argument="Invalid index argument \`%s'" 251bc4a673fSDevin Teskemsg_invalid_swap_size="Invalid swap size \`%s'" 252cd88b886SDevin Teskemsg_invalid_virtual_device_type="Invalid Virtual Device type \`%s'" 253bc4a673fSDevin Teskemsg_last_chance_are_you_sure="Last Chance! Are you sure you want to destroy\nthe current contents of the following disks:\n\n %s" 254bc4a673fSDevin Teskemsg_last_chance_are_you_sure_color='\\ZrLast Chance!\\ZR Are you \\Z1sure\\Zn you want to \\Zr\\Z1destroy\\Zn\nthe current contents of the following disks:\n\n %s' 255cd88b886SDevin Teskemsg_mirror_desc="Mirror - n-Way Mirroring" 256cd88b886SDevin Teskemsg_mirror_help="[2+ Disks] Mirroring provides the best performance, but the least storage" 257bc4a673fSDevin Teskemsg_missing_disk_arguments="missing disk arguments" 258bc4a673fSDevin Teskemsg_missing_one_or_more_scripted_disks="Missing one or more scripted disks!" 259cd88b886SDevin Teskemsg_no="NO" 260cd88b886SDevin Teskemsg_no_disks_present_to_configure="No disk(s) present to configure" 261cd88b886SDevin Teskemsg_no_disks_selected="No disks selected." 262bc4a673fSDevin Teskemsg_not_enough_disks_selected="Not enough disks selected. (%u < %u minimum)" 263bc4a673fSDevin Teskemsg_null_disk_argument="NULL disk argument" 264bc4a673fSDevin Teskemsg_null_index_argument="NULL index argument" 265bc4a673fSDevin Teskemsg_null_poolname="NULL poolname" 266cd88b886SDevin Teskemsg_ok="OK" 267cd88b886SDevin Teskemsg_partition_scheme="Partition Scheme" 2687059fa6fSAllan Judemsg_partition_scheme_help="Select partitioning scheme. GPT is recommended." 269cd88b886SDevin Teskemsg_please_enter_a_name_for_your_zpool="Please enter a name for your zpool:" 270cd88b886SDevin Teskemsg_please_enter_amount_of_swap_space="Please enter amount of swap space (SI-Unit suffixes\nrecommended; e.g., \`2g' for 2 Gigabytes):" 271cd88b886SDevin Teskemsg_please_select_one_or_more_disks="Please select one or more disks to create a zpool:" 272cd88b886SDevin Teskemsg_pool_name="Pool Name" 273cd88b886SDevin Teskemsg_pool_name_cannot_be_empty="Pool name cannot be empty." 274cd88b886SDevin Teskemsg_pool_name_help="Customize the name of the zpool to be created (Required)" 275bc4a673fSDevin Teskemsg_pool_type_disks="Pool Type/Disks:" 276bc4a673fSDevin Teskemsg_pool_type_disks_help="Choose type of ZFS Virtual Device and disks to use (Required)" 277cd88b886SDevin Teskemsg_processing_selection="Processing selection..." 278cd88b886SDevin Teskemsg_raidz1_desc="RAID-Z1 - Single Redundant RAID" 279cd88b886SDevin Teskemsg_raidz1_help="[3+ Disks] Withstand failure of 1 disk. Recommended for: 3, 5 or 9 disks" 280cd88b886SDevin Teskemsg_raidz2_desc="RAID-Z2 - Double Redundant RAID" 281cd88b886SDevin Teskemsg_raidz2_help="[4+ Disks] Withstand failure of 2 disks. Recommended for: 4, 6 or 10 disks" 282cd88b886SDevin Teskemsg_raidz3_desc="RAID-Z3 - Triple Redundant RAID" 283cd88b886SDevin Teskemsg_raidz3_help="[5+ Disks] Withstand failure of 3 disks. Recommended for: 5, 7 or 11 disks" 284cd88b886SDevin Teskemsg_rescan_devices="Rescan Devices" 285cd88b886SDevin Teskemsg_rescan_devices_help="Scan for device changes" 286cd88b886SDevin Teskemsg_select="Select" 287cd88b886SDevin Teskemsg_select_a_disk_device="Select a disk device" 288cd88b886SDevin Teskemsg_select_virtual_device_type="Select Virtual Device type:" 289cd88b886SDevin Teskemsg_stripe_desc="Stripe - No Redundancy" 290cd88b886SDevin Teskemsg_stripe_help="[1+ Disks] Striping provides maximum storage but no redundancy" 2912875e59fSOllivier Robertmsg_swap_encrypt="Encrypt Swap?" 2922875e59fSOllivier Robertmsg_swap_encrypt_help="Encrypt swap partitions with temporary keys, discarded on reboot" 293169ff110SAllan Judemsg_swap_invalid="The selected swap size (%s) is invalid. Enter a number optionally followed by units. Example: 2G" 2942875e59fSOllivier Robertmsg_swap_mirror="Mirror Swap?" 2952875e59fSOllivier Robertmsg_swap_mirror_help="Mirror swap partitions for redundancy, breaks crash dumps" 296cd88b886SDevin Teskemsg_swap_size="Swap Size" 297cd88b886SDevin Teskemsg_swap_size_help="Customize how much swap space is allocated to each selected disk" 298169ff110SAllan Judemsg_swap_toosmall="The selected swap size (%s) is to small. Please enter a value greater than 100MB or enter 0 for no swap" 299bc4a673fSDevin Teskemsg_these_disks_are_too_small="These disks are too small given the amount of requested\nswap (%s) and/or geli(8) (%s) partitions, which would\ntake 50%% or more of each of the following selected disk\ndevices (not recommended):\n\n %s\n\nRecommend changing partition size(s) and/or selecting a\ndifferent set of devices." 30012307018SAllan Judemsg_uefi_not_supported="The FreeBSD UEFI loader does not currently support booting root-on-ZFS. Your system will need to boot in legacy (CSM) mode.\nDo you want to continue?" 301bc4a673fSDevin Teskemsg_unable_to_get_disk_capacity="Unable to get disk capacity of \`%s'" 302bc4a673fSDevin Teskemsg_unsupported_partition_scheme="%s is an unsupported partition scheme" 303bc4a673fSDevin Teskemsg_user_cancelled="User Cancelled." 304cd88b886SDevin Teskemsg_yes="YES" 305cd88b886SDevin Teskemsg_zfs_configuration="ZFS Configuration" 306cd88b886SDevin Teske 307cd88b886SDevin Teske############################################################ FUNCTIONS 308cd88b886SDevin Teske 309cd88b886SDevin Teske# dialog_menu_main 310cd88b886SDevin Teske# 311cd88b886SDevin Teske# Display the dialog(1)-based application main menu. 312cd88b886SDevin Teske# 313cd88b886SDevin Teskedialog_menu_main() 314cd88b886SDevin Teske{ 315cd88b886SDevin Teske local title="$DIALOG_TITLE" 316cd88b886SDevin Teske local btitle="$DIALOG_BACKTITLE" 317cd88b886SDevin Teske local prompt="$msg_configure_options" 318cd88b886SDevin Teske local force4k="$msg_no" 319cd88b886SDevin Teske local usegeli="$msg_no" 3202875e59fSOllivier Robert local swapgeli="$msg_no" 3212875e59fSOllivier Robert local swapmirror="$msg_no" 322b4843bd6SSteven Hartland [ "$ZFSBOOT_FORCE_4K_SECTORS" ] && force4k="$msg_yes" 323cd88b886SDevin Teske [ "$ZFSBOOT_GELI_ENCRYPTION" ] && usegeli="$msg_yes" 3242875e59fSOllivier Robert [ "$ZFSBOOT_SWAP_ENCRYPTION" ] && swapgeli="$msg_yes" 3252875e59fSOllivier Robert [ "$ZFSBOOT_SWAP_MIRROR" ] && swapmirror="$msg_yes" 326695a612fSOllivier Robert local disks n disks_grammar 327a88393ceSDevin Teske f_count n $ZFSBOOT_DISKS 328695a612fSOllivier Robert { [ $n -eq 1 ] && disks_grammar=$msg_disk_singular; } || 329695a612fSOllivier Robert disks_grammar=$msg_disk_plural # grammar 330cd88b886SDevin Teske local menu_list=" 331bc4a673fSDevin Teske '>>> $msg_install' '$msg_install_desc' 332bc4a673fSDevin Teske '$msg_install_help' 33333112d9eSDevin Teske 'T $msg_pool_type_disks' 33433112d9eSDevin Teske '$ZFSBOOT_VDEV_TYPE: $n $disks_grammar' 335bc4a673fSDevin Teske '$msg_pool_type_disks_help' 336cd88b886SDevin Teske '- $msg_rescan_devices' '*' 337cd88b886SDevin Teske '$msg_rescan_devices_help' 338cd88b886SDevin Teske '- $msg_disk_info' '*' 339cd88b886SDevin Teske '$msg_disk_info_help' 340bc4a673fSDevin Teske 'N $msg_pool_name' '$ZFSBOOT_POOL_NAME' 341cd88b886SDevin Teske '$msg_pool_name_help' 34233112d9eSDevin Teske '4 $msg_force_4k_sectors' 34333112d9eSDevin Teske '$force4k' 344cd88b886SDevin Teske '$msg_force_4k_sectors_help' 345bc4a673fSDevin Teske 'E $msg_encrypt_disks' '$usegeli' 346bc4a673fSDevin Teske '$msg_encrypt_disks_help' 34733112d9eSDevin Teske 'P $msg_partition_scheme' 34833112d9eSDevin Teske '$ZFSBOOT_PARTITION_SCHEME' 349cd88b886SDevin Teske '$msg_partition_scheme_help' 350bc4a673fSDevin Teske 'S $msg_swap_size' '$ZFSBOOT_SWAP_SIZE' 351cd88b886SDevin Teske '$msg_swap_size_help' 3522875e59fSOllivier Robert 'M $msg_swap_mirror' '$swapmirror' 3532875e59fSOllivier Robert '$msg_swap_mirror_help' 3542875e59fSOllivier Robert 'W $msg_swap_encrypt' '$swapgeli' 3552875e59fSOllivier Robert '$msg_swap_encrypt_help' 356cd88b886SDevin Teske " # END-QUOTE 357cd88b886SDevin Teske local defaultitem= # Calculated below 358cd88b886SDevin Teske local hline="$hline_alnum_arrows_punc_tab_enter" 359cd88b886SDevin Teske 360cd88b886SDevin Teske local height width rows 361cd88b886SDevin Teske eval f_dialog_menu_with_help_size height width rows \ 362cd88b886SDevin Teske \"\$title\" \"\$btitle\" \"\$prompt\" \"\$hline\" $menu_list 363cd88b886SDevin Teske 364cd88b886SDevin Teske # Obtain default-item from previously stored selection 365cd88b886SDevin Teske f_dialog_default_fetch defaultitem 366cd88b886SDevin Teske 367cd88b886SDevin Teske local menu_choice 368cd88b886SDevin Teske menu_choice=$( eval $DIALOG \ 369cd88b886SDevin Teske --title \"\$title\" \ 370cd88b886SDevin Teske --backtitle \"\$btitle\" \ 371cd88b886SDevin Teske --hline \"\$hline\" \ 372cd88b886SDevin Teske --item-help \ 373cd88b886SDevin Teske --ok-label \"\$msg_select\" \ 374cd88b886SDevin Teske --cancel-label \"\$msg_cancel\" \ 375cd88b886SDevin Teske --default-item \"\$defaultitem\" \ 376cd88b886SDevin Teske --menu \"\$prompt\" \ 377cd88b886SDevin Teske $height $width $rows \ 378cd88b886SDevin Teske $menu_list \ 379cd88b886SDevin Teske 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 380cd88b886SDevin Teske ) 381cd88b886SDevin Teske local retval=$? 382cd88b886SDevin Teske f_dialog_data_sanitize menu_choice 383cd88b886SDevin Teske f_dialog_menutag_store "$menu_choice" 384cd88b886SDevin Teske 385cd88b886SDevin Teske # Only update default-item on success 386cd88b886SDevin Teske [ $retval -eq $DIALOG_OK ] && f_dialog_default_store "$menu_choice" 387cd88b886SDevin Teske 388cd88b886SDevin Teske return $retval 389cd88b886SDevin Teske} 390cd88b886SDevin Teske 391bc4a673fSDevin Teske# dialog_last_chance $disks ... 392cd88b886SDevin Teske# 393bc4a673fSDevin Teske# Display a list of the disks that the user is about to destroy. The default 394bc4a673fSDevin Teske# action is to return error status unless the user explicitly (non-default) 395bc4a673fSDevin Teske# selects "Yes" from the noyes dialog. 396cd88b886SDevin Teske# 397bc4a673fSDevin Teskedialog_last_chance() 398cd88b886SDevin Teske{ 399cd88b886SDevin Teske local title="$DIALOG_TITLE" 400cd88b886SDevin Teske local btitle="$DIALOG_BACKTITLE" 401bc4a673fSDevin Teske local prompt # Calculated below 402bc4a673fSDevin Teske local hline="$hline_arrows_tab_enter" 403cd88b886SDevin Teske 404bc4a673fSDevin Teske local height=8 width=50 prefix=" " 405bc4a673fSDevin Teske local plen=${#prefix} list= line= 406bc4a673fSDevin Teske local max_width=$(( $width - 3 - $plen )) 407bc4a673fSDevin Teske 408bc4a673fSDevin Teske local yes no defaultno extra_args format 409bc4a673fSDevin Teske if [ "$USE_XDIALOG" ]; then 410bc4a673fSDevin Teske yes=ok no=cancel defaultno=default-no 411bc4a673fSDevin Teske extra_args="--wrap --left" 412bc4a673fSDevin Teske format="$msg_last_chance_are_you_sure" 413bc4a673fSDevin Teske else 414bc4a673fSDevin Teske yes=yes no=no defaultno=defaultno 415bc4a673fSDevin Teske extra_args="--colors --cr-wrap" 416bc4a673fSDevin Teske format="$msg_last_chance_are_you_sure_color" 417bc4a673fSDevin Teske fi 418bc4a673fSDevin Teske 419bc4a673fSDevin Teske local disk line_width 420bc4a673fSDevin Teske for disk in $*; do 421bc4a673fSDevin Teske if [ "$line" ]; then 422bc4a673fSDevin Teske line_width=${#line} 423bc4a673fSDevin Teske else 424bc4a673fSDevin Teske line_width=$plen 425bc4a673fSDevin Teske fi 426bc4a673fSDevin Teske line_width=$(( $line_width + 1 + ${#disk} )) 427bc4a673fSDevin Teske # Add newline before disk if it would exceed max_width 428bc4a673fSDevin Teske if [ $line_width -gt $max_width ]; then 429bc4a673fSDevin Teske list="$list$line\n" 430bc4a673fSDevin Teske line="$prefix" 431bc4a673fSDevin Teske height=$(( $height + 1 )) 432bc4a673fSDevin Teske fi 433bc4a673fSDevin Teske # Add the disk to the list 434bc4a673fSDevin Teske line="$line $disk" 435bc4a673fSDevin Teske done 436bc4a673fSDevin Teske # Append the left-overs 437bc4a673fSDevin Teske if [ "${line#$prefix}" ]; then 438bc4a673fSDevin Teske list="$list$line" 439bc4a673fSDevin Teske height=$(( $height + 1 )) 440bc4a673fSDevin Teske fi 441bc4a673fSDevin Teske 442bc4a673fSDevin Teske # Add height for Xdialog(1) 443bc4a673fSDevin Teske [ "$USE_XDIALOG" ] && height=$(( $height + $height / 5 + 3 )) 444bc4a673fSDevin Teske 445bc4a673fSDevin Teske prompt=$( printf "$format" "$list" ) 446bc4a673fSDevin Teske f_dprintf "%s: Last Chance!" "$0" 447bc4a673fSDevin Teske $DIALOG \ 448bc4a673fSDevin Teske --title "$title" \ 449bc4a673fSDevin Teske --backtitle "$btitle" \ 450bc4a673fSDevin Teske --hline "$hline" \ 451bc4a673fSDevin Teske --$defaultno \ 452bc4a673fSDevin Teske --$yes-label "$msg_yes" \ 453bc4a673fSDevin Teske --$no-label "$msg_no" \ 454bc4a673fSDevin Teske $extra_args \ 455bc4a673fSDevin Teske --yesno "$prompt" $height $width 456bc4a673fSDevin Teske} 457bc4a673fSDevin Teske 458bc4a673fSDevin Teske# dialog_menu_layout 459cd88b886SDevin Teske# 460bc4a673fSDevin Teske# Configure Virtual Device type and disks to use for the ZFS boot pool. User 461bc4a673fSDevin Teske# must select enough disks to satisfy the chosen vdev type. 462cd88b886SDevin Teske# 463bc4a673fSDevin Teskedialog_menu_layout() 464bc4a673fSDevin Teske{ 465bc4a673fSDevin Teske local funcname=dialog_menu_layout 466bc4a673fSDevin Teske local title="$DIALOG_TITLE" 467bc4a673fSDevin Teske local btitle="$DIALOG_BACKTITLE" 468bc4a673fSDevin Teske local vdev_prompt="$msg_select_virtual_device_type" 469bc4a673fSDevin Teske local disk_prompt="$msg_please_select_one_or_more_disks" 470bc4a673fSDevin Teske local vdev_menu_list=" 471bc4a673fSDevin Teske 'stripe' '$msg_stripe_desc' '$msg_stripe_help' 472bc4a673fSDevin Teske 'mirror' '$msg_mirror_desc' '$msg_mirror_help' 473bc4a673fSDevin Teske 'raidz1' '$msg_raidz1_desc' '$msg_raidz1_help' 474bc4a673fSDevin Teske 'raidz2' '$msg_raidz2_desc' '$msg_raidz2_help' 475bc4a673fSDevin Teske 'raidz3' '$msg_raidz3_desc' '$msg_raidz3_help' 476bc4a673fSDevin Teske " # END-QUOTE 477bc4a673fSDevin Teske local disk_check_list= # Calculated below 478bc4a673fSDevin Teske local vdev_hline="$hline_arrows_tab_enter" 479bc4a673fSDevin Teske local disk_hline="$hline_arrows_space_tab_enter" 480bc4a673fSDevin Teske 481bc4a673fSDevin Teske # Warn the user if vdev type is not valid 482bc4a673fSDevin Teske case "$ZFSBOOT_VDEV_TYPE" in 483bc4a673fSDevin Teske stripe|mirror|raidz1|raidz2|raidz3) : known good ;; 484bc4a673fSDevin Teske *) 485bc4a673fSDevin Teske f_dprintf "%s: Invalid virtual device type \`%s'" \ 486bc4a673fSDevin Teske $funcname "$ZFSBOOT_VDEV_TYPE" 487bc4a673fSDevin Teske f_show_err "$msg_invalid_virtual_device_type" \ 488bc4a673fSDevin Teske "$ZFSBOOT_VDEV_TYPE" 489bc4a673fSDevin Teske f_interactive || return $FAILURE 490bc4a673fSDevin Teske esac 491bc4a673fSDevin Teske 492bc4a673fSDevin Teske # Calculate size of vdev menu once only 493bc4a673fSDevin Teske local vheight vwidth vrows 494bc4a673fSDevin Teske eval f_dialog_menu_with_help_size vheight vwidth vrows \ 495bc4a673fSDevin Teske \"\$title\" \"\$btitle\" \"\$vdev_prompt\" \"\$vdev_hline\" \ 496bc4a673fSDevin Teske $vdev_menu_list 497bc4a673fSDevin Teske 498bc4a673fSDevin Teske # Get a list of probed disk devices 499bc4a673fSDevin Teske local disks= 500a88393ceSDevin Teske debug= f_device_find "" $DEVICE_TYPE_DISK disks 501a88393ceSDevin Teske 502a88393ceSDevin Teske # Prune out mounted md(4) devices that may be part of the boot process 503a88393ceSDevin Teske local disk name new_list= 504a88393ceSDevin Teske for disk in $disks; do 505a88393ceSDevin Teske debug= $disk get name name 506a88393ceSDevin Teske case "$name" in 507a88393ceSDevin Teske md[0-9]*) f_mounted -b "/dev/$name" && continue ;; 508a88393ceSDevin Teske esac 509a88393ceSDevin Teske new_list="$new_list $disk" 510a88393ceSDevin Teske done 511a88393ceSDevin Teske disks="${new_list# }" 512a88393ceSDevin Teske 513a88393ceSDevin Teske # Debugging 514a88393ceSDevin Teske if [ "$debug" ]; then 515a88393ceSDevin Teske local disk_names= 516a88393ceSDevin Teske for disk in $disks; do 517a88393ceSDevin Teske debug= $disk get name name 518a88393ceSDevin Teske disk_names="$disk_names $name" 519a88393ceSDevin Teske done 520a88393ceSDevin Teske f_dprintf "$funcname: disks=[%s]" "${disk_names# }" 521a88393ceSDevin Teske fi 522a88393ceSDevin Teske 523cd88b886SDevin Teske if [ ! "$disks" ]; then 524bc4a673fSDevin Teske f_dprintf "No disk(s) present to configure" 525bc4a673fSDevin Teske f_show_err "$msg_no_disks_present_to_configure" 526cd88b886SDevin Teske return $FAILURE 527cd88b886SDevin Teske fi 528cd88b886SDevin Teske 529cd88b886SDevin Teske # Lets sort the disks array to be more user friendly 530a88393ceSDevin Teske f_device_sort_by name disks disks 531cd88b886SDevin Teske 532cd88b886SDevin Teske # 533bc4a673fSDevin Teske # Operate in a loop so we can (if interactive) repeat if not enough 534bc4a673fSDevin Teske # disks are selected to satisfy the chosen vdev type or user wants to 535bc4a673fSDevin Teske # back-up to the previous menu. 536cd88b886SDevin Teske # 537a88393ceSDevin Teske local vardisk ndisks onoff selections vdev_choice breakout device 538a88393ceSDevin Teske local valid_disks all_valid want_disks desc height width rows 539bc4a673fSDevin Teske while :; do 540cd88b886SDevin Teske # 541bc4a673fSDevin Teske # Confirm the vdev type that was selected 542cd88b886SDevin Teske # 543bc4a673fSDevin Teske if f_interactive && [ "$ZFSBOOT_CONFIRM_LAYOUT" ]; then 544bc4a673fSDevin Teske vdev_choice=$( eval $DIALOG \ 545cd88b886SDevin Teske --title \"\$title\" \ 546cd88b886SDevin Teske --backtitle \"\$btitle\" \ 547bc4a673fSDevin Teske --hline \"\$vdev_hline\" \ 548cd88b886SDevin Teske --ok-label \"\$msg_ok\" \ 549cd88b886SDevin Teske --cancel-label \"\$msg_cancel\" \ 550cd88b886SDevin Teske --item-help \ 551bc4a673fSDevin Teske --default-item \"\$ZFSBOOT_VDEV_TYPE\" \ 552bc4a673fSDevin Teske --menu \"\$vdev_prompt\" \ 553bc4a673fSDevin Teske $vheight $vwidth $vrows \ 554bc4a673fSDevin Teske $vdev_menu_list \ 555cd88b886SDevin Teske 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 556bc4a673fSDevin Teske ) || return $? 557bc4a673fSDevin Teske # Exit if user pressed ESC or chose Cancel/No 558bc4a673fSDevin Teske f_dialog_data_sanitize vdev_choice 559cd88b886SDevin Teske 560bc4a673fSDevin Teske ZFSBOOT_VDEV_TYPE="$vdev_choice" 561bc4a673fSDevin Teske f_dprintf "$funcname: ZFSBOOT_VDEV_TYPE=[%s]" \ 562bc4a673fSDevin Teske "$ZFSBOOT_VDEV_TYPE" 563bc4a673fSDevin Teske fi 564bc4a673fSDevin Teske 565bc4a673fSDevin Teske # Determine the number of disks needed for this vdev type 566a88393ceSDevin Teske want_disks=0 567bc4a673fSDevin Teske case "$ZFSBOOT_VDEV_TYPE" in 568cd88b886SDevin Teske stripe) want_disks=1 ;; 569cd88b886SDevin Teske mirror) want_disks=2 ;; 570cd88b886SDevin Teske raidz1) want_disks=3 ;; 571cd88b886SDevin Teske raidz2) want_disks=4 ;; 572cd88b886SDevin Teske raidz3) want_disks=5 ;; 573cd88b886SDevin Teske esac 574bc4a673fSDevin Teske 575a88393ceSDevin Teske # 576bc4a673fSDevin Teske # Warn the user if any scripted disks are invalid 577a88393ceSDevin Teske # 578a88393ceSDevin Teske valid_disks= all_valid=${ZFSBOOT_DISKS:+1} # optimism 579bc4a673fSDevin Teske for disk in $ZFSBOOT_DISKS; do 580a88393ceSDevin Teske if debug= f_device_find -1 \ 581a88393ceSDevin Teske $disk $DEVICE_TYPE_DISK device 582a88393ceSDevin Teske then 583bc4a673fSDevin Teske valid_disks="$valid_disks $disk" 584bc4a673fSDevin Teske continue 585cd88b886SDevin Teske fi 586bc4a673fSDevin Teske f_dprintf "$funcname: \`%s' is not a real disk" "$disk" 587bc4a673fSDevin Teske all_valid= 588bc4a673fSDevin Teske done 589bc4a673fSDevin Teske if [ ! "$all_valid" ]; then 590bc4a673fSDevin Teske if [ "$ZFSBOOT_DISKS" ]; then 591bc4a673fSDevin Teske f_show_err \ 592bc4a673fSDevin Teske "$msg_missing_one_or_more_scripted_disks" 593bc4a673fSDevin Teske else 594bc4a673fSDevin Teske f_dprintf "No disks selected." 595bc4a673fSDevin Teske f_interactive || 596bc4a673fSDevin Teske f_show_err "$msg_no_disks_selected" 597bc4a673fSDevin Teske fi 598bc4a673fSDevin Teske f_interactive || return $FAILURE 599bc4a673fSDevin Teske fi 600bc4a673fSDevin Teske ZFSBOOT_DISKS="${valid_disks# }" 601bc4a673fSDevin Teske 602bc4a673fSDevin Teske # 603bc4a673fSDevin Teske # Short-circuit if we're running non-interactively 604bc4a673fSDevin Teske # 605bc4a673fSDevin Teske if ! f_interactive || [ ! "$ZFSBOOT_CONFIRM_LAYOUT" ]; then 606a88393ceSDevin Teske f_count ndisks $ZFSBOOT_DISKS 607bc4a673fSDevin Teske [ $ndisks -ge $want_disks ] && break # to success 608bc4a673fSDevin Teske 609bc4a673fSDevin Teske # Not enough disks selected 610bc4a673fSDevin Teske f_dprintf "$funcname: %s: %s (%u < %u minimum)" \ 611bc4a673fSDevin Teske "$ZFSBOOT_VDEV_TYPE" \ 612bc4a673fSDevin Teske "Not enough disks selected." \ 613bc4a673fSDevin Teske $ndisks $want_disks 614bc4a673fSDevin Teske f_interactive || return $FAILURE 615bc4a673fSDevin Teske msg_yes="$msg_change_selection" msg_no="$msg_cancel" \ 616bc4a673fSDevin Teske f_yesno "%s: $msg_not_enough_disks_selected" \ 617bc4a673fSDevin Teske "$ZFSBOOT_VDEV_TYPE" $ndisks $want_disks || 618bc4a673fSDevin Teske return $FAILURE 619bc4a673fSDevin Teske fi 620bc4a673fSDevin Teske 621bc4a673fSDevin Teske # 622bc4a673fSDevin Teske # Confirm the disks that were selected 623bc4a673fSDevin Teske # Loop until the user cancels or selects enough disks 624bc4a673fSDevin Teske # 625a88393ceSDevin Teske breakout= 626bc4a673fSDevin Teske while :; do 627bc4a673fSDevin Teske # Loop over list of available disks, resetting state 628a88393ceSDevin Teske for disk in $disks; do 629a88393ceSDevin Teske f_isset _${disk}_status && _${disk}_status= 630a88393ceSDevin Teske done 631bc4a673fSDevin Teske 632bc4a673fSDevin Teske # Loop over list of selected disks and create temporary 633bc4a673fSDevin Teske # locals to map statuses onto up-to-date list of disks 634bc4a673fSDevin Teske for disk in $ZFSBOOT_DISKS; do 635a88393ceSDevin Teske debug= f_device_find -1 \ 636a88393ceSDevin Teske $disk $DEVICE_TYPE_DISK disk 637a88393ceSDevin Teske f_isset _${disk}_status || 638a88393ceSDevin Teske local _${disk}_status 639a88393ceSDevin Teske _${disk}_status=on 640bc4a673fSDevin Teske done 641bc4a673fSDevin Teske 642bc4a673fSDevin Teske # Create the checklist menu of discovered disk devices 643bc4a673fSDevin Teske disk_check_list= 644bc4a673fSDevin Teske for disk in $disks; do 645a88393ceSDevin Teske desc= 646a88393ceSDevin Teske $disk get name name 647a88393ceSDevin Teske $disk get desc desc 648bc4a673fSDevin Teske f_shell_escape "$desc" desc 649bc4a673fSDevin Teske f_getvar _${disk}_status:-off onoff 650bc4a673fSDevin Teske disk_check_list="$disk_check_list 651a88393ceSDevin Teske $name '$desc' $onoff" 652bc4a673fSDevin Teske done 653bc4a673fSDevin Teske 654bc4a673fSDevin Teske eval f_dialog_checklist_size height width rows \ 655bc4a673fSDevin Teske \"\$title\" \"\$btitle\" \"\$prompt\" \ 656bc4a673fSDevin Teske \"\$hline\" $disk_check_list 657bc4a673fSDevin Teske 658bc4a673fSDevin Teske selections=$( eval $DIALOG \ 659bc4a673fSDevin Teske --title \"\$DIALOG_TITLE\" \ 660bc4a673fSDevin Teske --backtitle \"\$DIALOG_BACKTITLE\" \ 661751952aeSDevin Teske --separate-output \ 662bc4a673fSDevin Teske --hline \"\$hline\" \ 663bc4a673fSDevin Teske --ok-label \"\$msg_ok\" \ 664bc4a673fSDevin Teske --cancel-label \"\$msg_back\" \ 665bc4a673fSDevin Teske --checklist \"\$prompt\" \ 666bc4a673fSDevin Teske $height $width $rows \ 667bc4a673fSDevin Teske $disk_check_list \ 668bc4a673fSDevin Teske 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 669bc4a673fSDevin Teske ) || break 670bc4a673fSDevin Teske # Loop if user pressed ESC or chose Cancel/No 671bc4a673fSDevin Teske f_dialog_data_sanitize selections 672bc4a673fSDevin Teske 673bc4a673fSDevin Teske ZFSBOOT_DISKS="$selections" 674bc4a673fSDevin Teske f_dprintf "$funcname: ZFSBOOT_DISKS=[%s]" \ 675bc4a673fSDevin Teske "$ZFSBOOT_DISKS" 676bc4a673fSDevin Teske 677a88393ceSDevin Teske f_count ndisks $ZFSBOOT_DISKS 678bc4a673fSDevin Teske [ $ndisks -ge $want_disks ] && 679bc4a673fSDevin Teske breakout=break && break 680bc4a673fSDevin Teske 681bc4a673fSDevin Teske # Not enough disks selected 682bc4a673fSDevin Teske f_dprintf "$funcname: %s: %s (%u < %u minimum)" \ 683bc4a673fSDevin Teske "$ZFSBOOT_VDEV_TYPE" \ 684bc4a673fSDevin Teske "Not enough disks selected." \ 685bc4a673fSDevin Teske $ndisks $want_disks 686bc4a673fSDevin Teske msg_yes="$msg_change_selection" msg_no="$msg_cancel" \ 687bc4a673fSDevin Teske f_yesno "%s: $msg_not_enough_disks_selected" \ 688bc4a673fSDevin Teske "$ZFSBOOT_VDEV_TYPE" $ndisks $want_disks || 689bc4a673fSDevin Teske break 690bc4a673fSDevin Teske done 691bc4a673fSDevin Teske [ "$breakout" = "break" ] && break 692bc4a673fSDevin Teske [ "$ZFSBOOT_CONFIRM_LAYOUT" ] || return $FAILURE 693bc4a673fSDevin Teske done 694bc4a673fSDevin Teske 695bc4a673fSDevin Teske return $DIALOG_OK 696cd88b886SDevin Teske} 697cd88b886SDevin Teske 69812307018SAllan Jude# dialog_uefi_prompt 69912307018SAllan Jude# 70012307018SAllan Jude# Confirm that the user wants to continue with the installation on a BIOS 70112307018SAllan Jude# system when they have booted with UEFI 70212307018SAllan Jude# 70312307018SAllan Judedialog_uefi_prompt() 70412307018SAllan Jude{ 70512307018SAllan Jude local title="$DIALOG_TITLE" 70612307018SAllan Jude local btitle="$DIALOG_BACKTITLE" 70712307018SAllan Jude local prompt # Calculated below 70812307018SAllan Jude local hline="$hline_arrows_tab_enter" 70912307018SAllan Jude 71012307018SAllan Jude local height=8 width=50 prefix=" " 71112307018SAllan Jude local plen=${#prefix} list= line= 71212307018SAllan Jude local max_width=$(( $width - 3 - $plen )) 71312307018SAllan Jude 71412307018SAllan Jude local yes no defaultno extra_args format 71512307018SAllan Jude if [ "$USE_XDIALOG" ]; then 71612307018SAllan Jude yes=ok no=cancel defaultno=default-no 71712307018SAllan Jude extra_args="--wrap --left" 71812307018SAllan Jude format="$msg_uefi_not_supported" 71912307018SAllan Jude else 72012307018SAllan Jude yes=yes no=no defaultno=defaultno 72112307018SAllan Jude extra_args="--cr-wrap" 72212307018SAllan Jude format="$msg_uefi_not_supported" 72312307018SAllan Jude fi 72412307018SAllan Jude 72512307018SAllan Jude # Add height for Xdialog(1) 72612307018SAllan Jude [ "$USE_XDIALOG" ] && height=$(( $height + $height / 5 + 3 )) 72712307018SAllan Jude 72812307018SAllan Jude prompt=$( printf "$format" ) 72912307018SAllan Jude f_dprintf "%s: UEFI prompt" "$0" 73012307018SAllan Jude $DIALOG \ 73112307018SAllan Jude --title "$title" \ 73212307018SAllan Jude --backtitle "$btitle" \ 73312307018SAllan Jude --hline "$hline" \ 73412307018SAllan Jude --$yes-label "$msg_yes" \ 73512307018SAllan Jude --$no-label "$msg_no" \ 73612307018SAllan Jude $extra_args \ 73712307018SAllan Jude --yesno "$prompt" $height $width 73812307018SAllan Jude} 73912307018SAllan Jude 740cd88b886SDevin Teske# zfs_create_diskpart $disk $index 741cd88b886SDevin Teske# 742cd88b886SDevin Teske# For each block device to be used in the zpool, rather than just create the 743cd88b886SDevin Teske# zpool with the raw block devices (e.g., da0, da1, etc.) we create partitions 744cd88b886SDevin Teske# so we can have some real swap. This also provides wiggle room incase your 745cd88b886SDevin Teske# replacement drivers do not have the exact same sector counts. 746cd88b886SDevin Teske# 7477cae6aabSDevin Teske# NOTE: $swapsize and $bootsize should be defined by the calling function. 748a622223fSDevin Teske# NOTE: Sets $bootpart and $targetpart for the calling function. 749cd88b886SDevin Teske# 750cd88b886SDevin Teskezfs_create_diskpart() 751cd88b886SDevin Teske{ 752cd88b886SDevin Teske local funcname=zfs_create_diskpart 753bc4a673fSDevin Teske local disk="$1" index="$2" 754cd88b886SDevin Teske 755cd88b886SDevin Teske # Check arguments 756bc4a673fSDevin Teske if [ ! "$disk" ]; then 757bc4a673fSDevin Teske f_dprintf "$funcname: NULL disk argument" 758bc4a673fSDevin Teske msg_error="$msg_error: $funcname" \ 759bc4a673fSDevin Teske f_show_err "$msg_null_disk_argument" 760bc4a673fSDevin Teske return $FAILURE 761bc4a673fSDevin Teske fi 762bc4a673fSDevin Teske if [ "${disk#*[$IFS]}" != "$disk" ]; then 763bc4a673fSDevin Teske f_dprintf "$funcname: Invalid disk argument \`%s'" "$disk" 764bc4a673fSDevin Teske msg_error="$msg_error: $funcname" \ 765bc4a673fSDevin Teske f_show_err "$msg_invalid_disk_argument" "$disk" 766bc4a673fSDevin Teske return $FAILURE 767bc4a673fSDevin Teske fi 768bc4a673fSDevin Teske if [ ! "$index" ]; then 769bc4a673fSDevin Teske f_dprintf "$funcname: NULL index argument" 770bc4a673fSDevin Teske msg_error="$msg_error: $funcname" \ 771bc4a673fSDevin Teske f_show_err "$msg_null_index_argument" 772bc4a673fSDevin Teske return $FAILURE 773bc4a673fSDevin Teske fi 774bc4a673fSDevin Teske if ! f_isinteger "$index"; then 775bc4a673fSDevin Teske f_dprintf "$funcname: Invalid index argument \`%s'" "$index" 776bc4a673fSDevin Teske msg_error="$msg_error: $funcname" \ 777bc4a673fSDevin Teske f_show_err "$msg_invalid_index_argument" "$index" 778bc4a673fSDevin Teske return $FAILURE 779bc4a673fSDevin Teske fi 780bc4a673fSDevin Teske f_dprintf "$funcname: disk=[%s] index=[%s]" "$disk" "$index" 781cd88b886SDevin Teske 782d4d729e4SDevin Teske # Check for unknown partition scheme before proceeding further 783d4d729e4SDevin Teske case "$ZFSBOOT_PARTITION_SCHEME" in 7847059fa6fSAllan Jude ""|MBR|GPT*) : known good ;; 785d4d729e4SDevin Teske *) 786d4d729e4SDevin Teske f_dprintf "$funcname: %s is an unsupported partition scheme" \ 787d4d729e4SDevin Teske "$ZFSBOOT_PARTITION_SCHEME" 788d4d729e4SDevin Teske msg_error="$msg_error: $funcname" f_show_err \ 789d4d729e4SDevin Teske "$msg_unsupported_partition_scheme" \ 790d4d729e4SDevin Teske "$ZFSBOOT_PARTITION_SCHEME" 791d4d729e4SDevin Teske return $FAILURE 792d4d729e4SDevin Teske esac 793d4d729e4SDevin Teske 794cd88b886SDevin Teske # 795cd88b886SDevin Teske # Destroy whatever partition layout is currently on disk. 796cd88b886SDevin Teske # NOTE: `-F' required to destroy if partitions still exist. 797cd88b886SDevin Teske # NOTE: Failure is ok here, blank disk will have nothing to destroy. 798cd88b886SDevin Teske # 799bc4a673fSDevin Teske f_dprintf "$funcname: Destroying all data/layouts on \`%s'..." "$disk" 800a622223fSDevin Teske f_eval_catch -d $funcname gpart "$GPART_DESTROY_F" $disk 801a622223fSDevin Teske f_eval_catch -d $funcname graid "$GRAID_DELETE" $disk 802a622223fSDevin Teske f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" /dev/$disk 803cd88b886SDevin Teske 804cd88b886SDevin Teske # Make doubly-sure backup GPT is destroyed 805a622223fSDevin Teske f_eval_catch -d $funcname gpart "$GPART_CREATE" gpt $disk 806a622223fSDevin Teske f_eval_catch -d $funcname gpart "$GPART_DESTROY_F" $disk 807cd88b886SDevin Teske 8087cae6aabSDevin Teske # 8097cae6aabSDevin Teske # Enable boot pool if encryption is desired 8107cae6aabSDevin Teske # 8117cae6aabSDevin Teske [ "$ZFSBOOT_GELI_ENCRYPTION" ] && ZFSBOOT_BOOT_POOL=1 812cd88b886SDevin Teske 813cd88b886SDevin Teske # 814cd88b886SDevin Teske # Lay down the desired type of partition scheme 815cd88b886SDevin Teske # 81669e4b249SAllan Jude local setsize mbrindex align_small align_big 81769e4b249SAllan Jude # 81869e4b249SAllan Jude # If user has requested 4 K alignment, add these params to the 81969e4b249SAllan Jude # gpart add calls. With GPT, we align large partitions to 1 M for 82069e4b249SAllan Jude # improved performance on SSDs. MBR does not always play well with gaps 82169e4b249SAllan Jude # between partitions, so all alignment is only 4k for that case. 82269e4b249SAllan Jude # With MBR, we align the BSD partition that contains the MBR, otherwise 82369e4b249SAllan Jude # the system fails to boot. 82469e4b249SAllan Jude # 82569e4b249SAllan Jude if [ "$ZFSBOOT_FORCE_4K_SECTORS" ]; then 82669e4b249SAllan Jude align_small="-a 4k" 82769e4b249SAllan Jude align_big="-a 1m" 82869e4b249SAllan Jude fi 82969e4b249SAllan Jude 830cd88b886SDevin Teske case "$ZFSBOOT_PARTITION_SCHEME" in 8317059fa6fSAllan Jude ""|GPT*) f_dprintf "$funcname: Creating GPT layout..." 832cd88b886SDevin Teske # 833cd88b886SDevin Teske # 1. Create GPT layout using labels 834cd88b886SDevin Teske # 835a622223fSDevin Teske f_eval_catch $funcname gpart "$GPART_CREATE" gpt $disk || 836bc4a673fSDevin Teske return $FAILURE 837cd88b886SDevin Teske 838cd88b886SDevin Teske # 8397059fa6fSAllan Jude # Apply workarounds if requested by the user 8407059fa6fSAllan Jude # 8417059fa6fSAllan Jude if [ "$ZFSBOOT_PARTITION_SCHEME" = "GPT + Lenovo Fix" ]; then 8427059fa6fSAllan Jude f_eval_catch $funcname gpart "$GPART_SET_LENOVOFIX" \ 8437059fa6fSAllan Jude $disk || return $FAILURE 8447059fa6fSAllan Jude elif [ "$ZFSBOOT_PARTITION_SCHEME" = "GPT + Active" ]; then 8457059fa6fSAllan Jude f_eval_catch $funcname gpart "$GPART_SET_PMBR_ACTIVE" \ 8467059fa6fSAllan Jude $disk || return $FAILURE 8477059fa6fSAllan Jude fi 8487059fa6fSAllan Jude 8497059fa6fSAllan Jude # 850cd88b886SDevin Teske # 2. Add small freebsd-boot partition labeled `boot#' 851cd88b886SDevin Teske # 85269e4b249SAllan Jude f_eval_catch $funcname gpart "$GPART_ADD_ALIGN_LABEL_WITH_SIZE" \ 85369e4b249SAllan Jude "$align_small" gptboot$index freebsd-boot 512k $disk || 854cd88b886SDevin Teske return $FAILURE 855bc4a673fSDevin Teske f_eval_catch $funcname gpart "$GPART_BOOTCODE_PART" \ 856a622223fSDevin Teske /boot/pmbr /boot/gptzfsboot 1 $disk || 857cd88b886SDevin Teske return $FAILURE 858cd88b886SDevin Teske 859a622223fSDevin Teske # NB: zpool will use the `zfs#' GPT labels 8602875e59fSOllivier Robert bootpart=p2 swappart=p2 targetpart=p2 8617cae6aabSDevin Teske [ ${swapsize:-0} -gt 0 ] && targetpart=p3 862cd88b886SDevin Teske 8637cae6aabSDevin Teske # 8647cae6aabSDevin Teske # Prepare boot pool if enabled (e.g., for geli(8)) 8657cae6aabSDevin Teske # 8667cae6aabSDevin Teske if [ "$ZFSBOOT_BOOT_POOL" ]; then 8672875e59fSOllivier Robert bootpart=p2 swappart=p3 targetpart=p3 8687cae6aabSDevin Teske [ ${swapsize:-0} -gt 0 ] && targetpart=p4 869bc4a673fSDevin Teske f_eval_catch $funcname gpart \ 87069e4b249SAllan Jude "$GPART_ADD_ALIGN_LABEL_WITH_SIZE" \ 87169e4b249SAllan Jude "$align_big" boot$index freebsd-zfs \ 87269e4b249SAllan Jude ${bootsize}b $disk || 873bc4a673fSDevin Teske return $FAILURE 8747cae6aabSDevin Teske # Pedantically nuke any old labels 875a622223fSDevin Teske f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 876a622223fSDevin Teske /dev/$disk$bootpart 8777cae6aabSDevin Teske if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then 8787cae6aabSDevin Teske # Pedantically detach targetpart for later 8797cae6aabSDevin Teske f_eval_catch -d $funcname geli \ 8807cae6aabSDevin Teske "$GELI_DETACH_F" \ 881a622223fSDevin Teske /dev/$disk$targetpart 882cd88b886SDevin Teske fi 8837cae6aabSDevin Teske fi 884cd88b886SDevin Teske 885cd88b886SDevin Teske # 8867cae6aabSDevin Teske # 3. Add freebsd-swap partition labeled `swap#' 887cd88b886SDevin Teske # 888bc4a673fSDevin Teske if [ ${swapsize:-0} -gt 0 ]; then 889bc4a673fSDevin Teske f_eval_catch $funcname gpart \ 89069e4b249SAllan Jude "$GPART_ADD_ALIGN_LABEL_WITH_SIZE" \ 89169e4b249SAllan Jude "$align_big" swap$index freebsd-swap \ 89269e4b249SAllan Jude ${swapsize}b $disk || 893cd88b886SDevin Teske return $FAILURE 894cf9c3e56SDevin Teske # Pedantically nuke any old labels on the swap 895cf9c3e56SDevin Teske f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 8962875e59fSOllivier Robert /dev/$disk$swappart 897cd88b886SDevin Teske fi 8987cae6aabSDevin Teske 8997cae6aabSDevin Teske # 9007cae6aabSDevin Teske # 4. Add freebsd-zfs partition labeled `zfs#' for zroot 9017cae6aabSDevin Teske # 90269e4b249SAllan Jude f_eval_catch $funcname gpart "$GPART_ADD_ALIGN_LABEL" \ 90369e4b249SAllan Jude "$align_big" zfs$index freebsd-zfs $disk || 90469e4b249SAllan Jude return $FAILURE 9057cae6aabSDevin Teske f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 9067cae6aabSDevin Teske /dev/$disk$targetpart 907cd88b886SDevin Teske ;; 908cd88b886SDevin Teske 909bc4a673fSDevin Teske MBR) f_dprintf "$funcname: Creating MBR layout..." 910cd88b886SDevin Teske # 911cd88b886SDevin Teske # 1. Create MBR layout (no labels) 912cd88b886SDevin Teske # 913a622223fSDevin Teske f_eval_catch $funcname gpart "$GPART_CREATE" mbr $disk || 914bc4a673fSDevin Teske return $FAILURE 9152925848dSDevin Teske f_eval_catch $funcname gpart "$GPART_BOOTCODE" /boot/mbr \ 916a622223fSDevin Teske $disk || return $FAILURE 917cd88b886SDevin Teske 918cd88b886SDevin Teske # 919cd88b886SDevin Teske # 2. Add freebsd slice with all available space 920cd88b886SDevin Teske # 92169e4b249SAllan Jude f_eval_catch $funcname gpart "$GPART_ADD_ALIGN" "$align_small" \ 92269e4b249SAllan Jude freebsd $disk || 923bc4a673fSDevin Teske return $FAILURE 924a622223fSDevin Teske f_eval_catch $funcname gpart "$GPART_SET_ACTIVE" 1 $disk || 925bc4a673fSDevin Teske return $FAILURE 926a622223fSDevin Teske # Pedantically nuke any old labels 927a622223fSDevin Teske f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 928a622223fSDevin Teske /dev/${disk}s1 929a622223fSDevin Teske # Pedantically nuke any old scheme 930a622223fSDevin Teske f_eval_catch -d $funcname gpart "$GPART_DESTROY_F" ${disk}s1 931cd88b886SDevin Teske 932cd88b886SDevin Teske # 933bc4a673fSDevin Teske # 3. Write BSD scheme to the freebsd slice 934cd88b886SDevin Teske # 935a622223fSDevin Teske f_eval_catch $funcname gpart "$GPART_CREATE" BSD ${disk}s1 || 936bc4a673fSDevin Teske return $FAILURE 937cd88b886SDevin Teske 9387cae6aabSDevin Teske # NB: zpool will use s1a (no labels) 9392875e59fSOllivier Robert bootpart=s1a swappart=s1b targetpart=s1d mbrindex=4 940cd88b886SDevin Teske 9417cae6aabSDevin Teske # 9427cae6aabSDevin Teske # Always prepare a boot pool on MBR 9437cae6aabSDevin Teske # 9447cae6aabSDevin Teske ZFSBOOT_BOOT_POOL=1 945bc4a673fSDevin Teske f_eval_catch $funcname gpart \ 94669e4b249SAllan Jude "$GPART_ADD_ALIGN_INDEX_WITH_SIZE" \ 94769e4b249SAllan Jude "$align_small" 1 freebsd-zfs ${bootsize}b ${disk}s1 || 948bc4a673fSDevin Teske return $FAILURE 949a622223fSDevin Teske # Pedantically nuke any old labels 950a622223fSDevin Teske f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 951a622223fSDevin Teske /dev/$disk$bootpart 9527cae6aabSDevin Teske if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then 953a622223fSDevin Teske # Pedantically detach targetpart for later 954a622223fSDevin Teske f_eval_catch -d $funcname geli \ 955a622223fSDevin Teske "$GELI_DETACH_F" \ 956a622223fSDevin Teske /dev/$disk$targetpart 957cd88b886SDevin Teske fi 958cd88b886SDevin Teske 959cd88b886SDevin Teske # 9607cae6aabSDevin Teske # 4. Add freebsd-swap partition 961cd88b886SDevin Teske # 962bc4a673fSDevin Teske if [ ${swapsize:-0} -gt 0 ]; then 963bc4a673fSDevin Teske f_eval_catch $funcname gpart \ 96469e4b249SAllan Jude "$GPART_ADD_ALIGN_INDEX_WITH_SIZE" \ 96569e4b249SAllan Jude "$align_small" 2 freebsd-swap ${swapsize}b ${disk}s1 || 966cd88b886SDevin Teske return $FAILURE 967cf9c3e56SDevin Teske # Pedantically nuke any old labels on the swap 968cf9c3e56SDevin Teske f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 969cf9c3e56SDevin Teske /dev/${disk}s1b 970cd88b886SDevin Teske fi 9717cae6aabSDevin Teske 9727cae6aabSDevin Teske # 9737cae6aabSDevin Teske # 5. Add freebsd-zfs partition for zroot 9747cae6aabSDevin Teske # 97569e4b249SAllan Jude f_eval_catch $funcname gpart "$GPART_ADD_ALIGN_INDEX" \ 97669e4b249SAllan Jude "$align_small" $mbrindex freebsd-zfs ${disk}s1 || return $FAILURE 9777cae6aabSDevin Teske f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 9787cae6aabSDevin Teske /dev/$disk$targetpart # Pedantic 9797cae6aabSDevin Teske f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \ 9807cae6aabSDevin Teske /boot/zfsboot /dev/${disk}s1 count=1 || 9817cae6aabSDevin Teske return $FAILURE 982cd88b886SDevin Teske ;; 983cd88b886SDevin Teske 984cd88b886SDevin Teske esac # $ZFSBOOT_PARTITION_SCHEME 985cd88b886SDevin Teske 9862875e59fSOllivier Robert # Update fstab(5) 987caa3817dSAllan Jude local swapsize 988caa3817dSAllan Jude f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize 9892875e59fSOllivier Robert if [ "$isswapmirror" ]; then 9902875e59fSOllivier Robert # This is not the first disk in the mirror, do nothing 9912875e59fSOllivier Robert elif [ "$ZFSBOOT_SWAP_ENCRYPTION" -a "$ZFSBOOT_SWAP_MIRROR" ]; then 9922875e59fSOllivier Robert f_eval_catch $funcname printf "$PRINTF_FSTAB" \ 9932875e59fSOllivier Robert /dev/mirror/swap.eli none swap sw 0 0 \ 9942875e59fSOllivier Robert $BSDINSTALL_TMPETC/fstab || 9952875e59fSOllivier Robert return $FAILURE 9962875e59fSOllivier Robert isswapmirror=1 9972875e59fSOllivier Robert elif [ "$ZFSBOOT_SWAP_MIRROR" ]; then 9982875e59fSOllivier Robert f_eval_catch $funcname printf "$PRINTF_FSTAB" \ 9992875e59fSOllivier Robert /dev/mirror/swap none swap sw 0 0 \ 10002875e59fSOllivier Robert $BSDINSTALL_TMPETC/fstab || 10012875e59fSOllivier Robert return $FAILURE 10022875e59fSOllivier Robert isswapmirror=1 10032875e59fSOllivier Robert elif [ "$ZFSBOOT_SWAP_ENCRYPTION" ]; then 10042875e59fSOllivier Robert f_eval_catch $funcname printf "$PRINTF_FSTAB" \ 10052875e59fSOllivier Robert /dev/$disk${swappart}.eli none swap sw 0 0 \ 10062875e59fSOllivier Robert $BSDINSTALL_TMPETC/fstab || 10072875e59fSOllivier Robert return $FAILURE 1008dce66381SAllan Jude elif [ ${swapsize:-0} -eq 0 ]; then 1009caa3817dSAllan Jude # If swap is 0 sized, don't add it to fstab 10102875e59fSOllivier Robert else 10112875e59fSOllivier Robert f_eval_catch $funcname printf "$PRINTF_FSTAB" \ 10122875e59fSOllivier Robert /dev/$disk$swappart none swap sw 0 0 \ 10132875e59fSOllivier Robert $BSDINSTALL_TMPETC/fstab || 10142875e59fSOllivier Robert return $FAILURE 10152875e59fSOllivier Robert fi 10162875e59fSOllivier Robert 1017cd88b886SDevin Teske return $SUCCESS 1018cd88b886SDevin Teske} 1019cd88b886SDevin Teske 1020bc4a673fSDevin Teske# zfs_create_boot $poolname $vdev_type $disks ... 1021cd88b886SDevin Teske# 1022cd88b886SDevin Teske# Creates boot pool and dataset layout. Returns error if something goes wrong. 1023cd88b886SDevin Teske# Errors are printed to stderr for collection and display. 1024cd88b886SDevin Teske# 1025cd88b886SDevin Teskezfs_create_boot() 1026cd88b886SDevin Teske{ 1027cd88b886SDevin Teske local funcname=zfs_create_boot 10287cae6aabSDevin Teske local zroot_name="$1" 10297cae6aabSDevin Teske local zroot_vdevtype="$2" 10307cae6aabSDevin Teske local zroot_vdevs= # Calculated below 10312875e59fSOllivier Robert local swap_devs= # Calculated below 10327cae6aabSDevin Teske local boot_vdevs= # Used for geli(8) and/or MBR layouts 1033a622223fSDevin Teske shift 2 # poolname vdev_type 1034a622223fSDevin Teske local disks="$*" disk 10352875e59fSOllivier Robert local isswapmirror 10362875e59fSOllivier Robert local bootpart targetpart swappart # Set by zfs_create_diskpart() below 103747206692SDevin Teske local create_options 1038cd88b886SDevin Teske 1039a622223fSDevin Teske # 1040cd88b886SDevin Teske # Pedantic checks; should never be seen 1041a622223fSDevin Teske # 10427cae6aabSDevin Teske if [ ! "$zroot_name" ]; then 1043bc4a673fSDevin Teske f_dprintf "$funcname: NULL poolname" 1044bc4a673fSDevin Teske msg_error="$msg_error: $funcname" \ 1045bc4a673fSDevin Teske f_show_err "$msg_null_poolname" 1046cd88b886SDevin Teske return $FAILURE 1047cd88b886SDevin Teske fi 1048cd88b886SDevin Teske if [ $# -lt 1 ]; then 1049bc4a673fSDevin Teske f_dprintf "$funcname: missing disk arguments" 1050bc4a673fSDevin Teske msg_error="$msg_error: $funcname" \ 1051bc4a673fSDevin Teske f_show_err "$msg_missing_disk_arguments" 1052cd88b886SDevin Teske return $FAILURE 1053cd88b886SDevin Teske fi 1054bc4a673fSDevin Teske f_dprintf "$funcname: poolname=[%s] vdev_type=[%s]" \ 10557cae6aabSDevin Teske "$zroot_name" "$zroot_vdevtype" 1056cd88b886SDevin Teske 1057a622223fSDevin Teske # 1058cd88b886SDevin Teske # Initialize fstab(5) 1059a622223fSDevin Teske # 1060bc4a673fSDevin Teske f_dprintf "$funcname: Initializing temporary fstab(5) file..." 1061a622223fSDevin Teske f_eval_catch $funcname sh "$SHELL_TRUNCATE" $BSDINSTALL_TMPETC/fstab || 1062bc4a673fSDevin Teske return $FAILURE 1063bc4a673fSDevin Teske f_eval_catch $funcname printf "$PRINTF_FSTAB" \ 1064cd88b886SDevin Teske "# Device" Mountpoint FStype Options Dump "Pass#" \ 1065a622223fSDevin Teske $BSDINSTALL_TMPETC/fstab || return $FAILURE 1066cd88b886SDevin Teske 1067a622223fSDevin Teske # 1068cd88b886SDevin Teske # Expand SI units in desired sizes 1069a622223fSDevin Teske # 10707cae6aabSDevin Teske f_dprintf "$funcname: Expanding supplied size values..." 10717cae6aabSDevin Teske local swapsize bootsize 1072bc4a673fSDevin Teske if ! f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize; then 1073bc4a673fSDevin Teske f_dprintf "$funcname: Invalid swap size \`%s'" \ 1074bc4a673fSDevin Teske "$ZFSBOOT_SWAP_SIZE" 1075bc4a673fSDevin Teske f_show_err "$msg_invalid_swap_size" "$ZFSBOOT_SWAP_SIZE" 1076bc4a673fSDevin Teske return $FAILURE 1077bc4a673fSDevin Teske fi 10787cae6aabSDevin Teske if ! f_expand_number "$ZFSBOOT_BOOT_POOL_SIZE" bootsize; then 10797cae6aabSDevin Teske f_dprintf "$funcname: Invalid boot pool size \`%s'" \ 10807cae6aabSDevin Teske "$ZFSBOOT_BOOT_POOL_SIZE" 10817cae6aabSDevin Teske f_show_err "$msg_invalid_boot_pool_size" \ 10827cae6aabSDevin Teske "$ZFSBOOT_BOOT_POOL_SIZE" 1083bc4a673fSDevin Teske return $FAILURE 1084bc4a673fSDevin Teske fi 1085bc4a673fSDevin Teske f_dprintf "$funcname: ZFSBOOT_SWAP_SIZE=[%s] swapsize=[%s]" \ 1086bc4a673fSDevin Teske "$ZFSBOOT_SWAP_SIZE" "$swapsize" 10877cae6aabSDevin Teske f_dprintf "$funcname: ZFSBOOT_BOOT_POOL_SIZE=[%s] bootsize=[%s]" \ 10887cae6aabSDevin Teske "$ZFSBOOT_BOOT_POOL_SIZE" "$bootsize" 1089cd88b886SDevin Teske 1090a622223fSDevin Teske # 1091a88393ceSDevin Teske # Destroy the pool in-case this is our second time 'round (case of 1092a88393ceSDevin Teske # failure and installer presented ``Retry'' option to come back). 1093a88393ceSDevin Teske # 1094a88393ceSDevin Teske # NB: If we don't destroy the pool, later gpart(8) destroy commands 1095a88393ceSDevin Teske # that try to clear existing partitions (see zfs_create_diskpart()) 1096a88393ceSDevin Teske # will fail with a `Device Busy' error, leading to `GEOM exists'. 1097a88393ceSDevin Teske # 1098a88393ceSDevin Teske f_eval_catch -d $funcname zpool "$ZPOOL_DESTROY" "$zroot_name" 1099a88393ceSDevin Teske 1100a88393ceSDevin Teske # 11017cae6aabSDevin Teske # Prepare the disks and build pool device list(s) 1102a622223fSDevin Teske # 1103bc4a673fSDevin Teske f_dprintf "$funcname: Preparing disk partitions for ZFS pool..." 1104b4843bd6SSteven Hartland 1105b4843bd6SSteven Hartland # Force 4K sectors using vfs.zfs.min_auto_ashift=12 1106b4843bd6SSteven Hartland if [ "$ZFSBOOT_FORCE_4K_SECTORS" ]; then 1107b4843bd6SSteven Hartland f_dprintf "$funcname: With 4K sectors..." 1108b4843bd6SSteven Hartland f_eval_catch $funcname sysctl "$SYSCTL_ZFS_MIN_ASHIFT_12" \ 1109b4843bd6SSteven Hartland || return $FAILURE 1110b4843bd6SSteven Hartland fi 1111cd88b886SDevin Teske local n=0 1112a622223fSDevin Teske for disk in $disks; do 1113cd88b886SDevin Teske zfs_create_diskpart $disk $n || return $FAILURE 11142875e59fSOllivier Robert # Now $bootpart, $targetpart, and $swappart are set (suffix 11152875e59fSOllivier Robert # for $disk) 11167cae6aabSDevin Teske if [ "$ZFSBOOT_BOOT_POOL" ]; then 11177cae6aabSDevin Teske boot_vdevs="$boot_vdevs $disk$bootpart" 11187cae6aabSDevin Teske fi 11197cae6aabSDevin Teske zroot_vdevs="$zroot_vdevs $disk$targetpart" 1120e751d176SSteven Hartland if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then 1121e751d176SSteven Hartland zroot_vdevs="$zroot_vdevs.eli" 1122e751d176SSteven Hartland fi 11237cae6aabSDevin Teske 11247cae6aabSDevin Teske n=$(( $n + 1 )) 11257cae6aabSDevin Teske done # disks 11267cae6aabSDevin Teske 11277cae6aabSDevin Teske # 11287cae6aabSDevin Teske # If we need/want a boot pool, create it 11297cae6aabSDevin Teske # 11307cae6aabSDevin Teske if [ "$ZFSBOOT_BOOT_POOL" ]; then 11317cae6aabSDevin Teske local bootpool_vdevtype= # Calculated below 11327cae6aabSDevin Teske local bootpool_options= # Calculated below 11337cae6aabSDevin Teske local bootpool_name="$ZFSBOOT_BOOT_POOL_NAME" 11347cae6aabSDevin Teske local bootpool="$BSDINSTALL_CHROOT/$bootpool_name" 11357cae6aabSDevin Teske local zroot_key="${ZFSBOOT_GELI_KEY_FILE#/}" 11367cae6aabSDevin Teske 11377cae6aabSDevin Teske f_dprintf "$funcname: Setting up boot pool..." 1138cd88b886SDevin Teske [ "$ZFSBOOT_GELI_ENCRYPTION" ] && 11397cae6aabSDevin Teske f_dprintf "$funcname: For encrypted root disk..." 1140cd88b886SDevin Teske 11417cae6aabSDevin Teske # Create parent directory for boot pool 1142a622223fSDevin Teske f_eval_catch -d $funcname umount "$UMOUNT" /mnt 1143bc4a673fSDevin Teske f_eval_catch $funcname mount "$MOUNT_TYPE" tmpfs none \ 1144a622223fSDevin Teske $BSDINSTALL_CHROOT || return $FAILURE 1145cd88b886SDevin Teske 11467cae6aabSDevin Teske # Create mirror across the boot partition on all disks 1147a88393ceSDevin Teske local nvdevs 1148a88393ceSDevin Teske f_count nvdevs $boot_vdevs 1149a88393ceSDevin Teske [ $nvdevs -gt 1 ] && bootpool_vdevtype=mirror 1150cd88b886SDevin Teske 115147206692SDevin Teske create_options="$ZFSBOOT_BOOT_POOL_CREATE_OPTIONS" 11527cae6aabSDevin Teske bootpool_options="-o altroot=$BSDINSTALL_CHROOT" 115347206692SDevin Teske bootpool_options="$bootpool_options $create_options" 11547cae6aabSDevin Teske bootpool_options="$bootpool_options -m \"/$bootpool_name\" -f" 1155bc4a673fSDevin Teske f_eval_catch $funcname zpool "$ZPOOL_CREATE_WITH_OPTIONS" \ 11567cae6aabSDevin Teske "$bootpool_options" "$bootpool_name" \ 11574b4b90d5SDevin Teske "$bootpool_vdevtype" "$boot_vdevs" || 11584b4b90d5SDevin Teske return $FAILURE 115945df402eSDevin Teske 11607cae6aabSDevin Teske f_eval_catch $funcname mkdir "$MKDIR_P" "$bootpool/boot" || 1161cd88b886SDevin Teske return $FAILURE 1162cd88b886SDevin Teske 11637cae6aabSDevin Teske if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then 1164cd88b886SDevin Teske # Generate an encryption key using random(4) 1165bc4a673fSDevin Teske f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \ 11667cae6aabSDevin Teske /dev/random "$bootpool/$zroot_key" \ 11677cae6aabSDevin Teske "bs=4096 count=1" || return $FAILURE 11681ebd9bd4SDevin Teske f_eval_catch $funcname chmod "$CHMOD_MODE" \ 11694ef40262SDevin Teske go-wrx "$bootpool/$zroot_key" || 11704ef40262SDevin Teske return $FAILURE 11717cae6aabSDevin Teske else 11727cae6aabSDevin Teske # Clean up 11737cae6aabSDevin Teske f_eval_catch $funcname zfs "$ZFS_UNMOUNT" \ 11747cae6aabSDevin Teske "$bootpool_name" || return $FAILURE 11757cae6aabSDevin Teske f_eval_catch -d $funcname umount "$UMOUNT" /mnt # tmpfs 11767cae6aabSDevin Teske fi 11777cae6aabSDevin Teske 11787cae6aabSDevin Teske fi 1179cd88b886SDevin Teske 1180a622223fSDevin Teske # 1181cd88b886SDevin Teske # Create the geli(8) GEOMS 1182a622223fSDevin Teske # 11837cae6aabSDevin Teske if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then 11847cae6aabSDevin Teske # Prompt user for password (twice) 1185bc4a673fSDevin Teske if ! msg_enter_new_password="$msg_geli_password" \ 1186bc4a673fSDevin Teske f_dialog_input_password 1187bc4a673fSDevin Teske then 1188bc4a673fSDevin Teske f_dprintf "$funcname: User cancelled" 1189bc4a673fSDevin Teske f_show_err "$msg_user_cancelled" 1190bc4a673fSDevin Teske return $FAILURE 1191bc4a673fSDevin Teske fi 1192a622223fSDevin Teske 1193a622223fSDevin Teske # Initialize geli(8) on each of the target partitions 1194bc4a673fSDevin Teske for disk in $disks; do 1195cd88b886SDevin Teske f_dialog_info "$msg_geli_setup" \ 1196cd88b886SDevin Teske 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 1197a622223fSDevin Teske if ! echo "$pw_password" | f_eval_catch \ 1198a622223fSDevin Teske $funcname geli "$GELI_PASSWORD_INIT" \ 11997cae6aabSDevin Teske "$bootpool/boot/$disk$targetpart.eli" \ 12007cae6aabSDevin Teske AES-XTS "$bootpool/$zroot_key" \ 1201a622223fSDevin Teske $disk$targetpart 1202bc4a673fSDevin Teske then 1203bc4a673fSDevin Teske f_interactive || f_die 1204a622223fSDevin Teske unset pw_password # Sensitive info 1205cd88b886SDevin Teske return $FAILURE 1206bc4a673fSDevin Teske fi 1207a622223fSDevin Teske if ! echo "$pw_password" | f_eval_catch \ 1208a622223fSDevin Teske $funcname geli "$GELI_ATTACH" \ 12097cae6aabSDevin Teske "$bootpool/$zroot_key" $disk$targetpart 1210bc4a673fSDevin Teske then 1211bc4a673fSDevin Teske f_interactive || f_die 1212a622223fSDevin Teske unset pw_password # Sensitive info 1213bc4a673fSDevin Teske return $FAILURE 1214bc4a673fSDevin Teske fi 1215cd88b886SDevin Teske done 1216a622223fSDevin Teske unset pw_password # Sensitive info 1217a622223fSDevin Teske 1218a622223fSDevin Teske # Clean up 12197cae6aabSDevin Teske f_eval_catch $funcname zfs "$ZFS_UNMOUNT" "$bootpool_name" || 12207cae6aabSDevin Teske return $FAILURE 1221a622223fSDevin Teske f_eval_catch -d $funcname umount "$UMOUNT" /mnt # tmpfs 1222cd88b886SDevin Teske fi 122333112d9eSDevin Teske 12242875e59fSOllivier Robert # 12252875e59fSOllivier Robert # Create the gmirror(8) GEOMS for swap 12262875e59fSOllivier Robert # 12272875e59fSOllivier Robert if [ "$ZFSBOOT_SWAP_MIRROR" ]; then 12282875e59fSOllivier Robert for disk in $disks; do 12292875e59fSOllivier Robert swap_devs="$swap_devs $disk$swappart" 12302875e59fSOllivier Robert done 12312875e59fSOllivier Robert f_eval_catch $funcname gmirror "$SWAP_GMIRROR_LABEL" \ 12322875e59fSOllivier Robert "$swap_devs" || return $FAILURE 12332875e59fSOllivier Robert fi 1234cd88b886SDevin Teske 1235cd88b886SDevin Teske # 1236a622223fSDevin Teske # Create the ZFS root pool with desired type and disk devices 1237cd88b886SDevin Teske # 12387cae6aabSDevin Teske f_dprintf "$funcname: Creating root pool..." 123947206692SDevin Teske create_options="$ZFSBOOT_POOL_CREATE_OPTIONS" 1240bc4a673fSDevin Teske f_eval_catch $funcname zpool "$ZPOOL_CREATE_WITH_OPTIONS" \ 124147206692SDevin Teske "-o altroot=$BSDINSTALL_CHROOT $create_options -m none -f" \ 12424b4b90d5SDevin Teske "$zroot_name" "$zroot_vdevtype" "$zroot_vdevs" || 12434b4b90d5SDevin Teske return $FAILURE 1244cd88b886SDevin Teske 1245cd88b886SDevin Teske # 12467cae6aabSDevin Teske # Create ZFS dataset layout within the new root pool 1247cd88b886SDevin Teske # 1248bc4a673fSDevin Teske f_dprintf "$funcname: Creating ZFS datasets..." 1249cd88b886SDevin Teske echo "$ZFSBOOT_DATASETS" | while read dataset options; do 1250cd88b886SDevin Teske # Skip blank lines and comments 1251cd88b886SDevin Teske case "$dataset" in "#"*|"") continue; esac 1252cd88b886SDevin Teske # Remove potential inline comments in options 1253cd88b886SDevin Teske options="${options%%#*}" 1254cd88b886SDevin Teske # Replace tabs with spaces 1255cd88b886SDevin Teske f_replaceall "$options" " " " " options 1256cd88b886SDevin Teske # Reduce contiguous runs of space to one single space 1257cd88b886SDevin Teske oldoptions= 1258cd88b886SDevin Teske while [ "$oldoptions" != "$options" ]; do 1259cd88b886SDevin Teske oldoptions="$options" 1260cd88b886SDevin Teske f_replaceall "$options" " " " " options 1261cd88b886SDevin Teske done 1262cd88b886SDevin Teske # Replace both commas and spaces with ` -o ' 1263cd88b886SDevin Teske f_replaceall "$options" "[ ,]" " -o " options 1264cd88b886SDevin Teske # Create the dataset with desired options 1265bc4a673fSDevin Teske f_eval_catch $funcname zfs "$ZFS_CREATE_WITH_OPTIONS" \ 12667cae6aabSDevin Teske "${options:+-o $options}" "$zroot_name$dataset" || 1267cd88b886SDevin Teske return $FAILURE 1268cd88b886SDevin Teske done 1269cd88b886SDevin Teske 12707e3ebc5bSAllan Jude # 12717e3ebc5bSAllan Jude # Set a mountpoint for the root of the pool so newly created datasets 12727e3ebc5bSAllan Jude # have a mountpoint to inherit 12737e3ebc5bSAllan Jude # 12747e3ebc5bSAllan Jude f_dprintf "$funcname: Setting mountpoint for root of the pool..." 12757e3ebc5bSAllan Jude f_eval_catch $funcname zfs "$ZFS_SET" \ 12767e3ebc5bSAllan Jude "mountpoint=/$zroot_name" "$zroot_name" || 12777e3ebc5bSAllan Jude return $FAILURE 12787e3ebc5bSAllan Jude 1279cd88b886SDevin Teske # Touch up permissions on the tmp directories 1280bc4a673fSDevin Teske f_dprintf "$funcname: Modifying directory permissions..." 1281bc4a673fSDevin Teske local dir 1282bc4a673fSDevin Teske for dir in /tmp /var/tmp; do 1283bc4a673fSDevin Teske f_eval_catch $funcname chmod "$CHMOD_MODE" 1777 \ 12844ffa3da5SAllan Jude $BSDINSTALL_CHROOT$dir || return $FAILURE 1285bc4a673fSDevin Teske done 1286cd88b886SDevin Teske 1287cd88b886SDevin Teske # Create symlink(s) 12887cae6aabSDevin Teske if [ "$ZFSBOOT_BOOT_POOL" ]; then 12897cae6aabSDevin Teske f_dprintf "$funcname: Creating /boot symlink for boot pool..." 12907cae6aabSDevin Teske f_eval_catch $funcname ln "$LN_SF" "$bootpool_name/boot" \ 1291a622223fSDevin Teske $BSDINSTALL_CHROOT/boot || return $FAILURE 1292bc4a673fSDevin Teske fi 1293cd88b886SDevin Teske 1294cd88b886SDevin Teske # Set bootfs property 12957cae6aabSDevin Teske local zroot_bootfs="$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOTFS_NAME" 1296bc4a673fSDevin Teske f_dprintf "$funcname: Setting bootfs property..." 1297bc4a673fSDevin Teske f_eval_catch $funcname zpool "$ZPOOL_SET" \ 12987cae6aabSDevin Teske "bootfs=\"$zroot_name/$zroot_bootfs\"" "$zroot_name" || 12997cae6aabSDevin Teske return $FAILURE 1300cd88b886SDevin Teske 1301cd88b886SDevin Teske # Export the pool(s) 1302bc4a673fSDevin Teske f_dprintf "$funcname: Temporarily exporting ZFS pool(s)..." 13037cae6aabSDevin Teske f_eval_catch $funcname zpool "$ZPOOL_EXPORT" "$zroot_name" || 1304bc4a673fSDevin Teske return $FAILURE 13057cae6aabSDevin Teske if [ "$ZFSBOOT_BOOT_POOL" ]; then 1306bc4a673fSDevin Teske f_eval_catch $funcname zpool "$ZPOOL_EXPORT" \ 13077cae6aabSDevin Teske "$bootpool_name" || return $FAILURE 1308bc4a673fSDevin Teske fi 1309cd88b886SDevin Teske 13107cae6aabSDevin Teske # MBR boot loader touch-up 1311cd88b886SDevin Teske if [ "$ZFSBOOT_PARTITION_SCHEME" = "MBR" ]; then 1312bc4a673fSDevin Teske f_dprintf "$funcname: Updating MBR boot loader on disks..." 1313cd88b886SDevin Teske # Stick the ZFS boot loader in the "convienient hole" after 1314cd88b886SDevin Teske # the ZFS internal metadata 1315bc4a673fSDevin Teske for disk in $disks; do 1316bc4a673fSDevin Teske f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \ 1317a622223fSDevin Teske /boot/zfsboot /dev/$disk$bootpart \ 1318bc4a673fSDevin Teske "skip=1 seek=1024" || return $FAILURE 1319cd88b886SDevin Teske done 1320cd88b886SDevin Teske fi 1321cd88b886SDevin Teske 1322cd88b886SDevin Teske # Re-import the ZFS pool(s) 1323bc4a673fSDevin Teske f_dprintf "$funcname: Re-importing ZFS pool(s)..." 1324bc4a673fSDevin Teske f_eval_catch $funcname zpool "$ZPOOL_IMPORT_WITH_OPTIONS" \ 13257cae6aabSDevin Teske "-o altroot=\"$BSDINSTALL_CHROOT\"" "$zroot_name" || 1326bc4a673fSDevin Teske return $FAILURE 13277cae6aabSDevin Teske if [ "$ZFSBOOT_BOOT_POOL" ]; then 1328bc4a673fSDevin Teske f_eval_catch $funcname zpool "$ZPOOL_IMPORT_WITH_OPTIONS" \ 13297cae6aabSDevin Teske "-o altroot=\"$BSDINSTALL_CHROOT\"" \ 13307cae6aabSDevin Teske "$bootpool_name" || return $FAILURE 1331bc4a673fSDevin Teske fi 1332cd88b886SDevin Teske 1333cd88b886SDevin Teske # While this is apparently not needed, it seems to help MBR 13346311cc9eSDevin Teske f_dprintf "$funcname: Configuring zpool.cache for zroot..." 1335a622223fSDevin Teske f_eval_catch $funcname mkdir "$MKDIR_P" $BSDINSTALL_CHROOT/boot/zfs || 1336bc4a673fSDevin Teske return $FAILURE 1337bc4a673fSDevin Teske f_eval_catch $funcname zpool "$ZPOOL_SET" \ 1338a622223fSDevin Teske "cachefile=\"$BSDINSTALL_CHROOT/boot/zfs/zpool.cache\"" \ 13397cae6aabSDevin Teske "$zroot_name" || return $FAILURE 1340cd88b886SDevin Teske 134113d8e1ceSDevin Teske # Last, but not least... required lines for rc.conf(5)/loader.conf(5) 1342cd88b886SDevin Teske # NOTE: We later concatenate these into their destination 1343bc4a673fSDevin Teske f_dprintf "%s: Configuring rc.conf(5)/loader.conf(5) additions..." \ 1344bc4a673fSDevin Teske "$funcname" 1345bc4a673fSDevin Teske f_eval_catch $funcname echo "$ECHO_APPEND" 'zfs_enable=\"YES\"' \ 1346a622223fSDevin Teske $BSDINSTALL_TMPETC/rc.conf.zfs || return $FAILURE 1347ee482f2cSDevin Teske f_eval_catch $funcname echo "$ECHO_APPEND" \ 1348ee482f2cSDevin Teske 'kern.geom.label.disk_ident.enable=\"0\"' \ 1349ee482f2cSDevin Teske $BSDINSTALL_TMPBOOT/loader.conf.zfs || return $FAILURE 13502875e59fSOllivier Robert f_eval_catch $funcname echo "$ECHO_APPEND" \ 13512875e59fSOllivier Robert 'kern.geom.label.gptid.enable=\"0\"' \ 13522875e59fSOllivier Robert $BSDINSTALL_TMPBOOT/loader.conf.zfs || return $FAILURE 13532875e59fSOllivier Robert 13542875e59fSOllivier Robert if [ "$ZFSBOOT_SWAP_MIRROR" ]; then 135533112d9eSDevin Teske f_eval_catch $funcname echo "$ECHO_APPEND" \ 135633112d9eSDevin Teske 'geom_mirror_load=\"YES\"' \ 135733112d9eSDevin Teske $BSDINSTALL_TMPBOOT/loader.conf.gmirror || 135833112d9eSDevin Teske return $FAILURE 13592875e59fSOllivier Robert fi 1360cd88b886SDevin Teske 13617cae6aabSDevin Teske # We're all done unless we should go on for boot pool 13627cae6aabSDevin Teske [ "$ZFSBOOT_BOOT_POOL" ] || return $SUCCESS 1363cd88b886SDevin Teske 13646311cc9eSDevin Teske # Set cachefile for boot pool so it auto-imports at system start 13656311cc9eSDevin Teske f_dprintf "$funcname: Configuring zpool.cache for boot pool..." 13666311cc9eSDevin Teske f_eval_catch $funcname zpool "$ZPOOL_SET" \ 13676311cc9eSDevin Teske "cachefile=\"$BSDINSTALL_CHROOT/boot/zfs/zpool.cache\"" \ 13686311cc9eSDevin Teske "$bootpool_name" || return $FAILURE 13696311cc9eSDevin Teske 1370bc4a673fSDevin Teske # Some additional geli(8) requirements for loader.conf(5) 1371bc4a673fSDevin Teske for option in \ 1372a622223fSDevin Teske 'zpool_cache_load=\"YES\"' \ 1373a622223fSDevin Teske 'zpool_cache_type=\"/boot/zfs/zpool.cache\"' \ 1374a622223fSDevin Teske 'zpool_cache_name=\"/boot/zfs/zpool.cache\"' \ 1375bc4a673fSDevin Teske ; do 1376a622223fSDevin Teske f_eval_catch $funcname echo "$ECHO_APPEND" "$option" \ 1377a622223fSDevin Teske $BSDINSTALL_TMPBOOT/loader.conf.zfs || 1378bc4a673fSDevin Teske return $FAILURE 1379bc4a673fSDevin Teske done 13807cae6aabSDevin Teske f_eval_catch $funcname printf "$PRINTF_CONF" vfs.root.mountfrom \ 13817cae6aabSDevin Teske "\"zfs:$zroot_name/$zroot_bootfs\"" \ 13827cae6aabSDevin Teske $BSDINSTALL_TMPBOOT/loader.conf.root || return $FAILURE 13837cae6aabSDevin Teske 13847cae6aabSDevin Teske # We're all done unless we should go on to do encryption 13857cae6aabSDevin Teske [ "$ZFSBOOT_GELI_ENCRYPTION" ] || return $SUCCESS 138613d8e1ceSDevin Teske 1387cd88b886SDevin Teske # 1388cd88b886SDevin Teske # Configure geli(8)-based encryption 1389cd88b886SDevin Teske # 1390bc4a673fSDevin Teske f_dprintf "$funcname: Configuring disk encryption..." 1391bc4a673fSDevin Teske f_eval_catch $funcname echo "$ECHO_APPEND" 'aesni_load=\"YES\"' \ 1392a622223fSDevin Teske $BSDINSTALL_TMPBOOT/loader.conf.aesni || return $FAILURE 1393bc4a673fSDevin Teske f_eval_catch $funcname echo "$ECHO_APPEND" 'geom_eli_load=\"YES\"' \ 1394a622223fSDevin Teske $BSDINSTALL_TMPBOOT/loader.conf.geli || return $FAILURE 139543d4f8c4SDevin Teske f_eval_catch $funcname echo "$ECHO_APPEND" \ 139643d4f8c4SDevin Teske 'geom_eli_passphrase_prompt=\"YES\"' \ 139743d4f8c4SDevin Teske $BSDINSTALL_TMPBOOT/loader.conf.geli || return $FAILURE 1398bc4a673fSDevin Teske for disk in $disks; do 1399bc4a673fSDevin Teske f_eval_catch $funcname printf "$PRINTF_CONF" \ 1400a622223fSDevin Teske geli_%s_keyfile0_load "$disk$targetpart YES" \ 1401a622223fSDevin Teske $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart || 1402cd88b886SDevin Teske return $FAILURE 1403bc4a673fSDevin Teske f_eval_catch $funcname printf "$PRINTF_CONF" \ 1404bc4a673fSDevin Teske geli_%s_keyfile0_type \ 1405a622223fSDevin Teske "$disk$targetpart $disk$targetpart:geli_keyfile0" \ 1406a622223fSDevin Teske $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart || 1407cd88b886SDevin Teske return $FAILURE 1408bc4a673fSDevin Teske f_eval_catch $funcname printf "$PRINTF_CONF" \ 1409bc4a673fSDevin Teske geli_%s_keyfile0_name \ 1410a622223fSDevin Teske "$disk$targetpart \"$ZFSBOOT_GELI_KEY_FILE\"" \ 1411a622223fSDevin Teske $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart || 1412cd88b886SDevin Teske return $FAILURE 1413cd88b886SDevin Teske done 1414cd88b886SDevin Teske 1415cd88b886SDevin Teske return $SUCCESS 1416cd88b886SDevin Teske} 1417cd88b886SDevin Teske 1418cd88b886SDevin Teske# dialog_menu_diskinfo 1419cd88b886SDevin Teske# 1420cd88b886SDevin Teske# Prompt the user to select a disk and then provide detailed info on it. 1421cd88b886SDevin Teske# 1422cd88b886SDevin Teskedialog_menu_diskinfo() 1423cd88b886SDevin Teske{ 1424a88393ceSDevin Teske local device disk 1425cd88b886SDevin Teske 1426cd88b886SDevin Teske # 1427cd88b886SDevin Teske # Break from loop when user cancels disk selection 1428cd88b886SDevin Teske # 1429cd88b886SDevin Teske while :; do 1430a88393ceSDevin Teske device=$( msg_cancel="$msg_back" f_device_menu \ 1431cd88b886SDevin Teske "$DIALOG_TITLE" "$msg_select_a_disk_device" "" \ 1432cd88b886SDevin Teske $DEVICE_TYPE_DISK 2>&1 ) || break 1433a88393ceSDevin Teske $device get name disk 1434cd88b886SDevin Teske 1435cd88b886SDevin Teske # Show gpart(8) `show' and camcontrol(8) `inquiry' data 1436cd88b886SDevin Teske f_show_msg "$msg_detailed_disk_info" \ 1437cd88b886SDevin Teske "$disk" "$( gpart show $disk 2> /dev/null )" \ 1438cd88b886SDevin Teske "$disk" "$( camcontrol inquiry $disk 2> /dev/null )" \ 1439cd88b886SDevin Teske "$disk" "$( camcontrol identify $disk 2> /dev/null )" 1440cd88b886SDevin Teske done 1441cd88b886SDevin Teske 1442cd88b886SDevin Teske return $SUCCESS 1443cd88b886SDevin Teske} 1444cd88b886SDevin Teske 1445cd88b886SDevin Teske############################################################ MAIN 1446cd88b886SDevin Teske 1447cd88b886SDevin Teske# 1448cd88b886SDevin Teske# Initialize 1449cd88b886SDevin Teske# 1450cd88b886SDevin Teskef_dialog_title "$msg_zfs_configuration" 1451cd88b886SDevin Teskef_dialog_backtitle "$msg_freebsd_installer" 1452cd88b886SDevin Teske 1453cd88b886SDevin Teske# User may have specifically requested ZFS-related operations be interactive 1454cd88b886SDevin Teske! f_interactive && f_zfsinteractive && unset $VAR_NONINTERACTIVE 1455cd88b886SDevin Teske 1456cd88b886SDevin Teske# 1457bc4a673fSDevin Teske# Debugging 1458bc4a673fSDevin Teske# 1459bc4a673fSDevin Teskef_dprintf "BSDINSTALL_CHROOT=[%s]" "$BSDINSTALL_CHROOT" 1460bc4a673fSDevin Teskef_dprintf "BSDINSTALL_TMPETC=[%s]" "$BSDINSTALL_TMPETC" 1461a622223fSDevin Teskef_dprintf "FSTAB_FMT=[%s]" "$FSTAB_FMT" 1462bc4a673fSDevin Teske 1463bc4a673fSDevin Teske# 146412307018SAllan Jude# If the system was booted with UEFI, warn the user that FreeBSD can't do 146512307018SAllan Jude# ZFS with UEFI yet 146612307018SAllan Jude# 146712307018SAllan Judeif f_interactive; then 146812307018SAllan Jude bootmethod=$( sysctl -n machdep.bootmethod ) 146912307018SAllan Jude f_dprintf "machdep.bootmethod=[%s]" "$bootmethod" 147012307018SAllan Jude if [ "$bootmethod" != "BIOS" ]; then 147112307018SAllan Jude dialog_uefi_prompt 147212307018SAllan Jude retval=$? 147312307018SAllan Jude f_dprintf "uefi_prompt=[%s]" "$retval" 147412307018SAllan Jude [ $retval -eq $DIALOG_OK ] || f_die 147512307018SAllan Jude fi 147612307018SAllan Judefi 147712307018SAllan Jude 147812307018SAllan Jude# 1479cd88b886SDevin Teske# Loop over the main menu until we've accomplished what we came here to do 1480cd88b886SDevin Teske# 1481cd88b886SDevin Teskewhile :; do 1482cd88b886SDevin Teske if ! f_interactive; then 1483cd88b886SDevin Teske retval=$DIALOG_OK 1484bc4a673fSDevin Teske mtag=">>> $msg_install" 1485cd88b886SDevin Teske else 1486cd88b886SDevin Teske dialog_menu_main 1487cd88b886SDevin Teske retval=$? 1488cd88b886SDevin Teske f_dialog_menutag_fetch mtag 1489cd88b886SDevin Teske fi 1490cd88b886SDevin Teske 1491bc4a673fSDevin Teske f_dprintf "retval=%u mtag=[%s]" $retval "$mtag" 1492cd88b886SDevin Teske [ $retval -eq $DIALOG_OK ] || f_die 1493cd88b886SDevin Teske 1494cd88b886SDevin Teske case "$mtag" in 1495bc4a673fSDevin Teske ">>> $msg_install") 1496cd88b886SDevin Teske # 1497cd88b886SDevin Teske # First, validate the user's selections 1498cd88b886SDevin Teske # 1499cd88b886SDevin Teske 1500cd88b886SDevin Teske # Make sure they gave us a name for the pool 1501cd88b886SDevin Teske if [ ! "$ZFSBOOT_POOL_NAME" ]; then 1502bc4a673fSDevin Teske f_dprintf "Pool name cannot be empty." 1503bc4a673fSDevin Teske f_show_err "$msg_pool_name_cannot_be_empty" 1504cd88b886SDevin Teske continue 1505cd88b886SDevin Teske fi 1506bc4a673fSDevin Teske 1507bc4a673fSDevin Teske # Validate vdev type against number of disks selected/scripted 1508bc4a673fSDevin Teske # (also validates that ZFSBOOT_DISKS are real [probed] disks) 1509bc4a673fSDevin Teske # NB: dialog_menu_layout supports running non-interactively 1510bc4a673fSDevin Teske dialog_menu_layout || continue 1511bc4a673fSDevin Teske 1512cd88b886SDevin Teske # Make sure each disk will be at least 50% ZFS 1513cd88b886SDevin Teske if f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize && 15147cae6aabSDevin Teske f_expand_number "$ZFSBOOT_BOOT_POOL_SIZE" bootsize 1515cd88b886SDevin Teske then 1516cd88b886SDevin Teske minsize=$swapsize teeny_disks= 15177cae6aabSDevin Teske [ "$ZFSBOOT_BOOT_POOL" ] && 15187cae6aabSDevin Teske minsize=$(( $minsize + $bootsize )) 1519bc4a673fSDevin Teske for disk in $ZFSBOOT_DISKS; do 1520a88393ceSDevin Teske debug= f_device_find -1 \ 1521a88393ceSDevin Teske $disk $DEVICE_TYPE_DISK device 1522a88393ceSDevin Teske $device get capacity disksize || continue 1523a88393ceSDevin Teske [ ${disksize:-0} -ge 0 ] || disksize=0 1524cd88b886SDevin Teske disksize=$(( $disksize - $minsize )) 1525cd88b886SDevin Teske [ $disksize -lt $minsize ] && 1526cd88b886SDevin Teske teeny_disks="$teeny_disks $disk" 1527cd88b886SDevin Teske done 1528cd88b886SDevin Teske if [ "$teeny_disks" ]; then 15297cae6aabSDevin Teske f_dprintf "swapsize=[%s] bootsize[%s] %s" \ 1530bc4a673fSDevin Teske "$ZFSBOOT_SWAP_SIZE" \ 15317cae6aabSDevin Teske "$ZFSBOOT_BOOT_POOL_SIZE" \ 15327cae6aabSDevin Teske "minsize=[$minsize]" 1533bc4a673fSDevin Teske f_dprintf "These disks are too small: %s" \ 1534bc4a673fSDevin Teske "$teeny_disks" 1535bc4a673fSDevin Teske f_show_err "$msg_these_disks_are_too_small" \ 1536cd88b886SDevin Teske "$ZFSBOOT_SWAP_SIZE" \ 15377cae6aabSDevin Teske "$ZFSBOOT_BOOT_POOL_SIZE" \ 1538cd88b886SDevin Teske "$teeny_disks" 1539cd88b886SDevin Teske continue 1540cd88b886SDevin Teske fi 1541cd88b886SDevin Teske fi 1542cd88b886SDevin Teske 1543cd88b886SDevin Teske # 1544cd88b886SDevin Teske # Last Chance! 1545cd88b886SDevin Teske # 1546bc4a673fSDevin Teske if f_interactive; then 1547bc4a673fSDevin Teske dialog_last_chance $ZFSBOOT_DISKS || continue 1548cd88b886SDevin Teske fi 1549cd88b886SDevin Teske 1550cd88b886SDevin Teske # 1551cd88b886SDevin Teske # Let's do this 1552cd88b886SDevin Teske # 1553cd88b886SDevin Teske 1554cd88b886SDevin Teske vdev_type="$ZFSBOOT_VDEV_TYPE" 1555cd88b886SDevin Teske 1556cd88b886SDevin Teske # Blank the vdev type for the default layout 1557cd88b886SDevin Teske [ "$vdev_type" = "stripe" ] && vdev_type= 1558cd88b886SDevin Teske 1559bc4a673fSDevin Teske zfs_create_boot "$ZFSBOOT_POOL_NAME" \ 1560bc4a673fSDevin Teske "$vdev_type" $ZFSBOOT_DISKS || continue 1561cd88b886SDevin Teske 1562cd88b886SDevin Teske break # to success 1563cd88b886SDevin Teske ;; 1564bc4a673fSDevin Teske ?" $msg_pool_type_disks") 1565bc4a673fSDevin Teske ZFSBOOT_CONFIRM_LAYOUT=1 1566bc4a673fSDevin Teske dialog_menu_layout 1567bc4a673fSDevin Teske # User has poked settings, disable later confirmation 1568bc4a673fSDevin Teske ZFSBOOT_CONFIRM_LAYOUT= 1569bc4a673fSDevin Teske ;; 1570cd88b886SDevin Teske "- $msg_rescan_devices") f_device_rescan ;; 1571cd88b886SDevin Teske "- $msg_disk_info") dialog_menu_diskinfo ;; 1572cd88b886SDevin Teske ?" $msg_pool_name") 1573cd88b886SDevin Teske # Prompt the user to input/change the name for the new pool 1574cd88b886SDevin Teske f_dialog_input input \ 1575cd88b886SDevin Teske "$msg_please_enter_a_name_for_your_zpool" \ 1576cd88b886SDevin Teske "$ZFSBOOT_POOL_NAME" && 1577cd88b886SDevin Teske ZFSBOOT_POOL_NAME="$input" 1578cd88b886SDevin Teske ;; 1579cd88b886SDevin Teske ?" $msg_force_4k_sectors") 1580cd88b886SDevin Teske # Toggle the variable referenced both by the menu and later 1581b4843bd6SSteven Hartland if [ "$ZFSBOOT_FORCE_4K_SECTORS" ]; then 1582b4843bd6SSteven Hartland ZFSBOOT_FORCE_4K_SECTORS= 1583cd88b886SDevin Teske else 1584b4843bd6SSteven Hartland ZFSBOOT_FORCE_4K_SECTORS=1 1585cd88b886SDevin Teske fi 1586cd88b886SDevin Teske ;; 1587bc4a673fSDevin Teske ?" $msg_encrypt_disks") 1588cd88b886SDevin Teske # Toggle the variable referenced both by the menu and later 1589cd88b886SDevin Teske if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then 1590cd88b886SDevin Teske ZFSBOOT_GELI_ENCRYPTION= 1591cd88b886SDevin Teske else 1592b4843bd6SSteven Hartland ZFSBOOT_FORCE_4K_SECTORS=1 1593cd88b886SDevin Teske ZFSBOOT_GELI_ENCRYPTION=1 1594cd88b886SDevin Teske fi 1595cd88b886SDevin Teske ;; 1596cd88b886SDevin Teske ?" $msg_partition_scheme") 1597cd88b886SDevin Teske # Toggle between GPT and MBR 1598cd88b886SDevin Teske if [ "$ZFSBOOT_PARTITION_SCHEME" = GPT ]; then 1599cd88b886SDevin Teske ZFSBOOT_PARTITION_SCHEME=MBR 16007059fa6fSAllan Jude elif [ "$ZFSBOOT_PARTITION_SCHEME" = MBR ]; then 16017059fa6fSAllan Jude ZFSBOOT_PARTITION_SCHEME="GPT + Active" 16027059fa6fSAllan Jude elif [ "$ZFSBOOT_PARTITION_SCHEME" = "GPT + Active" ]; then 16037059fa6fSAllan Jude ZFSBOOT_PARTITION_SCHEME="GPT + Lenovo Fix" 1604cd88b886SDevin Teske else 1605cd88b886SDevin Teske ZFSBOOT_PARTITION_SCHEME=GPT 1606cd88b886SDevin Teske fi 1607cd88b886SDevin Teske ;; 1608cd88b886SDevin Teske ?" $msg_swap_size") 1609cd88b886SDevin Teske # Prompt the user to input/change the swap size for each disk 1610169ff110SAllan Jude while :; do 1611cd88b886SDevin Teske f_dialog_input input \ 1612cd88b886SDevin Teske "$msg_please_enter_amount_of_swap_space" \ 1613cd88b886SDevin Teske "$ZFSBOOT_SWAP_SIZE" && 161430c8ebe9SDevin Teske ZFSBOOT_SWAP_SIZE="${input:-0}" 1615169ff110SAllan Jude if f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize 1616169ff110SAllan Jude then 1617169ff110SAllan Jude if [ $swapsize -ne 0 -a $swapsize -lt 104857600 ]; then 1618169ff110SAllan Jude f_show_err "$msg_swap_toosmall" \ 1619169ff110SAllan Jude "$ZFSBOOT_SWAP_SIZE" 1620169ff110SAllan Jude continue; 1621169ff110SAllan Jude else 1622169ff110SAllan Jude break; 1623169ff110SAllan Jude fi 1624169ff110SAllan Jude else 1625169ff110SAllan Jude f_show_err "$msg_swap_invalid" \ 1626169ff110SAllan Jude "$ZFSBOOT_SWAP_SIZE" 1627169ff110SAllan Jude continue; 1628169ff110SAllan Jude fi 1629169ff110SAllan Jude done 1630cd88b886SDevin Teske ;; 16312875e59fSOllivier Robert ?" $msg_swap_mirror") 16322875e59fSOllivier Robert # Toggle the variable referenced both by the menu and later 16332875e59fSOllivier Robert if [ "$ZFSBOOT_SWAP_MIRROR" ]; then 16342875e59fSOllivier Robert ZFSBOOT_SWAP_MIRROR= 16352875e59fSOllivier Robert else 16362875e59fSOllivier Robert ZFSBOOT_SWAP_MIRROR=1 16372875e59fSOllivier Robert fi 16382875e59fSOllivier Robert ;; 16392875e59fSOllivier Robert ?" $msg_swap_encrypt") 16402875e59fSOllivier Robert # Toggle the variable referenced both by the menu and later 16412875e59fSOllivier Robert if [ "$ZFSBOOT_SWAP_ENCRYPTION" ]; then 16422875e59fSOllivier Robert ZFSBOOT_SWAP_ENCRYPTION= 16432875e59fSOllivier Robert else 16442875e59fSOllivier Robert ZFSBOOT_SWAP_ENCRYPTION=1 16452875e59fSOllivier Robert fi 16462875e59fSOllivier Robert ;; 1647cd88b886SDevin Teske esac 1648cd88b886SDevin Teskedone 1649cd88b886SDevin Teske 1650*65f36140SDevin Teskeexit $SUCCESS 1651cd88b886SDevin Teske 1652cd88b886SDevin Teske################################################################################ 1653cd88b886SDevin Teske# END 1654cd88b886SDevin Teske################################################################################ 1655