1cd88b886SDevin Teske#!/bin/sh 2cd88b886SDevin Teske#- 3cd88b886SDevin Teske# Copyright (c) 2013 Allan Jude 4cd88b886SDevin Teske# Copyright (c) 2013 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 160ed8690e3SOllivier Robert /var/crash exec=off,setuid=off 161ed8690e3SOllivier Robert /var/log exec=off,setuid=off 162ed8690e3SOllivier Robert /var/mail atime=on 163ed8690e3SOllivier Robert /var/tmp setuid=off 164cd88b886SDevin Teske" # END-QUOTE 165cd88b886SDevin Teske 166bc4a673fSDevin Teske# 167bc4a673fSDevin Teske# If interactive and the user has not explicitly chosen a vdev type or disks, 168bc4a673fSDevin Teske# make the user confirm scripted/default choices when proceeding to install. 169bc4a673fSDevin Teske# 170bc4a673fSDevin Teske: ${ZFSBOOT_CONFIRM_LAYOUT:=1} 171bc4a673fSDevin Teske 172cd88b886SDevin Teske############################################################ GLOBALS 173cd88b886SDevin Teske 174cd88b886SDevin Teske# 175bc4a673fSDevin Teske# Format of a line in printf(1) syntax to add to fstab(5) 176bc4a673fSDevin Teske# 177bc4a673fSDevin TeskeFSTAB_FMT="%s\t\t%s\t%s\t%s\t\t%s\t%s\n" 178bc4a673fSDevin Teske 179bc4a673fSDevin Teske# 180bc4a673fSDevin Teske# Command strings for various tasks 181bc4a673fSDevin Teske# 182bc4a673fSDevin TeskeCHMOD_MODE='chmod %s "%s"' 183bc4a673fSDevin TeskeDD_WITH_OPTIONS='dd if="%s" of="%s" %s' 184bc4a673fSDevin TeskeECHO_APPEND='echo "%s" >> "%s"' 185bc4a673fSDevin TeskeGELI_ATTACH='geli attach -j - -k "%s" "%s"' 186a622223fSDevin TeskeGELI_DETACH_F='geli detach -f "%s"' 187bc4a673fSDevin TeskeGELI_PASSWORD_INIT='geli init -b -B "%s" -e %s -J - -K "%s" -l 256 -s 4096 "%s"' 188bc4a673fSDevin TeskeGPART_ADD='gpart add -t %s "%s"' 189bc4a673fSDevin TeskeGPART_ADD_INDEX='gpart add -i %s -t %s "%s"' 190bc4a673fSDevin TeskeGPART_ADD_INDEX_WITH_SIZE='gpart add -i %s -t %s -s %s "%s"' 191bc4a673fSDevin TeskeGPART_ADD_LABEL='gpart add -l %s -t %s "%s"' 192bc4a673fSDevin TeskeGPART_ADD_LABEL_WITH_SIZE='gpart add -l %s -t %s -s %s "%s"' 193bc4a673fSDevin TeskeGPART_BOOTCODE='gpart bootcode -b "%s" "%s"' 194bc4a673fSDevin TeskeGPART_BOOTCODE_PART='gpart bootcode -b "%s" -p "%s" -i %s "%s"' 195bc4a673fSDevin TeskeGPART_CREATE='gpart create -s %s "%s"' 196a622223fSDevin TeskeGPART_DESTROY_F='gpart destroy -F "%s"' 197bc4a673fSDevin TeskeGPART_SET_ACTIVE='gpart set -a active -i %s "%s"' 198a622223fSDevin TeskeGRAID_DELETE='graid delete "%s"' 199bc4a673fSDevin TeskeLN_SF='ln -sf "%s" "%s"' 200bc4a673fSDevin TeskeMKDIR_P='mkdir -p "%s"' 201bc4a673fSDevin TeskeMOUNT_TYPE='mount -t %s "%s" "%s"' 202bc4a673fSDevin TeskePRINTF_CONF="printf '%s=\"%%s\"\\\n' %s >> \"%s\"" 203bc4a673fSDevin TeskePRINTF_FSTAB='printf "$FSTAB_FMT" "%s" "%s" "%s" "%s" "%s" "%s" >> "%s"' 204bc4a673fSDevin TeskeSHELL_TRUNCATE=':> "%s"' 2052875e59fSOllivier RobertSWAP_GMIRROR_LABEL='gmirror label swap %s' 206b4843bd6SSteven HartlandSYSCTL_ZFS_MIN_ASHIFT_12='sysctl vfs.zfs.min_auto_ashift=12' 207a622223fSDevin TeskeUMOUNT='umount "%s"' 208bc4a673fSDevin TeskeZFS_CREATE_WITH_OPTIONS='zfs create %s "%s"' 209bc4a673fSDevin TeskeZFS_SET='zfs set "%s" "%s"' 210bc4a673fSDevin TeskeZFS_UNMOUNT='zfs unmount "%s"' 211bc4a673fSDevin TeskeZPOOL_CREATE_WITH_OPTIONS='zpool create %s "%s" %s %s' 212a88393ceSDevin TeskeZPOOL_DESTROY='zpool destroy "%s"' 213bc4a673fSDevin TeskeZPOOL_EXPORT='zpool export "%s"' 214bc4a673fSDevin TeskeZPOOL_IMPORT_WITH_OPTIONS='zpool import %s "%s"' 215a622223fSDevin TeskeZPOOL_LABELCLEAR_F='zpool labelclear -f "%s"' 216bc4a673fSDevin TeskeZPOOL_SET='zpool set %s "%s"' 217bc4a673fSDevin Teske 218bc4a673fSDevin Teske# 219cd88b886SDevin Teske# Strings that should be moved to an i18n file and loaded with f_include_lang() 220cd88b886SDevin Teske# 221cd88b886SDevin Teskehline_alnum_arrows_punc_tab_enter="Use alnum, arrows, punctuation, TAB or ENTER" 222cd88b886SDevin Teskehline_arrows_space_tab_enter="Use arrows, SPACE, TAB or ENTER" 223cd88b886SDevin Teskehline_arrows_tab_enter="Press arrows, TAB or ENTER" 224bc4a673fSDevin Teskemsg_an_unknown_error_occurred="An unknown error occurred" 225cd88b886SDevin Teskemsg_back="Back" 226cd88b886SDevin Teskemsg_cancel="Cancel" 227bc4a673fSDevin Teskemsg_change_selection="Change Selection" 228cd88b886SDevin Teskemsg_configure_options="Configure Options:" 229cd88b886SDevin 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" 230cd88b886SDevin Teskemsg_disk_info="Disk Info" 231cd88b886SDevin Teskemsg_disk_info_help="Get detailed information on disk device(s)" 232695a612fSOllivier Robertmsg_disk_singular="disk" 233695a612fSOllivier Robertmsg_disk_plural="disks" 234bc4a673fSDevin Teskemsg_encrypt_disks="Encrypt Disks?" 235bc4a673fSDevin Teskemsg_encrypt_disks_help="Use geli(8) to encrypt all data partitions" 236bc4a673fSDevin Teskemsg_error="Error" 237cd88b886SDevin Teskemsg_force_4k_sectors="Force 4K Sectors?" 238b4843bd6SSteven Hartlandmsg_force_4k_sectors_help="Use sysctl(8) vfs.zfs.min_auto_ashift=12 to force 4K sectors" 239cd88b886SDevin Teskemsg_freebsd_installer="FreeBSD Installer" 240cd88b886SDevin 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" 2417a434c5cSDevin Teskemsg_geli_setup="Initializing encryption on selected disks,\n this will take several seconds per disk" 242bc4a673fSDevin Teskemsg_install="Install" 243bc4a673fSDevin Teskemsg_install_desc="Proceed with Installation" 244bc4a673fSDevin Teskemsg_install_help="Create ZFS boot pool with displayed options" 2457cae6aabSDevin Teskemsg_invalid_boot_pool_size="Invalid boot pool size \`%s'" 246bc4a673fSDevin Teskemsg_invalid_disk_argument="Invalid disk argument \`%s'" 247bc4a673fSDevin Teskemsg_invalid_index_argument="Invalid index argument \`%s'" 248bc4a673fSDevin Teskemsg_invalid_swap_size="Invalid swap size \`%s'" 249cd88b886SDevin Teskemsg_invalid_virtual_device_type="Invalid Virtual Device type \`%s'" 250bc4a673fSDevin 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" 251bc4a673fSDevin 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' 252cd88b886SDevin Teskemsg_mirror_desc="Mirror - n-Way Mirroring" 253cd88b886SDevin Teskemsg_mirror_help="[2+ Disks] Mirroring provides the best performance, but the least storage" 254bc4a673fSDevin Teskemsg_missing_disk_arguments="missing disk arguments" 255bc4a673fSDevin Teskemsg_missing_one_or_more_scripted_disks="Missing one or more scripted disks!" 256cd88b886SDevin Teskemsg_no="NO" 257cd88b886SDevin Teskemsg_no_disks_present_to_configure="No disk(s) present to configure" 258cd88b886SDevin Teskemsg_no_disks_selected="No disks selected." 259bc4a673fSDevin Teskemsg_not_enough_disks_selected="Not enough disks selected. (%u < %u minimum)" 260bc4a673fSDevin Teskemsg_null_disk_argument="NULL disk argument" 261bc4a673fSDevin Teskemsg_null_index_argument="NULL index argument" 262bc4a673fSDevin Teskemsg_null_poolname="NULL poolname" 263cd88b886SDevin Teskemsg_ok="OK" 264cd88b886SDevin Teskemsg_partition_scheme="Partition Scheme" 265cd88b886SDevin Teskemsg_partition_scheme_help="Toggle between GPT and MBR partitioning schemes" 266cd88b886SDevin Teskemsg_please_enter_a_name_for_your_zpool="Please enter a name for your zpool:" 267cd88b886SDevin Teskemsg_please_enter_amount_of_swap_space="Please enter amount of swap space (SI-Unit suffixes\nrecommended; e.g., \`2g' for 2 Gigabytes):" 268cd88b886SDevin Teskemsg_please_select_one_or_more_disks="Please select one or more disks to create a zpool:" 269cd88b886SDevin Teskemsg_pool_name="Pool Name" 270cd88b886SDevin Teskemsg_pool_name_cannot_be_empty="Pool name cannot be empty." 271cd88b886SDevin Teskemsg_pool_name_help="Customize the name of the zpool to be created (Required)" 272bc4a673fSDevin Teskemsg_pool_type_disks="Pool Type/Disks:" 273bc4a673fSDevin Teskemsg_pool_type_disks_help="Choose type of ZFS Virtual Device and disks to use (Required)" 274cd88b886SDevin Teskemsg_processing_selection="Processing selection..." 275cd88b886SDevin Teskemsg_raidz1_desc="RAID-Z1 - Single Redundant RAID" 276cd88b886SDevin Teskemsg_raidz1_help="[3+ Disks] Withstand failure of 1 disk. Recommended for: 3, 5 or 9 disks" 277cd88b886SDevin Teskemsg_raidz2_desc="RAID-Z2 - Double Redundant RAID" 278cd88b886SDevin Teskemsg_raidz2_help="[4+ Disks] Withstand failure of 2 disks. Recommended for: 4, 6 or 10 disks" 279cd88b886SDevin Teskemsg_raidz3_desc="RAID-Z3 - Triple Redundant RAID" 280cd88b886SDevin Teskemsg_raidz3_help="[5+ Disks] Withstand failure of 3 disks. Recommended for: 5, 7 or 11 disks" 281cd88b886SDevin Teskemsg_rescan_devices="Rescan Devices" 282cd88b886SDevin Teskemsg_rescan_devices_help="Scan for device changes" 283cd88b886SDevin Teskemsg_select="Select" 284cd88b886SDevin Teskemsg_select_a_disk_device="Select a disk device" 285cd88b886SDevin Teskemsg_select_virtual_device_type="Select Virtual Device type:" 286cd88b886SDevin Teskemsg_stripe_desc="Stripe - No Redundancy" 287cd88b886SDevin Teskemsg_stripe_help="[1+ Disks] Striping provides maximum storage but no redundancy" 2882875e59fSOllivier Robertmsg_swap_encrypt="Encrypt Swap?" 2892875e59fSOllivier Robertmsg_swap_encrypt_help="Encrypt swap partitions with temporary keys, discarded on reboot" 2902875e59fSOllivier Robertmsg_swap_mirror="Mirror Swap?" 2912875e59fSOllivier Robertmsg_swap_mirror_help="Mirror swap partitions for redundancy, breaks crash dumps" 292cd88b886SDevin Teskemsg_swap_size="Swap Size" 293cd88b886SDevin Teskemsg_swap_size_help="Customize how much swap space is allocated to each selected disk" 294bc4a673fSDevin 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." 29512307018SAllan 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?" 296bc4a673fSDevin Teskemsg_unable_to_get_disk_capacity="Unable to get disk capacity of \`%s'" 297bc4a673fSDevin Teskemsg_unsupported_partition_scheme="%s is an unsupported partition scheme" 298bc4a673fSDevin Teskemsg_user_cancelled="User Cancelled." 299cd88b886SDevin Teskemsg_yes="YES" 300cd88b886SDevin Teskemsg_zfs_configuration="ZFS Configuration" 301cd88b886SDevin Teske 302cd88b886SDevin Teske############################################################ FUNCTIONS 303cd88b886SDevin Teske 304cd88b886SDevin Teske# dialog_menu_main 305cd88b886SDevin Teske# 306cd88b886SDevin Teske# Display the dialog(1)-based application main menu. 307cd88b886SDevin Teske# 308cd88b886SDevin Teskedialog_menu_main() 309cd88b886SDevin Teske{ 310cd88b886SDevin Teske local title="$DIALOG_TITLE" 311cd88b886SDevin Teske local btitle="$DIALOG_BACKTITLE" 312cd88b886SDevin Teske local prompt="$msg_configure_options" 313cd88b886SDevin Teske local force4k="$msg_no" 314cd88b886SDevin Teske local usegeli="$msg_no" 3152875e59fSOllivier Robert local swapgeli="$msg_no" 3162875e59fSOllivier Robert local swapmirror="$msg_no" 317b4843bd6SSteven Hartland [ "$ZFSBOOT_FORCE_4K_SECTORS" ] && force4k="$msg_yes" 318cd88b886SDevin Teske [ "$ZFSBOOT_GELI_ENCRYPTION" ] && usegeli="$msg_yes" 3192875e59fSOllivier Robert [ "$ZFSBOOT_SWAP_ENCRYPTION" ] && swapgeli="$msg_yes" 3202875e59fSOllivier Robert [ "$ZFSBOOT_SWAP_MIRROR" ] && swapmirror="$msg_yes" 321695a612fSOllivier Robert local disks n disks_grammar 322a88393ceSDevin Teske f_count n $ZFSBOOT_DISKS 323695a612fSOllivier Robert { [ $n -eq 1 ] && disks_grammar=$msg_disk_singular; } || 324695a612fSOllivier Robert disks_grammar=$msg_disk_plural # grammar 325cd88b886SDevin Teske local menu_list=" 326bc4a673fSDevin Teske '>>> $msg_install' '$msg_install_desc' 327bc4a673fSDevin Teske '$msg_install_help' 328*33112d9eSDevin Teske 'T $msg_pool_type_disks' 329*33112d9eSDevin Teske '$ZFSBOOT_VDEV_TYPE: $n $disks_grammar' 330bc4a673fSDevin Teske '$msg_pool_type_disks_help' 331cd88b886SDevin Teske '- $msg_rescan_devices' '*' 332cd88b886SDevin Teske '$msg_rescan_devices_help' 333cd88b886SDevin Teske '- $msg_disk_info' '*' 334cd88b886SDevin Teske '$msg_disk_info_help' 335bc4a673fSDevin Teske 'N $msg_pool_name' '$ZFSBOOT_POOL_NAME' 336cd88b886SDevin Teske '$msg_pool_name_help' 337*33112d9eSDevin Teske '4 $msg_force_4k_sectors' 338*33112d9eSDevin Teske '$force4k' 339cd88b886SDevin Teske '$msg_force_4k_sectors_help' 340bc4a673fSDevin Teske 'E $msg_encrypt_disks' '$usegeli' 341bc4a673fSDevin Teske '$msg_encrypt_disks_help' 342*33112d9eSDevin Teske 'P $msg_partition_scheme' 343*33112d9eSDevin Teske '$ZFSBOOT_PARTITION_SCHEME' 344cd88b886SDevin Teske '$msg_partition_scheme_help' 345bc4a673fSDevin Teske 'S $msg_swap_size' '$ZFSBOOT_SWAP_SIZE' 346cd88b886SDevin Teske '$msg_swap_size_help' 3472875e59fSOllivier Robert 'M $msg_swap_mirror' '$swapmirror' 3482875e59fSOllivier Robert '$msg_swap_mirror_help' 3492875e59fSOllivier Robert 'W $msg_swap_encrypt' '$swapgeli' 3502875e59fSOllivier Robert '$msg_swap_encrypt_help' 351cd88b886SDevin Teske " # END-QUOTE 352cd88b886SDevin Teske local defaultitem= # Calculated below 353cd88b886SDevin Teske local hline="$hline_alnum_arrows_punc_tab_enter" 354cd88b886SDevin Teske 355cd88b886SDevin Teske local height width rows 356cd88b886SDevin Teske eval f_dialog_menu_with_help_size height width rows \ 357cd88b886SDevin Teske \"\$title\" \"\$btitle\" \"\$prompt\" \"\$hline\" $menu_list 358cd88b886SDevin Teske 359cd88b886SDevin Teske # Obtain default-item from previously stored selection 360cd88b886SDevin Teske f_dialog_default_fetch defaultitem 361cd88b886SDevin Teske 362cd88b886SDevin Teske local menu_choice 363cd88b886SDevin Teske menu_choice=$( eval $DIALOG \ 364cd88b886SDevin Teske --title \"\$title\" \ 365cd88b886SDevin Teske --backtitle \"\$btitle\" \ 366cd88b886SDevin Teske --hline \"\$hline\" \ 367cd88b886SDevin Teske --item-help \ 368cd88b886SDevin Teske --ok-label \"\$msg_select\" \ 369cd88b886SDevin Teske --cancel-label \"\$msg_cancel\" \ 370cd88b886SDevin Teske --default-item \"\$defaultitem\" \ 371cd88b886SDevin Teske --menu \"\$prompt\" \ 372cd88b886SDevin Teske $height $width $rows \ 373cd88b886SDevin Teske $menu_list \ 374cd88b886SDevin Teske 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 375cd88b886SDevin Teske ) 376cd88b886SDevin Teske local retval=$? 377cd88b886SDevin Teske f_dialog_data_sanitize menu_choice 378cd88b886SDevin Teske f_dialog_menutag_store "$menu_choice" 379cd88b886SDevin Teske 380cd88b886SDevin Teske # Only update default-item on success 381cd88b886SDevin Teske [ $retval -eq $DIALOG_OK ] && f_dialog_default_store "$menu_choice" 382cd88b886SDevin Teske 383cd88b886SDevin Teske return $retval 384cd88b886SDevin Teske} 385cd88b886SDevin Teske 386bc4a673fSDevin Teske# dialog_last_chance $disks ... 387cd88b886SDevin Teske# 388bc4a673fSDevin Teske# Display a list of the disks that the user is about to destroy. The default 389bc4a673fSDevin Teske# action is to return error status unless the user explicitly (non-default) 390bc4a673fSDevin Teske# selects "Yes" from the noyes dialog. 391cd88b886SDevin Teske# 392bc4a673fSDevin Teskedialog_last_chance() 393cd88b886SDevin Teske{ 394cd88b886SDevin Teske local title="$DIALOG_TITLE" 395cd88b886SDevin Teske local btitle="$DIALOG_BACKTITLE" 396bc4a673fSDevin Teske local prompt # Calculated below 397bc4a673fSDevin Teske local hline="$hline_arrows_tab_enter" 398cd88b886SDevin Teske 399bc4a673fSDevin Teske local height=8 width=50 prefix=" " 400bc4a673fSDevin Teske local plen=${#prefix} list= line= 401bc4a673fSDevin Teske local max_width=$(( $width - 3 - $plen )) 402bc4a673fSDevin Teske 403bc4a673fSDevin Teske local yes no defaultno extra_args format 404bc4a673fSDevin Teske if [ "$USE_XDIALOG" ]; then 405bc4a673fSDevin Teske yes=ok no=cancel defaultno=default-no 406bc4a673fSDevin Teske extra_args="--wrap --left" 407bc4a673fSDevin Teske format="$msg_last_chance_are_you_sure" 408bc4a673fSDevin Teske else 409bc4a673fSDevin Teske yes=yes no=no defaultno=defaultno 410bc4a673fSDevin Teske extra_args="--colors --cr-wrap" 411bc4a673fSDevin Teske format="$msg_last_chance_are_you_sure_color" 412bc4a673fSDevin Teske fi 413bc4a673fSDevin Teske 414bc4a673fSDevin Teske local disk line_width 415bc4a673fSDevin Teske for disk in $*; do 416bc4a673fSDevin Teske if [ "$line" ]; then 417bc4a673fSDevin Teske line_width=${#line} 418bc4a673fSDevin Teske else 419bc4a673fSDevin Teske line_width=$plen 420bc4a673fSDevin Teske fi 421bc4a673fSDevin Teske line_width=$(( $line_width + 1 + ${#disk} )) 422bc4a673fSDevin Teske # Add newline before disk if it would exceed max_width 423bc4a673fSDevin Teske if [ $line_width -gt $max_width ]; then 424bc4a673fSDevin Teske list="$list$line\n" 425bc4a673fSDevin Teske line="$prefix" 426bc4a673fSDevin Teske height=$(( $height + 1 )) 427bc4a673fSDevin Teske fi 428bc4a673fSDevin Teske # Add the disk to the list 429bc4a673fSDevin Teske line="$line $disk" 430bc4a673fSDevin Teske done 431bc4a673fSDevin Teske # Append the left-overs 432bc4a673fSDevin Teske if [ "${line#$prefix}" ]; then 433bc4a673fSDevin Teske list="$list$line" 434bc4a673fSDevin Teske height=$(( $height + 1 )) 435bc4a673fSDevin Teske fi 436bc4a673fSDevin Teske 437bc4a673fSDevin Teske # Add height for Xdialog(1) 438bc4a673fSDevin Teske [ "$USE_XDIALOG" ] && height=$(( $height + $height / 5 + 3 )) 439bc4a673fSDevin Teske 440bc4a673fSDevin Teske prompt=$( printf "$format" "$list" ) 441bc4a673fSDevin Teske f_dprintf "%s: Last Chance!" "$0" 442bc4a673fSDevin Teske $DIALOG \ 443bc4a673fSDevin Teske --title "$title" \ 444bc4a673fSDevin Teske --backtitle "$btitle" \ 445bc4a673fSDevin Teske --hline "$hline" \ 446bc4a673fSDevin Teske --$defaultno \ 447bc4a673fSDevin Teske --$yes-label "$msg_yes" \ 448bc4a673fSDevin Teske --$no-label "$msg_no" \ 449bc4a673fSDevin Teske $extra_args \ 450bc4a673fSDevin Teske --yesno "$prompt" $height $width 451bc4a673fSDevin Teske} 452bc4a673fSDevin Teske 453bc4a673fSDevin Teske# dialog_menu_layout 454cd88b886SDevin Teske# 455bc4a673fSDevin Teske# Configure Virtual Device type and disks to use for the ZFS boot pool. User 456bc4a673fSDevin Teske# must select enough disks to satisfy the chosen vdev type. 457cd88b886SDevin Teske# 458bc4a673fSDevin Teskedialog_menu_layout() 459bc4a673fSDevin Teske{ 460bc4a673fSDevin Teske local funcname=dialog_menu_layout 461bc4a673fSDevin Teske local title="$DIALOG_TITLE" 462bc4a673fSDevin Teske local btitle="$DIALOG_BACKTITLE" 463bc4a673fSDevin Teske local vdev_prompt="$msg_select_virtual_device_type" 464bc4a673fSDevin Teske local disk_prompt="$msg_please_select_one_or_more_disks" 465bc4a673fSDevin Teske local vdev_menu_list=" 466bc4a673fSDevin Teske 'stripe' '$msg_stripe_desc' '$msg_stripe_help' 467bc4a673fSDevin Teske 'mirror' '$msg_mirror_desc' '$msg_mirror_help' 468bc4a673fSDevin Teske 'raidz1' '$msg_raidz1_desc' '$msg_raidz1_help' 469bc4a673fSDevin Teske 'raidz2' '$msg_raidz2_desc' '$msg_raidz2_help' 470bc4a673fSDevin Teske 'raidz3' '$msg_raidz3_desc' '$msg_raidz3_help' 471bc4a673fSDevin Teske " # END-QUOTE 472bc4a673fSDevin Teske local disk_check_list= # Calculated below 473bc4a673fSDevin Teske local vdev_hline="$hline_arrows_tab_enter" 474bc4a673fSDevin Teske local disk_hline="$hline_arrows_space_tab_enter" 475bc4a673fSDevin Teske 476bc4a673fSDevin Teske # Warn the user if vdev type is not valid 477bc4a673fSDevin Teske case "$ZFSBOOT_VDEV_TYPE" in 478bc4a673fSDevin Teske stripe|mirror|raidz1|raidz2|raidz3) : known good ;; 479bc4a673fSDevin Teske *) 480bc4a673fSDevin Teske f_dprintf "%s: Invalid virtual device type \`%s'" \ 481bc4a673fSDevin Teske $funcname "$ZFSBOOT_VDEV_TYPE" 482bc4a673fSDevin Teske f_show_err "$msg_invalid_virtual_device_type" \ 483bc4a673fSDevin Teske "$ZFSBOOT_VDEV_TYPE" 484bc4a673fSDevin Teske f_interactive || return $FAILURE 485bc4a673fSDevin Teske esac 486bc4a673fSDevin Teske 487bc4a673fSDevin Teske # Calculate size of vdev menu once only 488bc4a673fSDevin Teske local vheight vwidth vrows 489bc4a673fSDevin Teske eval f_dialog_menu_with_help_size vheight vwidth vrows \ 490bc4a673fSDevin Teske \"\$title\" \"\$btitle\" \"\$vdev_prompt\" \"\$vdev_hline\" \ 491bc4a673fSDevin Teske $vdev_menu_list 492bc4a673fSDevin Teske 493bc4a673fSDevin Teske # Get a list of probed disk devices 494bc4a673fSDevin Teske local disks= 495a88393ceSDevin Teske debug= f_device_find "" $DEVICE_TYPE_DISK disks 496a88393ceSDevin Teske 497a88393ceSDevin Teske # Prune out mounted md(4) devices that may be part of the boot process 498a88393ceSDevin Teske local disk name new_list= 499a88393ceSDevin Teske for disk in $disks; do 500a88393ceSDevin Teske debug= $disk get name name 501a88393ceSDevin Teske case "$name" in 502a88393ceSDevin Teske md[0-9]*) f_mounted -b "/dev/$name" && continue ;; 503a88393ceSDevin Teske esac 504a88393ceSDevin Teske new_list="$new_list $disk" 505a88393ceSDevin Teske done 506a88393ceSDevin Teske disks="${new_list# }" 507a88393ceSDevin Teske 508a88393ceSDevin Teske # Debugging 509a88393ceSDevin Teske if [ "$debug" ]; then 510a88393ceSDevin Teske local disk_names= 511a88393ceSDevin Teske for disk in $disks; do 512a88393ceSDevin Teske debug= $disk get name name 513a88393ceSDevin Teske disk_names="$disk_names $name" 514a88393ceSDevin Teske done 515a88393ceSDevin Teske f_dprintf "$funcname: disks=[%s]" "${disk_names# }" 516a88393ceSDevin Teske fi 517a88393ceSDevin Teske 518cd88b886SDevin Teske if [ ! "$disks" ]; then 519bc4a673fSDevin Teske f_dprintf "No disk(s) present to configure" 520bc4a673fSDevin Teske f_show_err "$msg_no_disks_present_to_configure" 521cd88b886SDevin Teske return $FAILURE 522cd88b886SDevin Teske fi 523cd88b886SDevin Teske 524cd88b886SDevin Teske # Lets sort the disks array to be more user friendly 525a88393ceSDevin Teske f_device_sort_by name disks disks 526cd88b886SDevin Teske 527cd88b886SDevin Teske # 528bc4a673fSDevin Teske # Operate in a loop so we can (if interactive) repeat if not enough 529bc4a673fSDevin Teske # disks are selected to satisfy the chosen vdev type or user wants to 530bc4a673fSDevin Teske # back-up to the previous menu. 531cd88b886SDevin Teske # 532a88393ceSDevin Teske local vardisk ndisks onoff selections vdev_choice breakout device 533a88393ceSDevin Teske local valid_disks all_valid want_disks desc height width rows 534bc4a673fSDevin Teske while :; do 535cd88b886SDevin Teske # 536bc4a673fSDevin Teske # Confirm the vdev type that was selected 537cd88b886SDevin Teske # 538bc4a673fSDevin Teske if f_interactive && [ "$ZFSBOOT_CONFIRM_LAYOUT" ]; then 539bc4a673fSDevin Teske vdev_choice=$( eval $DIALOG \ 540cd88b886SDevin Teske --title \"\$title\" \ 541cd88b886SDevin Teske --backtitle \"\$btitle\" \ 542bc4a673fSDevin Teske --hline \"\$vdev_hline\" \ 543cd88b886SDevin Teske --ok-label \"\$msg_ok\" \ 544cd88b886SDevin Teske --cancel-label \"\$msg_cancel\" \ 545cd88b886SDevin Teske --item-help \ 546bc4a673fSDevin Teske --default-item \"\$ZFSBOOT_VDEV_TYPE\" \ 547bc4a673fSDevin Teske --menu \"\$vdev_prompt\" \ 548bc4a673fSDevin Teske $vheight $vwidth $vrows \ 549bc4a673fSDevin Teske $vdev_menu_list \ 550cd88b886SDevin Teske 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 551bc4a673fSDevin Teske ) || return $? 552bc4a673fSDevin Teske # Exit if user pressed ESC or chose Cancel/No 553bc4a673fSDevin Teske f_dialog_data_sanitize vdev_choice 554cd88b886SDevin Teske 555bc4a673fSDevin Teske ZFSBOOT_VDEV_TYPE="$vdev_choice" 556bc4a673fSDevin Teske f_dprintf "$funcname: ZFSBOOT_VDEV_TYPE=[%s]" \ 557bc4a673fSDevin Teske "$ZFSBOOT_VDEV_TYPE" 558bc4a673fSDevin Teske fi 559bc4a673fSDevin Teske 560bc4a673fSDevin Teske # Determine the number of disks needed for this vdev type 561a88393ceSDevin Teske want_disks=0 562bc4a673fSDevin Teske case "$ZFSBOOT_VDEV_TYPE" in 563cd88b886SDevin Teske stripe) want_disks=1 ;; 564cd88b886SDevin Teske mirror) want_disks=2 ;; 565cd88b886SDevin Teske raidz1) want_disks=3 ;; 566cd88b886SDevin Teske raidz2) want_disks=4 ;; 567cd88b886SDevin Teske raidz3) want_disks=5 ;; 568cd88b886SDevin Teske esac 569bc4a673fSDevin Teske 570a88393ceSDevin Teske # 571bc4a673fSDevin Teske # Warn the user if any scripted disks are invalid 572a88393ceSDevin Teske # 573a88393ceSDevin Teske valid_disks= all_valid=${ZFSBOOT_DISKS:+1} # optimism 574bc4a673fSDevin Teske for disk in $ZFSBOOT_DISKS; do 575a88393ceSDevin Teske if debug= f_device_find -1 \ 576a88393ceSDevin Teske $disk $DEVICE_TYPE_DISK device 577a88393ceSDevin Teske then 578bc4a673fSDevin Teske valid_disks="$valid_disks $disk" 579bc4a673fSDevin Teske continue 580cd88b886SDevin Teske fi 581bc4a673fSDevin Teske f_dprintf "$funcname: \`%s' is not a real disk" "$disk" 582bc4a673fSDevin Teske all_valid= 583bc4a673fSDevin Teske done 584bc4a673fSDevin Teske if [ ! "$all_valid" ]; then 585bc4a673fSDevin Teske if [ "$ZFSBOOT_DISKS" ]; then 586bc4a673fSDevin Teske f_show_err \ 587bc4a673fSDevin Teske "$msg_missing_one_or_more_scripted_disks" 588bc4a673fSDevin Teske else 589bc4a673fSDevin Teske f_dprintf "No disks selected." 590bc4a673fSDevin Teske f_interactive || 591bc4a673fSDevin Teske f_show_err "$msg_no_disks_selected" 592bc4a673fSDevin Teske fi 593bc4a673fSDevin Teske f_interactive || return $FAILURE 594bc4a673fSDevin Teske fi 595bc4a673fSDevin Teske ZFSBOOT_DISKS="${valid_disks# }" 596bc4a673fSDevin Teske 597bc4a673fSDevin Teske # 598bc4a673fSDevin Teske # Short-circuit if we're running non-interactively 599bc4a673fSDevin Teske # 600bc4a673fSDevin Teske if ! f_interactive || [ ! "$ZFSBOOT_CONFIRM_LAYOUT" ]; then 601a88393ceSDevin Teske f_count ndisks $ZFSBOOT_DISKS 602bc4a673fSDevin Teske [ $ndisks -ge $want_disks ] && break # to success 603bc4a673fSDevin Teske 604bc4a673fSDevin Teske # Not enough disks selected 605bc4a673fSDevin Teske f_dprintf "$funcname: %s: %s (%u < %u minimum)" \ 606bc4a673fSDevin Teske "$ZFSBOOT_VDEV_TYPE" \ 607bc4a673fSDevin Teske "Not enough disks selected." \ 608bc4a673fSDevin Teske $ndisks $want_disks 609bc4a673fSDevin Teske f_interactive || return $FAILURE 610bc4a673fSDevin Teske msg_yes="$msg_change_selection" msg_no="$msg_cancel" \ 611bc4a673fSDevin Teske f_yesno "%s: $msg_not_enough_disks_selected" \ 612bc4a673fSDevin Teske "$ZFSBOOT_VDEV_TYPE" $ndisks $want_disks || 613bc4a673fSDevin Teske return $FAILURE 614bc4a673fSDevin Teske fi 615bc4a673fSDevin Teske 616bc4a673fSDevin Teske # 617bc4a673fSDevin Teske # Confirm the disks that were selected 618bc4a673fSDevin Teske # Loop until the user cancels or selects enough disks 619bc4a673fSDevin Teske # 620a88393ceSDevin Teske breakout= 621bc4a673fSDevin Teske while :; do 622bc4a673fSDevin Teske # Loop over list of available disks, resetting state 623a88393ceSDevin Teske for disk in $disks; do 624a88393ceSDevin Teske f_isset _${disk}_status && _${disk}_status= 625a88393ceSDevin Teske done 626bc4a673fSDevin Teske 627bc4a673fSDevin Teske # Loop over list of selected disks and create temporary 628bc4a673fSDevin Teske # locals to map statuses onto up-to-date list of disks 629bc4a673fSDevin Teske for disk in $ZFSBOOT_DISKS; do 630a88393ceSDevin Teske debug= f_device_find -1 \ 631a88393ceSDevin Teske $disk $DEVICE_TYPE_DISK disk 632a88393ceSDevin Teske f_isset _${disk}_status || 633a88393ceSDevin Teske local _${disk}_status 634a88393ceSDevin Teske _${disk}_status=on 635bc4a673fSDevin Teske done 636bc4a673fSDevin Teske 637bc4a673fSDevin Teske # Create the checklist menu of discovered disk devices 638bc4a673fSDevin Teske disk_check_list= 639bc4a673fSDevin Teske for disk in $disks; do 640a88393ceSDevin Teske desc= 641a88393ceSDevin Teske $disk get name name 642a88393ceSDevin Teske $disk get desc desc 643bc4a673fSDevin Teske f_shell_escape "$desc" desc 644bc4a673fSDevin Teske f_getvar _${disk}_status:-off onoff 645bc4a673fSDevin Teske disk_check_list="$disk_check_list 646a88393ceSDevin Teske $name '$desc' $onoff" 647bc4a673fSDevin Teske done 648bc4a673fSDevin Teske 649bc4a673fSDevin Teske eval f_dialog_checklist_size height width rows \ 650bc4a673fSDevin Teske \"\$title\" \"\$btitle\" \"\$prompt\" \ 651bc4a673fSDevin Teske \"\$hline\" $disk_check_list 652bc4a673fSDevin Teske 653bc4a673fSDevin Teske selections=$( eval $DIALOG \ 654bc4a673fSDevin Teske --title \"\$DIALOG_TITLE\" \ 655bc4a673fSDevin Teske --backtitle \"\$DIALOG_BACKTITLE\" \ 656751952aeSDevin Teske --separate-output \ 657bc4a673fSDevin Teske --hline \"\$hline\" \ 658bc4a673fSDevin Teske --ok-label \"\$msg_ok\" \ 659bc4a673fSDevin Teske --cancel-label \"\$msg_back\" \ 660bc4a673fSDevin Teske --checklist \"\$prompt\" \ 661bc4a673fSDevin Teske $height $width $rows \ 662bc4a673fSDevin Teske $disk_check_list \ 663bc4a673fSDevin Teske 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 664bc4a673fSDevin Teske ) || break 665bc4a673fSDevin Teske # Loop if user pressed ESC or chose Cancel/No 666bc4a673fSDevin Teske f_dialog_data_sanitize selections 667bc4a673fSDevin Teske 668bc4a673fSDevin Teske ZFSBOOT_DISKS="$selections" 669bc4a673fSDevin Teske f_dprintf "$funcname: ZFSBOOT_DISKS=[%s]" \ 670bc4a673fSDevin Teske "$ZFSBOOT_DISKS" 671bc4a673fSDevin Teske 672a88393ceSDevin Teske f_count ndisks $ZFSBOOT_DISKS 673bc4a673fSDevin Teske [ $ndisks -ge $want_disks ] && 674bc4a673fSDevin Teske breakout=break && break 675bc4a673fSDevin Teske 676bc4a673fSDevin Teske # Not enough disks selected 677bc4a673fSDevin Teske f_dprintf "$funcname: %s: %s (%u < %u minimum)" \ 678bc4a673fSDevin Teske "$ZFSBOOT_VDEV_TYPE" \ 679bc4a673fSDevin Teske "Not enough disks selected." \ 680bc4a673fSDevin Teske $ndisks $want_disks 681bc4a673fSDevin Teske msg_yes="$msg_change_selection" msg_no="$msg_cancel" \ 682bc4a673fSDevin Teske f_yesno "%s: $msg_not_enough_disks_selected" \ 683bc4a673fSDevin Teske "$ZFSBOOT_VDEV_TYPE" $ndisks $want_disks || 684bc4a673fSDevin Teske break 685bc4a673fSDevin Teske done 686bc4a673fSDevin Teske [ "$breakout" = "break" ] && break 687bc4a673fSDevin Teske [ "$ZFSBOOT_CONFIRM_LAYOUT" ] || return $FAILURE 688bc4a673fSDevin Teske done 689bc4a673fSDevin Teske 690bc4a673fSDevin Teske return $DIALOG_OK 691cd88b886SDevin Teske} 692cd88b886SDevin Teske 69312307018SAllan Jude# dialog_uefi_prompt 69412307018SAllan Jude# 69512307018SAllan Jude# Confirm that the user wants to continue with the installation on a BIOS 69612307018SAllan Jude# system when they have booted with UEFI 69712307018SAllan Jude# 69812307018SAllan Judedialog_uefi_prompt() 69912307018SAllan Jude{ 70012307018SAllan Jude local title="$DIALOG_TITLE" 70112307018SAllan Jude local btitle="$DIALOG_BACKTITLE" 70212307018SAllan Jude local prompt # Calculated below 70312307018SAllan Jude local hline="$hline_arrows_tab_enter" 70412307018SAllan Jude 70512307018SAllan Jude local height=8 width=50 prefix=" " 70612307018SAllan Jude local plen=${#prefix} list= line= 70712307018SAllan Jude local max_width=$(( $width - 3 - $plen )) 70812307018SAllan Jude 70912307018SAllan Jude local yes no defaultno extra_args format 71012307018SAllan Jude if [ "$USE_XDIALOG" ]; then 71112307018SAllan Jude yes=ok no=cancel defaultno=default-no 71212307018SAllan Jude extra_args="--wrap --left" 71312307018SAllan Jude format="$msg_uefi_not_supported" 71412307018SAllan Jude else 71512307018SAllan Jude yes=yes no=no defaultno=defaultno 71612307018SAllan Jude extra_args="--cr-wrap" 71712307018SAllan Jude format="$msg_uefi_not_supported" 71812307018SAllan Jude fi 71912307018SAllan Jude 72012307018SAllan Jude # Add height for Xdialog(1) 72112307018SAllan Jude [ "$USE_XDIALOG" ] && height=$(( $height + $height / 5 + 3 )) 72212307018SAllan Jude 72312307018SAllan Jude prompt=$( printf "$format" ) 72412307018SAllan Jude f_dprintf "%s: UEFI prompt" "$0" 72512307018SAllan Jude $DIALOG \ 72612307018SAllan Jude --title "$title" \ 72712307018SAllan Jude --backtitle "$btitle" \ 72812307018SAllan Jude --hline "$hline" \ 72912307018SAllan Jude --$yes-label "$msg_yes" \ 73012307018SAllan Jude --$no-label "$msg_no" \ 73112307018SAllan Jude $extra_args \ 73212307018SAllan Jude --yesno "$prompt" $height $width 73312307018SAllan Jude} 73412307018SAllan Jude 735cd88b886SDevin Teske# zfs_create_diskpart $disk $index 736cd88b886SDevin Teske# 737cd88b886SDevin Teske# For each block device to be used in the zpool, rather than just create the 738cd88b886SDevin Teske# zpool with the raw block devices (e.g., da0, da1, etc.) we create partitions 739cd88b886SDevin Teske# so we can have some real swap. This also provides wiggle room incase your 740cd88b886SDevin Teske# replacement drivers do not have the exact same sector counts. 741cd88b886SDevin Teske# 7427cae6aabSDevin Teske# NOTE: $swapsize and $bootsize should be defined by the calling function. 743a622223fSDevin Teske# NOTE: Sets $bootpart and $targetpart for the calling function. 744cd88b886SDevin Teske# 745cd88b886SDevin Teskezfs_create_diskpart() 746cd88b886SDevin Teske{ 747cd88b886SDevin Teske local funcname=zfs_create_diskpart 748bc4a673fSDevin Teske local disk="$1" index="$2" 749cd88b886SDevin Teske 750cd88b886SDevin Teske # Check arguments 751bc4a673fSDevin Teske if [ ! "$disk" ]; then 752bc4a673fSDevin Teske f_dprintf "$funcname: NULL disk argument" 753bc4a673fSDevin Teske msg_error="$msg_error: $funcname" \ 754bc4a673fSDevin Teske f_show_err "$msg_null_disk_argument" 755bc4a673fSDevin Teske return $FAILURE 756bc4a673fSDevin Teske fi 757bc4a673fSDevin Teske if [ "${disk#*[$IFS]}" != "$disk" ]; then 758bc4a673fSDevin Teske f_dprintf "$funcname: Invalid disk argument \`%s'" "$disk" 759bc4a673fSDevin Teske msg_error="$msg_error: $funcname" \ 760bc4a673fSDevin Teske f_show_err "$msg_invalid_disk_argument" "$disk" 761bc4a673fSDevin Teske return $FAILURE 762bc4a673fSDevin Teske fi 763bc4a673fSDevin Teske if [ ! "$index" ]; then 764bc4a673fSDevin Teske f_dprintf "$funcname: NULL index argument" 765bc4a673fSDevin Teske msg_error="$msg_error: $funcname" \ 766bc4a673fSDevin Teske f_show_err "$msg_null_index_argument" 767bc4a673fSDevin Teske return $FAILURE 768bc4a673fSDevin Teske fi 769bc4a673fSDevin Teske if ! f_isinteger "$index"; then 770bc4a673fSDevin Teske f_dprintf "$funcname: Invalid index argument \`%s'" "$index" 771bc4a673fSDevin Teske msg_error="$msg_error: $funcname" \ 772bc4a673fSDevin Teske f_show_err "$msg_invalid_index_argument" "$index" 773bc4a673fSDevin Teske return $FAILURE 774bc4a673fSDevin Teske fi 775bc4a673fSDevin Teske f_dprintf "$funcname: disk=[%s] index=[%s]" "$disk" "$index" 776cd88b886SDevin Teske 777d4d729e4SDevin Teske # Check for unknown partition scheme before proceeding further 778d4d729e4SDevin Teske case "$ZFSBOOT_PARTITION_SCHEME" in 779d4d729e4SDevin Teske ""|MBR|GPT) : known good ;; 780d4d729e4SDevin Teske *) 781d4d729e4SDevin Teske f_dprintf "$funcname: %s is an unsupported partition scheme" \ 782d4d729e4SDevin Teske "$ZFSBOOT_PARTITION_SCHEME" 783d4d729e4SDevin Teske msg_error="$msg_error: $funcname" f_show_err \ 784d4d729e4SDevin Teske "$msg_unsupported_partition_scheme" \ 785d4d729e4SDevin Teske "$ZFSBOOT_PARTITION_SCHEME" 786d4d729e4SDevin Teske return $FAILURE 787d4d729e4SDevin Teske esac 788d4d729e4SDevin Teske 789cd88b886SDevin Teske # 790cd88b886SDevin Teske # Destroy whatever partition layout is currently on disk. 791cd88b886SDevin Teske # NOTE: `-F' required to destroy if partitions still exist. 792cd88b886SDevin Teske # NOTE: Failure is ok here, blank disk will have nothing to destroy. 793cd88b886SDevin Teske # 794bc4a673fSDevin Teske f_dprintf "$funcname: Destroying all data/layouts on \`%s'..." "$disk" 795a622223fSDevin Teske f_eval_catch -d $funcname gpart "$GPART_DESTROY_F" $disk 796a622223fSDevin Teske f_eval_catch -d $funcname graid "$GRAID_DELETE" $disk 797a622223fSDevin Teske f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" /dev/$disk 798cd88b886SDevin Teske 799cd88b886SDevin Teske # Make doubly-sure backup GPT is destroyed 800a622223fSDevin Teske f_eval_catch -d $funcname gpart "$GPART_CREATE" gpt $disk 801a622223fSDevin Teske f_eval_catch -d $funcname gpart "$GPART_DESTROY_F" $disk 802cd88b886SDevin Teske 8037cae6aabSDevin Teske # 8047cae6aabSDevin Teske # Enable boot pool if encryption is desired 8057cae6aabSDevin Teske # 8067cae6aabSDevin Teske [ "$ZFSBOOT_GELI_ENCRYPTION" ] && ZFSBOOT_BOOT_POOL=1 807cd88b886SDevin Teske 808cd88b886SDevin Teske # 809cd88b886SDevin Teske # Lay down the desired type of partition scheme 810cd88b886SDevin Teske # 811cd88b886SDevin Teske local setsize mbrindex 812cd88b886SDevin Teske case "$ZFSBOOT_PARTITION_SCHEME" in 813bc4a673fSDevin Teske ""|GPT) f_dprintf "$funcname: Creating GPT layout..." 814cd88b886SDevin Teske # 815cd88b886SDevin Teske # 1. Create GPT layout using labels 816cd88b886SDevin Teske # 817a622223fSDevin Teske f_eval_catch $funcname gpart "$GPART_CREATE" gpt $disk || 818bc4a673fSDevin Teske return $FAILURE 819cd88b886SDevin Teske 820cd88b886SDevin Teske # 821cd88b886SDevin Teske # 2. Add small freebsd-boot partition labeled `boot#' 822cd88b886SDevin Teske # 823bc4a673fSDevin Teske f_eval_catch $funcname gpart "$GPART_ADD_LABEL_WITH_SIZE" \ 824a622223fSDevin Teske gptboot$index freebsd-boot 512k $disk || 825cd88b886SDevin Teske return $FAILURE 826bc4a673fSDevin Teske f_eval_catch $funcname gpart "$GPART_BOOTCODE_PART" \ 827a622223fSDevin Teske /boot/pmbr /boot/gptzfsboot 1 $disk || 828cd88b886SDevin Teske return $FAILURE 829cd88b886SDevin Teske 830a622223fSDevin Teske # NB: zpool will use the `zfs#' GPT labels 8312875e59fSOllivier Robert bootpart=p2 swappart=p2 targetpart=p2 8327cae6aabSDevin Teske [ ${swapsize:-0} -gt 0 ] && targetpart=p3 833cd88b886SDevin Teske 8347cae6aabSDevin Teske # 8357cae6aabSDevin Teske # Prepare boot pool if enabled (e.g., for geli(8)) 8367cae6aabSDevin Teske # 8377cae6aabSDevin Teske if [ "$ZFSBOOT_BOOT_POOL" ]; then 8382875e59fSOllivier Robert bootpart=p2 swappart=p3 targetpart=p3 8397cae6aabSDevin Teske [ ${swapsize:-0} -gt 0 ] && targetpart=p4 840bc4a673fSDevin Teske f_eval_catch $funcname gpart \ 841a622223fSDevin Teske "$GPART_ADD_LABEL_WITH_SIZE" boot$index \ 8427cae6aabSDevin Teske freebsd-zfs ${bootsize}b $disk || 843bc4a673fSDevin Teske return $FAILURE 8447cae6aabSDevin Teske # Pedantically nuke any old labels 845a622223fSDevin Teske f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 846a622223fSDevin Teske /dev/$disk$bootpart 8477cae6aabSDevin Teske if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then 8487cae6aabSDevin Teske # Pedantically detach targetpart for later 8497cae6aabSDevin Teske f_eval_catch -d $funcname geli \ 8507cae6aabSDevin Teske "$GELI_DETACH_F" \ 851a622223fSDevin Teske /dev/$disk$targetpart 852cd88b886SDevin Teske fi 8537cae6aabSDevin Teske fi 854cd88b886SDevin Teske 855cd88b886SDevin Teske # 8567cae6aabSDevin Teske # 3. Add freebsd-swap partition labeled `swap#' 857cd88b886SDevin Teske # 858bc4a673fSDevin Teske if [ ${swapsize:-0} -gt 0 ]; then 859bc4a673fSDevin Teske f_eval_catch $funcname gpart \ 8607cae6aabSDevin Teske "$GPART_ADD_LABEL_WITH_SIZE" swap$index \ 8617cae6aabSDevin Teske freebsd-swap ${swapsize}b $disk || 862cd88b886SDevin Teske return $FAILURE 863cf9c3e56SDevin Teske # Pedantically nuke any old labels on the swap 864cf9c3e56SDevin Teske f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 8652875e59fSOllivier Robert /dev/$disk$swappart 866cd88b886SDevin Teske fi 8677cae6aabSDevin Teske 8687cae6aabSDevin Teske # 8697cae6aabSDevin Teske # 4. Add freebsd-zfs partition labeled `zfs#' for zroot 8707cae6aabSDevin Teske # 8717cae6aabSDevin Teske f_eval_catch $funcname gpart "$GPART_ADD_LABEL" \ 8727cae6aabSDevin Teske zfs$index freebsd-zfs $disk || return $FAILURE 8737cae6aabSDevin Teske f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 8747cae6aabSDevin Teske /dev/$disk$targetpart 875cd88b886SDevin Teske ;; 876cd88b886SDevin Teske 877bc4a673fSDevin Teske MBR) f_dprintf "$funcname: Creating MBR layout..." 878cd88b886SDevin Teske # 879cd88b886SDevin Teske # 1. Create MBR layout (no labels) 880cd88b886SDevin Teske # 881a622223fSDevin Teske f_eval_catch $funcname gpart "$GPART_CREATE" mbr $disk || 882bc4a673fSDevin Teske return $FAILURE 8832925848dSDevin Teske f_eval_catch $funcname gpart "$GPART_BOOTCODE" /boot/mbr \ 884a622223fSDevin Teske $disk || return $FAILURE 885cd88b886SDevin Teske 886cd88b886SDevin Teske # 887cd88b886SDevin Teske # 2. Add freebsd slice with all available space 888cd88b886SDevin Teske # 889a622223fSDevin Teske f_eval_catch $funcname gpart "$GPART_ADD" freebsd $disk || 890bc4a673fSDevin Teske return $FAILURE 891a622223fSDevin Teske f_eval_catch $funcname gpart "$GPART_SET_ACTIVE" 1 $disk || 892bc4a673fSDevin Teske return $FAILURE 893a622223fSDevin Teske # Pedantically nuke any old labels 894a622223fSDevin Teske f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 895a622223fSDevin Teske /dev/${disk}s1 896a622223fSDevin Teske # Pedantically nuke any old scheme 897a622223fSDevin Teske f_eval_catch -d $funcname gpart "$GPART_DESTROY_F" ${disk}s1 898cd88b886SDevin Teske 899cd88b886SDevin Teske # 900bc4a673fSDevin Teske # 3. Write BSD scheme to the freebsd slice 901cd88b886SDevin Teske # 902a622223fSDevin Teske f_eval_catch $funcname gpart "$GPART_CREATE" BSD ${disk}s1 || 903bc4a673fSDevin Teske return $FAILURE 904cd88b886SDevin Teske 9057cae6aabSDevin Teske # NB: zpool will use s1a (no labels) 9062875e59fSOllivier Robert bootpart=s1a swappart=s1b targetpart=s1d mbrindex=4 907cd88b886SDevin Teske 9087cae6aabSDevin Teske # 9097cae6aabSDevin Teske # Always prepare a boot pool on MBR 9107cae6aabSDevin Teske # 9117cae6aabSDevin Teske ZFSBOOT_BOOT_POOL=1 912bc4a673fSDevin Teske f_eval_catch $funcname gpart \ 913bc4a673fSDevin Teske "$GPART_ADD_INDEX_WITH_SIZE" \ 9147cae6aabSDevin Teske 1 freebsd-zfs ${bootsize}b ${disk}s1 || 915bc4a673fSDevin Teske return $FAILURE 916a622223fSDevin Teske # Pedantically nuke any old labels 917a622223fSDevin Teske f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 918a622223fSDevin Teske /dev/$disk$bootpart 9197cae6aabSDevin Teske if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then 920a622223fSDevin Teske # Pedantically detach targetpart for later 921a622223fSDevin Teske f_eval_catch -d $funcname geli \ 922a622223fSDevin Teske "$GELI_DETACH_F" \ 923a622223fSDevin Teske /dev/$disk$targetpart 924cd88b886SDevin Teske fi 925cd88b886SDevin Teske 926cd88b886SDevin Teske # 9277cae6aabSDevin Teske # 4. Add freebsd-swap partition 928cd88b886SDevin Teske # 929bc4a673fSDevin Teske if [ ${swapsize:-0} -gt 0 ]; then 930bc4a673fSDevin Teske f_eval_catch $funcname gpart \ 9317cae6aabSDevin Teske "$GPART_ADD_INDEX_WITH_SIZE" 2 \ 9327cae6aabSDevin Teske freebsd-swap ${swapsize}b ${disk}s1 || 933cd88b886SDevin Teske return $FAILURE 934cf9c3e56SDevin Teske # Pedantically nuke any old labels on the swap 935cf9c3e56SDevin Teske f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 936cf9c3e56SDevin Teske /dev/${disk}s1b 937cd88b886SDevin Teske fi 9387cae6aabSDevin Teske 9397cae6aabSDevin Teske # 9407cae6aabSDevin Teske # 5. Add freebsd-zfs partition for zroot 9417cae6aabSDevin Teske # 9427cae6aabSDevin Teske f_eval_catch $funcname gpart "$GPART_ADD_INDEX" \ 9437cae6aabSDevin Teske $mbrindex freebsd-zfs ${disk}s1 || return $FAILURE 9447cae6aabSDevin Teske f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 9457cae6aabSDevin Teske /dev/$disk$targetpart # Pedantic 9467cae6aabSDevin Teske f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \ 9477cae6aabSDevin Teske /boot/zfsboot /dev/${disk}s1 count=1 || 9487cae6aabSDevin Teske return $FAILURE 949cd88b886SDevin Teske ;; 950cd88b886SDevin Teske 951cd88b886SDevin Teske esac # $ZFSBOOT_PARTITION_SCHEME 952cd88b886SDevin Teske 9532875e59fSOllivier Robert # Update fstab(5) 9542875e59fSOllivier Robert if [ "$isswapmirror" ]; then 9552875e59fSOllivier Robert # This is not the first disk in the mirror, do nothing 9562875e59fSOllivier Robert elif [ "$ZFSBOOT_SWAP_ENCRYPTION" -a "$ZFSBOOT_SWAP_MIRROR" ]; then 9572875e59fSOllivier Robert f_eval_catch $funcname printf "$PRINTF_FSTAB" \ 9582875e59fSOllivier Robert /dev/mirror/swap.eli none swap sw 0 0 \ 9592875e59fSOllivier Robert $BSDINSTALL_TMPETC/fstab || 9602875e59fSOllivier Robert return $FAILURE 9612875e59fSOllivier Robert isswapmirror=1 9622875e59fSOllivier Robert elif [ "$ZFSBOOT_SWAP_MIRROR" ]; then 9632875e59fSOllivier Robert f_eval_catch $funcname printf "$PRINTF_FSTAB" \ 9642875e59fSOllivier Robert /dev/mirror/swap none swap sw 0 0 \ 9652875e59fSOllivier Robert $BSDINSTALL_TMPETC/fstab || 9662875e59fSOllivier Robert return $FAILURE 9672875e59fSOllivier Robert isswapmirror=1 9682875e59fSOllivier Robert elif [ "$ZFSBOOT_SWAP_ENCRYPTION" ]; then 9692875e59fSOllivier Robert f_eval_catch $funcname printf "$PRINTF_FSTAB" \ 9702875e59fSOllivier Robert /dev/$disk${swappart}.eli none swap sw 0 0 \ 9712875e59fSOllivier Robert $BSDINSTALL_TMPETC/fstab || 9722875e59fSOllivier Robert return $FAILURE 9732875e59fSOllivier Robert else 9742875e59fSOllivier Robert f_eval_catch $funcname printf "$PRINTF_FSTAB" \ 9752875e59fSOllivier Robert /dev/$disk$swappart none swap sw 0 0 \ 9762875e59fSOllivier Robert $BSDINSTALL_TMPETC/fstab || 9772875e59fSOllivier Robert return $FAILURE 9782875e59fSOllivier Robert fi 9792875e59fSOllivier Robert 980cd88b886SDevin Teske return $SUCCESS 981cd88b886SDevin Teske} 982cd88b886SDevin Teske 983bc4a673fSDevin Teske# zfs_create_boot $poolname $vdev_type $disks ... 984cd88b886SDevin Teske# 985cd88b886SDevin Teske# Creates boot pool and dataset layout. Returns error if something goes wrong. 986cd88b886SDevin Teske# Errors are printed to stderr for collection and display. 987cd88b886SDevin Teske# 988cd88b886SDevin Teskezfs_create_boot() 989cd88b886SDevin Teske{ 990cd88b886SDevin Teske local funcname=zfs_create_boot 9917cae6aabSDevin Teske local zroot_name="$1" 9927cae6aabSDevin Teske local zroot_vdevtype="$2" 9937cae6aabSDevin Teske local zroot_vdevs= # Calculated below 9942875e59fSOllivier Robert local swap_devs= # Calculated below 9957cae6aabSDevin Teske local boot_vdevs= # Used for geli(8) and/or MBR layouts 996a622223fSDevin Teske shift 2 # poolname vdev_type 997a622223fSDevin Teske local disks="$*" disk 9982875e59fSOllivier Robert local isswapmirror 9992875e59fSOllivier Robert local bootpart targetpart swappart # Set by zfs_create_diskpart() below 100047206692SDevin Teske local create_options 1001cd88b886SDevin Teske 1002a622223fSDevin Teske # 1003cd88b886SDevin Teske # Pedantic checks; should never be seen 1004a622223fSDevin Teske # 10057cae6aabSDevin Teske if [ ! "$zroot_name" ]; then 1006bc4a673fSDevin Teske f_dprintf "$funcname: NULL poolname" 1007bc4a673fSDevin Teske msg_error="$msg_error: $funcname" \ 1008bc4a673fSDevin Teske f_show_err "$msg_null_poolname" 1009cd88b886SDevin Teske return $FAILURE 1010cd88b886SDevin Teske fi 1011cd88b886SDevin Teske if [ $# -lt 1 ]; then 1012bc4a673fSDevin Teske f_dprintf "$funcname: missing disk arguments" 1013bc4a673fSDevin Teske msg_error="$msg_error: $funcname" \ 1014bc4a673fSDevin Teske f_show_err "$msg_missing_disk_arguments" 1015cd88b886SDevin Teske return $FAILURE 1016cd88b886SDevin Teske fi 1017bc4a673fSDevin Teske f_dprintf "$funcname: poolname=[%s] vdev_type=[%s]" \ 10187cae6aabSDevin Teske "$zroot_name" "$zroot_vdevtype" 1019cd88b886SDevin Teske 1020a622223fSDevin Teske # 1021cd88b886SDevin Teske # Initialize fstab(5) 1022a622223fSDevin Teske # 1023bc4a673fSDevin Teske f_dprintf "$funcname: Initializing temporary fstab(5) file..." 1024a622223fSDevin Teske f_eval_catch $funcname sh "$SHELL_TRUNCATE" $BSDINSTALL_TMPETC/fstab || 1025bc4a673fSDevin Teske return $FAILURE 1026bc4a673fSDevin Teske f_eval_catch $funcname printf "$PRINTF_FSTAB" \ 1027cd88b886SDevin Teske "# Device" Mountpoint FStype Options Dump "Pass#" \ 1028a622223fSDevin Teske $BSDINSTALL_TMPETC/fstab || return $FAILURE 1029cd88b886SDevin Teske 1030a622223fSDevin Teske # 1031cd88b886SDevin Teske # Expand SI units in desired sizes 1032a622223fSDevin Teske # 10337cae6aabSDevin Teske f_dprintf "$funcname: Expanding supplied size values..." 10347cae6aabSDevin Teske local swapsize bootsize 1035bc4a673fSDevin Teske if ! f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize; then 1036bc4a673fSDevin Teske f_dprintf "$funcname: Invalid swap size \`%s'" \ 1037bc4a673fSDevin Teske "$ZFSBOOT_SWAP_SIZE" 1038bc4a673fSDevin Teske f_show_err "$msg_invalid_swap_size" "$ZFSBOOT_SWAP_SIZE" 1039bc4a673fSDevin Teske return $FAILURE 1040bc4a673fSDevin Teske fi 10417cae6aabSDevin Teske if ! f_expand_number "$ZFSBOOT_BOOT_POOL_SIZE" bootsize; then 10427cae6aabSDevin Teske f_dprintf "$funcname: Invalid boot pool size \`%s'" \ 10437cae6aabSDevin Teske "$ZFSBOOT_BOOT_POOL_SIZE" 10447cae6aabSDevin Teske f_show_err "$msg_invalid_boot_pool_size" \ 10457cae6aabSDevin Teske "$ZFSBOOT_BOOT_POOL_SIZE" 1046bc4a673fSDevin Teske return $FAILURE 1047bc4a673fSDevin Teske fi 1048bc4a673fSDevin Teske f_dprintf "$funcname: ZFSBOOT_SWAP_SIZE=[%s] swapsize=[%s]" \ 1049bc4a673fSDevin Teske "$ZFSBOOT_SWAP_SIZE" "$swapsize" 10507cae6aabSDevin Teske f_dprintf "$funcname: ZFSBOOT_BOOT_POOL_SIZE=[%s] bootsize=[%s]" \ 10517cae6aabSDevin Teske "$ZFSBOOT_BOOT_POOL_SIZE" "$bootsize" 1052cd88b886SDevin Teske 1053a622223fSDevin Teske # 1054a88393ceSDevin Teske # Destroy the pool in-case this is our second time 'round (case of 1055a88393ceSDevin Teske # failure and installer presented ``Retry'' option to come back). 1056a88393ceSDevin Teske # 1057a88393ceSDevin Teske # NB: If we don't destroy the pool, later gpart(8) destroy commands 1058a88393ceSDevin Teske # that try to clear existing partitions (see zfs_create_diskpart()) 1059a88393ceSDevin Teske # will fail with a `Device Busy' error, leading to `GEOM exists'. 1060a88393ceSDevin Teske # 1061a88393ceSDevin Teske f_eval_catch -d $funcname zpool "$ZPOOL_DESTROY" "$zroot_name" 1062a88393ceSDevin Teske 1063a88393ceSDevin Teske # 10647cae6aabSDevin Teske # Prepare the disks and build pool device list(s) 1065a622223fSDevin Teske # 1066bc4a673fSDevin Teske f_dprintf "$funcname: Preparing disk partitions for ZFS pool..." 1067b4843bd6SSteven Hartland 1068b4843bd6SSteven Hartland # Force 4K sectors using vfs.zfs.min_auto_ashift=12 1069b4843bd6SSteven Hartland if [ "$ZFSBOOT_FORCE_4K_SECTORS" ]; then 1070b4843bd6SSteven Hartland f_dprintf "$funcname: With 4K sectors..." 1071b4843bd6SSteven Hartland f_eval_catch $funcname sysctl "$SYSCTL_ZFS_MIN_ASHIFT_12" \ 1072b4843bd6SSteven Hartland || return $FAILURE 1073b4843bd6SSteven Hartland fi 1074cd88b886SDevin Teske local n=0 1075a622223fSDevin Teske for disk in $disks; do 1076cd88b886SDevin Teske zfs_create_diskpart $disk $n || return $FAILURE 10772875e59fSOllivier Robert # Now $bootpart, $targetpart, and $swappart are set (suffix 10782875e59fSOllivier Robert # for $disk) 10797cae6aabSDevin Teske if [ "$ZFSBOOT_BOOT_POOL" ]; then 10807cae6aabSDevin Teske boot_vdevs="$boot_vdevs $disk$bootpart" 10817cae6aabSDevin Teske fi 10827cae6aabSDevin Teske zroot_vdevs="$zroot_vdevs $disk$targetpart" 1083e751d176SSteven Hartland if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then 1084e751d176SSteven Hartland zroot_vdevs="$zroot_vdevs.eli" 1085e751d176SSteven Hartland fi 10867cae6aabSDevin Teske 10877cae6aabSDevin Teske n=$(( $n + 1 )) 10887cae6aabSDevin Teske done # disks 10897cae6aabSDevin Teske 10907cae6aabSDevin Teske # 10917cae6aabSDevin Teske # If we need/want a boot pool, create it 10927cae6aabSDevin Teske # 10937cae6aabSDevin Teske if [ "$ZFSBOOT_BOOT_POOL" ]; then 10947cae6aabSDevin Teske local bootpool_vdevtype= # Calculated below 10957cae6aabSDevin Teske local bootpool_options= # Calculated below 10967cae6aabSDevin Teske local bootpool_name="$ZFSBOOT_BOOT_POOL_NAME" 10977cae6aabSDevin Teske local bootpool="$BSDINSTALL_CHROOT/$bootpool_name" 10987cae6aabSDevin Teske local zroot_key="${ZFSBOOT_GELI_KEY_FILE#/}" 10997cae6aabSDevin Teske 11007cae6aabSDevin Teske f_dprintf "$funcname: Setting up boot pool..." 1101cd88b886SDevin Teske [ "$ZFSBOOT_GELI_ENCRYPTION" ] && 11027cae6aabSDevin Teske f_dprintf "$funcname: For encrypted root disk..." 1103cd88b886SDevin Teske 11047cae6aabSDevin Teske # Create parent directory for boot pool 1105a622223fSDevin Teske f_eval_catch -d $funcname umount "$UMOUNT" /mnt 1106bc4a673fSDevin Teske f_eval_catch $funcname mount "$MOUNT_TYPE" tmpfs none \ 1107a622223fSDevin Teske $BSDINSTALL_CHROOT || return $FAILURE 1108cd88b886SDevin Teske 11097cae6aabSDevin Teske # Create mirror across the boot partition on all disks 1110a88393ceSDevin Teske local nvdevs 1111a88393ceSDevin Teske f_count nvdevs $boot_vdevs 1112a88393ceSDevin Teske [ $nvdevs -gt 1 ] && bootpool_vdevtype=mirror 1113cd88b886SDevin Teske 111447206692SDevin Teske create_options="$ZFSBOOT_BOOT_POOL_CREATE_OPTIONS" 11157cae6aabSDevin Teske bootpool_options="-o altroot=$BSDINSTALL_CHROOT" 111647206692SDevin Teske bootpool_options="$bootpool_options $create_options" 11177cae6aabSDevin Teske bootpool_options="$bootpool_options -m \"/$bootpool_name\" -f" 1118bc4a673fSDevin Teske f_eval_catch $funcname zpool "$ZPOOL_CREATE_WITH_OPTIONS" \ 11197cae6aabSDevin Teske "$bootpool_options" "$bootpool_name" \ 11204b4b90d5SDevin Teske "$bootpool_vdevtype" "$boot_vdevs" || 11214b4b90d5SDevin Teske return $FAILURE 112245df402eSDevin Teske 11237cae6aabSDevin Teske f_eval_catch $funcname mkdir "$MKDIR_P" "$bootpool/boot" || 1124cd88b886SDevin Teske return $FAILURE 1125cd88b886SDevin Teske 11267cae6aabSDevin Teske if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then 1127cd88b886SDevin Teske # Generate an encryption key using random(4) 1128bc4a673fSDevin Teske f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \ 11297cae6aabSDevin Teske /dev/random "$bootpool/$zroot_key" \ 11307cae6aabSDevin Teske "bs=4096 count=1" || return $FAILURE 11317cae6aabSDevin Teske else 11327cae6aabSDevin Teske # Clean up 11337cae6aabSDevin Teske f_eval_catch $funcname zfs "$ZFS_UNMOUNT" \ 11347cae6aabSDevin Teske "$bootpool_name" || return $FAILURE 11357cae6aabSDevin Teske f_eval_catch -d $funcname umount "$UMOUNT" /mnt # tmpfs 11367cae6aabSDevin Teske fi 11377cae6aabSDevin Teske 11387cae6aabSDevin Teske fi 1139cd88b886SDevin Teske 1140a622223fSDevin Teske # 1141cd88b886SDevin Teske # Create the geli(8) GEOMS 1142a622223fSDevin Teske # 11437cae6aabSDevin Teske if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then 11447cae6aabSDevin Teske # Prompt user for password (twice) 1145bc4a673fSDevin Teske if ! msg_enter_new_password="$msg_geli_password" \ 1146bc4a673fSDevin Teske f_dialog_input_password 1147bc4a673fSDevin Teske then 1148bc4a673fSDevin Teske f_dprintf "$funcname: User cancelled" 1149bc4a673fSDevin Teske f_show_err "$msg_user_cancelled" 1150bc4a673fSDevin Teske return $FAILURE 1151bc4a673fSDevin Teske fi 1152a622223fSDevin Teske 1153a622223fSDevin Teske # Initialize geli(8) on each of the target partitions 1154bc4a673fSDevin Teske for disk in $disks; do 1155cd88b886SDevin Teske f_dialog_info "$msg_geli_setup" \ 1156cd88b886SDevin Teske 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 1157a622223fSDevin Teske if ! echo "$pw_password" | f_eval_catch \ 1158a622223fSDevin Teske $funcname geli "$GELI_PASSWORD_INIT" \ 11597cae6aabSDevin Teske "$bootpool/boot/$disk$targetpart.eli" \ 11607cae6aabSDevin Teske AES-XTS "$bootpool/$zroot_key" \ 1161a622223fSDevin Teske $disk$targetpart 1162bc4a673fSDevin Teske then 1163bc4a673fSDevin Teske f_interactive || f_die 1164a622223fSDevin Teske unset pw_password # Sensitive info 1165cd88b886SDevin Teske return $FAILURE 1166bc4a673fSDevin Teske fi 1167a622223fSDevin Teske if ! echo "$pw_password" | f_eval_catch \ 1168a622223fSDevin Teske $funcname geli "$GELI_ATTACH" \ 11697cae6aabSDevin Teske "$bootpool/$zroot_key" $disk$targetpart 1170bc4a673fSDevin Teske then 1171bc4a673fSDevin Teske f_interactive || f_die 1172a622223fSDevin Teske unset pw_password # Sensitive info 1173bc4a673fSDevin Teske return $FAILURE 1174bc4a673fSDevin Teske fi 1175cd88b886SDevin Teske done 1176a622223fSDevin Teske unset pw_password # Sensitive info 1177a622223fSDevin Teske 1178a622223fSDevin Teske # Clean up 11797cae6aabSDevin Teske f_eval_catch $funcname zfs "$ZFS_UNMOUNT" "$bootpool_name" || 11807cae6aabSDevin Teske return $FAILURE 1181a622223fSDevin Teske f_eval_catch -d $funcname umount "$UMOUNT" /mnt # tmpfs 1182cd88b886SDevin Teske fi 1183*33112d9eSDevin Teske 11842875e59fSOllivier Robert # 11852875e59fSOllivier Robert # Create the gmirror(8) GEOMS for swap 11862875e59fSOllivier Robert # 11872875e59fSOllivier Robert if [ "$ZFSBOOT_SWAP_MIRROR" ]; then 11882875e59fSOllivier Robert for disk in $disks; do 11892875e59fSOllivier Robert swap_devs="$swap_devs $disk$swappart" 11902875e59fSOllivier Robert done 11912875e59fSOllivier Robert f_eval_catch $funcname gmirror "$SWAP_GMIRROR_LABEL" \ 11922875e59fSOllivier Robert "$swap_devs" || return $FAILURE 11932875e59fSOllivier Robert fi 1194cd88b886SDevin Teske 1195cd88b886SDevin Teske # 1196a622223fSDevin Teske # Create the ZFS root pool with desired type and disk devices 1197cd88b886SDevin Teske # 11987cae6aabSDevin Teske f_dprintf "$funcname: Creating root pool..." 119947206692SDevin Teske create_options="$ZFSBOOT_POOL_CREATE_OPTIONS" 1200bc4a673fSDevin Teske f_eval_catch $funcname zpool "$ZPOOL_CREATE_WITH_OPTIONS" \ 120147206692SDevin Teske "-o altroot=$BSDINSTALL_CHROOT $create_options -m none -f" \ 12024b4b90d5SDevin Teske "$zroot_name" "$zroot_vdevtype" "$zroot_vdevs" || 12034b4b90d5SDevin Teske return $FAILURE 1204cd88b886SDevin Teske 1205cd88b886SDevin Teske # 12067cae6aabSDevin Teske # Create ZFS dataset layout within the new root pool 1207cd88b886SDevin Teske # 1208bc4a673fSDevin Teske f_dprintf "$funcname: Creating ZFS datasets..." 1209cd88b886SDevin Teske echo "$ZFSBOOT_DATASETS" | while read dataset options; do 1210cd88b886SDevin Teske # Skip blank lines and comments 1211cd88b886SDevin Teske case "$dataset" in "#"*|"") continue; esac 1212cd88b886SDevin Teske # Remove potential inline comments in options 1213cd88b886SDevin Teske options="${options%%#*}" 1214cd88b886SDevin Teske # Replace tabs with spaces 1215cd88b886SDevin Teske f_replaceall "$options" " " " " options 1216cd88b886SDevin Teske # Reduce contiguous runs of space to one single space 1217cd88b886SDevin Teske oldoptions= 1218cd88b886SDevin Teske while [ "$oldoptions" != "$options" ]; do 1219cd88b886SDevin Teske oldoptions="$options" 1220cd88b886SDevin Teske f_replaceall "$options" " " " " options 1221cd88b886SDevin Teske done 1222cd88b886SDevin Teske # Replace both commas and spaces with ` -o ' 1223cd88b886SDevin Teske f_replaceall "$options" "[ ,]" " -o " options 1224cd88b886SDevin Teske # Create the dataset with desired options 1225bc4a673fSDevin Teske f_eval_catch $funcname zfs "$ZFS_CREATE_WITH_OPTIONS" \ 12267cae6aabSDevin Teske "${options:+-o $options}" "$zroot_name$dataset" || 1227cd88b886SDevin Teske return $FAILURE 1228cd88b886SDevin Teske done 1229cd88b886SDevin Teske 1230cd88b886SDevin Teske # Touch up permissions on the tmp directories 1231bc4a673fSDevin Teske f_dprintf "$funcname: Modifying directory permissions..." 1232bc4a673fSDevin Teske local dir 1233bc4a673fSDevin Teske for dir in /tmp /var/tmp; do 1234bc4a673fSDevin Teske f_eval_catch $funcname chmod "$CHMOD_MODE" 1777 \ 1235a622223fSDevin Teske $BSDINSTALL_CHROOTDIR$dir || return $FAILURE 1236bc4a673fSDevin Teske done 1237cd88b886SDevin Teske 1238cd88b886SDevin Teske # Create symlink(s) 12397cae6aabSDevin Teske if [ "$ZFSBOOT_BOOT_POOL" ]; then 12407cae6aabSDevin Teske f_dprintf "$funcname: Creating /boot symlink for boot pool..." 12417cae6aabSDevin Teske f_eval_catch $funcname ln "$LN_SF" "$bootpool_name/boot" \ 1242a622223fSDevin Teske $BSDINSTALL_CHROOT/boot || return $FAILURE 1243bc4a673fSDevin Teske fi 1244cd88b886SDevin Teske 1245cd88b886SDevin Teske # Set bootfs property 12467cae6aabSDevin Teske local zroot_bootfs="$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOTFS_NAME" 1247bc4a673fSDevin Teske f_dprintf "$funcname: Setting bootfs property..." 1248bc4a673fSDevin Teske f_eval_catch $funcname zpool "$ZPOOL_SET" \ 12497cae6aabSDevin Teske "bootfs=\"$zroot_name/$zroot_bootfs\"" "$zroot_name" || 12507cae6aabSDevin Teske return $FAILURE 1251cd88b886SDevin Teske 1252cd88b886SDevin Teske # Export the pool(s) 1253bc4a673fSDevin Teske f_dprintf "$funcname: Temporarily exporting ZFS pool(s)..." 12547cae6aabSDevin Teske f_eval_catch $funcname zpool "$ZPOOL_EXPORT" "$zroot_name" || 1255bc4a673fSDevin Teske return $FAILURE 12567cae6aabSDevin Teske if [ "$ZFSBOOT_BOOT_POOL" ]; then 1257bc4a673fSDevin Teske f_eval_catch $funcname zpool "$ZPOOL_EXPORT" \ 12587cae6aabSDevin Teske "$bootpool_name" || return $FAILURE 1259bc4a673fSDevin Teske fi 1260cd88b886SDevin Teske 12617cae6aabSDevin Teske # MBR boot loader touch-up 1262cd88b886SDevin Teske if [ "$ZFSBOOT_PARTITION_SCHEME" = "MBR" ]; then 1263bc4a673fSDevin Teske f_dprintf "$funcname: Updating MBR boot loader on disks..." 1264cd88b886SDevin Teske # Stick the ZFS boot loader in the "convienient hole" after 1265cd88b886SDevin Teske # the ZFS internal metadata 1266bc4a673fSDevin Teske for disk in $disks; do 1267bc4a673fSDevin Teske f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \ 1268a622223fSDevin Teske /boot/zfsboot /dev/$disk$bootpart \ 1269bc4a673fSDevin Teske "skip=1 seek=1024" || return $FAILURE 1270cd88b886SDevin Teske done 1271cd88b886SDevin Teske fi 1272cd88b886SDevin Teske 1273cd88b886SDevin Teske # Re-import the ZFS pool(s) 1274bc4a673fSDevin Teske f_dprintf "$funcname: Re-importing ZFS pool(s)..." 1275bc4a673fSDevin Teske f_eval_catch $funcname zpool "$ZPOOL_IMPORT_WITH_OPTIONS" \ 12767cae6aabSDevin Teske "-o altroot=\"$BSDINSTALL_CHROOT\"" "$zroot_name" || 1277bc4a673fSDevin Teske return $FAILURE 12787cae6aabSDevin Teske if [ "$ZFSBOOT_BOOT_POOL" ]; then 1279bc4a673fSDevin Teske f_eval_catch $funcname zpool "$ZPOOL_IMPORT_WITH_OPTIONS" \ 12807cae6aabSDevin Teske "-o altroot=\"$BSDINSTALL_CHROOT\"" \ 12817cae6aabSDevin Teske "$bootpool_name" || return $FAILURE 1282bc4a673fSDevin Teske fi 1283cd88b886SDevin Teske 1284cd88b886SDevin Teske # While this is apparently not needed, it seems to help MBR 12856311cc9eSDevin Teske f_dprintf "$funcname: Configuring zpool.cache for zroot..." 1286a622223fSDevin Teske f_eval_catch $funcname mkdir "$MKDIR_P" $BSDINSTALL_CHROOT/boot/zfs || 1287bc4a673fSDevin Teske return $FAILURE 1288bc4a673fSDevin Teske f_eval_catch $funcname zpool "$ZPOOL_SET" \ 1289a622223fSDevin Teske "cachefile=\"$BSDINSTALL_CHROOT/boot/zfs/zpool.cache\"" \ 12907cae6aabSDevin Teske "$zroot_name" || return $FAILURE 1291cd88b886SDevin Teske 129213d8e1ceSDevin Teske # Last, but not least... required lines for rc.conf(5)/loader.conf(5) 1293cd88b886SDevin Teske # NOTE: We later concatenate these into their destination 1294bc4a673fSDevin Teske f_dprintf "%s: Configuring rc.conf(5)/loader.conf(5) additions..." \ 1295bc4a673fSDevin Teske "$funcname" 1296bc4a673fSDevin Teske f_eval_catch $funcname echo "$ECHO_APPEND" 'zfs_enable=\"YES\"' \ 1297a622223fSDevin Teske $BSDINSTALL_TMPETC/rc.conf.zfs || return $FAILURE 1298ee482f2cSDevin Teske f_eval_catch $funcname echo "$ECHO_APPEND" \ 1299ee482f2cSDevin Teske 'kern.geom.label.disk_ident.enable=\"0\"' \ 1300ee482f2cSDevin Teske $BSDINSTALL_TMPBOOT/loader.conf.zfs || return $FAILURE 13012875e59fSOllivier Robert f_eval_catch $funcname echo "$ECHO_APPEND" \ 13022875e59fSOllivier Robert 'kern.geom.label.gptid.enable=\"0\"' \ 13032875e59fSOllivier Robert $BSDINSTALL_TMPBOOT/loader.conf.zfs || return $FAILURE 13042875e59fSOllivier Robert 13052875e59fSOllivier Robert if [ "$ZFSBOOT_SWAP_MIRROR" ]; then 1306*33112d9eSDevin Teske f_eval_catch $funcname echo "$ECHO_APPEND" \ 1307*33112d9eSDevin Teske 'geom_mirror_load=\"YES\"' \ 1308*33112d9eSDevin Teske $BSDINSTALL_TMPBOOT/loader.conf.gmirror || 1309*33112d9eSDevin Teske return $FAILURE 13102875e59fSOllivier Robert fi 1311cd88b886SDevin Teske 13127cae6aabSDevin Teske # We're all done unless we should go on for boot pool 13137cae6aabSDevin Teske [ "$ZFSBOOT_BOOT_POOL" ] || return $SUCCESS 1314cd88b886SDevin Teske 13156311cc9eSDevin Teske # Set cachefile for boot pool so it auto-imports at system start 13166311cc9eSDevin Teske f_dprintf "$funcname: Configuring zpool.cache for boot pool..." 13176311cc9eSDevin Teske f_eval_catch $funcname zpool "$ZPOOL_SET" \ 13186311cc9eSDevin Teske "cachefile=\"$BSDINSTALL_CHROOT/boot/zfs/zpool.cache\"" \ 13196311cc9eSDevin Teske "$bootpool_name" || return $FAILURE 13206311cc9eSDevin Teske 1321bc4a673fSDevin Teske # Some additional geli(8) requirements for loader.conf(5) 1322bc4a673fSDevin Teske for option in \ 1323a622223fSDevin Teske 'zpool_cache_load=\"YES\"' \ 1324a622223fSDevin Teske 'zpool_cache_type=\"/boot/zfs/zpool.cache\"' \ 1325a622223fSDevin Teske 'zpool_cache_name=\"/boot/zfs/zpool.cache\"' \ 1326bc4a673fSDevin Teske ; do 1327a622223fSDevin Teske f_eval_catch $funcname echo "$ECHO_APPEND" "$option" \ 1328a622223fSDevin Teske $BSDINSTALL_TMPBOOT/loader.conf.zfs || 1329bc4a673fSDevin Teske return $FAILURE 1330bc4a673fSDevin Teske done 13317cae6aabSDevin Teske f_eval_catch $funcname printf "$PRINTF_CONF" vfs.root.mountfrom \ 13327cae6aabSDevin Teske "\"zfs:$zroot_name/$zroot_bootfs\"" \ 13337cae6aabSDevin Teske $BSDINSTALL_TMPBOOT/loader.conf.root || return $FAILURE 13347cae6aabSDevin Teske 13357cae6aabSDevin Teske # We're all done unless we should go on to do encryption 13367cae6aabSDevin Teske [ "$ZFSBOOT_GELI_ENCRYPTION" ] || return $SUCCESS 133713d8e1ceSDevin Teske 1338cd88b886SDevin Teske # 1339cd88b886SDevin Teske # Configure geli(8)-based encryption 1340cd88b886SDevin Teske # 1341bc4a673fSDevin Teske f_dprintf "$funcname: Configuring disk encryption..." 1342bc4a673fSDevin Teske f_eval_catch $funcname echo "$ECHO_APPEND" 'aesni_load=\"YES\"' \ 1343a622223fSDevin Teske $BSDINSTALL_TMPBOOT/loader.conf.aesni || return $FAILURE 1344bc4a673fSDevin Teske f_eval_catch $funcname echo "$ECHO_APPEND" 'geom_eli_load=\"YES\"' \ 1345a622223fSDevin Teske $BSDINSTALL_TMPBOOT/loader.conf.geli || return $FAILURE 1346bc4a673fSDevin Teske for disk in $disks; do 1347bc4a673fSDevin Teske f_eval_catch $funcname printf "$PRINTF_CONF" \ 1348a622223fSDevin Teske geli_%s_keyfile0_load "$disk$targetpart YES" \ 1349a622223fSDevin Teske $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart || 1350cd88b886SDevin Teske return $FAILURE 1351bc4a673fSDevin Teske f_eval_catch $funcname printf "$PRINTF_CONF" \ 1352bc4a673fSDevin Teske geli_%s_keyfile0_type \ 1353a622223fSDevin Teske "$disk$targetpart $disk$targetpart:geli_keyfile0" \ 1354a622223fSDevin Teske $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart || 1355cd88b886SDevin Teske return $FAILURE 1356bc4a673fSDevin Teske f_eval_catch $funcname printf "$PRINTF_CONF" \ 1357bc4a673fSDevin Teske geli_%s_keyfile0_name \ 1358a622223fSDevin Teske "$disk$targetpart \"$ZFSBOOT_GELI_KEY_FILE\"" \ 1359a622223fSDevin Teske $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart || 1360cd88b886SDevin Teske return $FAILURE 1361cd88b886SDevin Teske done 1362cd88b886SDevin Teske 1363cd88b886SDevin Teske return $SUCCESS 1364cd88b886SDevin Teske} 1365cd88b886SDevin Teske 1366cd88b886SDevin Teske# dialog_menu_diskinfo 1367cd88b886SDevin Teske# 1368cd88b886SDevin Teske# Prompt the user to select a disk and then provide detailed info on it. 1369cd88b886SDevin Teske# 1370cd88b886SDevin Teskedialog_menu_diskinfo() 1371cd88b886SDevin Teske{ 1372a88393ceSDevin Teske local device disk 1373cd88b886SDevin Teske 1374cd88b886SDevin Teske # 1375cd88b886SDevin Teske # Break from loop when user cancels disk selection 1376cd88b886SDevin Teske # 1377cd88b886SDevin Teske while :; do 1378a88393ceSDevin Teske device=$( msg_cancel="$msg_back" f_device_menu \ 1379cd88b886SDevin Teske "$DIALOG_TITLE" "$msg_select_a_disk_device" "" \ 1380cd88b886SDevin Teske $DEVICE_TYPE_DISK 2>&1 ) || break 1381a88393ceSDevin Teske $device get name disk 1382cd88b886SDevin Teske 1383cd88b886SDevin Teske # Show gpart(8) `show' and camcontrol(8) `inquiry' data 1384cd88b886SDevin Teske f_show_msg "$msg_detailed_disk_info" \ 1385cd88b886SDevin Teske "$disk" "$( gpart show $disk 2> /dev/null )" \ 1386cd88b886SDevin Teske "$disk" "$( camcontrol inquiry $disk 2> /dev/null )" \ 1387cd88b886SDevin Teske "$disk" "$( camcontrol identify $disk 2> /dev/null )" 1388cd88b886SDevin Teske done 1389cd88b886SDevin Teske 1390cd88b886SDevin Teske return $SUCCESS 1391cd88b886SDevin Teske} 1392cd88b886SDevin Teske 1393cd88b886SDevin Teske############################################################ MAIN 1394cd88b886SDevin Teske 1395cd88b886SDevin Teske# 1396cd88b886SDevin Teske# Initialize 1397cd88b886SDevin Teske# 1398cd88b886SDevin Teskef_dialog_title "$msg_zfs_configuration" 1399cd88b886SDevin Teskef_dialog_backtitle "$msg_freebsd_installer" 1400cd88b886SDevin Teske 1401cd88b886SDevin Teske# User may have specifically requested ZFS-related operations be interactive 1402cd88b886SDevin Teske! f_interactive && f_zfsinteractive && unset $VAR_NONINTERACTIVE 1403cd88b886SDevin Teske 1404cd88b886SDevin Teske# 1405bc4a673fSDevin Teske# Debugging 1406bc4a673fSDevin Teske# 1407bc4a673fSDevin Teskef_dprintf "BSDINSTALL_CHROOT=[%s]" "$BSDINSTALL_CHROOT" 1408bc4a673fSDevin Teskef_dprintf "BSDINSTALL_TMPETC=[%s]" "$BSDINSTALL_TMPETC" 1409a622223fSDevin Teskef_dprintf "FSTAB_FMT=[%s]" "$FSTAB_FMT" 1410bc4a673fSDevin Teske 1411bc4a673fSDevin Teske# 141212307018SAllan Jude# If the system was booted with UEFI, warn the user that FreeBSD can't do 141312307018SAllan Jude# ZFS with UEFI yet 141412307018SAllan Jude# 141512307018SAllan Judeif f_interactive; then 141612307018SAllan Jude bootmethod=$( sysctl -n machdep.bootmethod ) 141712307018SAllan Jude f_dprintf "machdep.bootmethod=[%s]" "$bootmethod" 141812307018SAllan Jude if [ "$bootmethod" != "BIOS" ]; then 141912307018SAllan Jude dialog_uefi_prompt 142012307018SAllan Jude retval=$? 142112307018SAllan Jude f_dprintf "uefi_prompt=[%s]" "$retval" 142212307018SAllan Jude [ $retval -eq $DIALOG_OK ] || f_die 142312307018SAllan Jude fi 142412307018SAllan Judefi 142512307018SAllan Jude 142612307018SAllan Jude# 1427cd88b886SDevin Teske# Loop over the main menu until we've accomplished what we came here to do 1428cd88b886SDevin Teske# 1429cd88b886SDevin Teskewhile :; do 1430cd88b886SDevin Teske if ! f_interactive; then 1431cd88b886SDevin Teske retval=$DIALOG_OK 1432bc4a673fSDevin Teske mtag=">>> $msg_install" 1433cd88b886SDevin Teske else 1434cd88b886SDevin Teske dialog_menu_main 1435cd88b886SDevin Teske retval=$? 1436cd88b886SDevin Teske f_dialog_menutag_fetch mtag 1437cd88b886SDevin Teske fi 1438cd88b886SDevin Teske 1439bc4a673fSDevin Teske f_dprintf "retval=%u mtag=[%s]" $retval "$mtag" 1440cd88b886SDevin Teske [ $retval -eq $DIALOG_OK ] || f_die 1441cd88b886SDevin Teske 1442cd88b886SDevin Teske case "$mtag" in 1443bc4a673fSDevin Teske ">>> $msg_install") 1444cd88b886SDevin Teske # 1445cd88b886SDevin Teske # First, validate the user's selections 1446cd88b886SDevin Teske # 1447cd88b886SDevin Teske 1448cd88b886SDevin Teske # Make sure they gave us a name for the pool 1449cd88b886SDevin Teske if [ ! "$ZFSBOOT_POOL_NAME" ]; then 1450bc4a673fSDevin Teske f_dprintf "Pool name cannot be empty." 1451bc4a673fSDevin Teske f_show_err "$msg_pool_name_cannot_be_empty" 1452cd88b886SDevin Teske continue 1453cd88b886SDevin Teske fi 1454bc4a673fSDevin Teske 1455bc4a673fSDevin Teske # Validate vdev type against number of disks selected/scripted 1456bc4a673fSDevin Teske # (also validates that ZFSBOOT_DISKS are real [probed] disks) 1457bc4a673fSDevin Teske # NB: dialog_menu_layout supports running non-interactively 1458bc4a673fSDevin Teske dialog_menu_layout || continue 1459bc4a673fSDevin Teske 1460cd88b886SDevin Teske # Make sure each disk will be at least 50% ZFS 1461cd88b886SDevin Teske if f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize && 14627cae6aabSDevin Teske f_expand_number "$ZFSBOOT_BOOT_POOL_SIZE" bootsize 1463cd88b886SDevin Teske then 1464cd88b886SDevin Teske minsize=$swapsize teeny_disks= 14657cae6aabSDevin Teske [ "$ZFSBOOT_BOOT_POOL" ] && 14667cae6aabSDevin Teske minsize=$(( $minsize + $bootsize )) 1467bc4a673fSDevin Teske for disk in $ZFSBOOT_DISKS; do 1468a88393ceSDevin Teske debug= f_device_find -1 \ 1469a88393ceSDevin Teske $disk $DEVICE_TYPE_DISK device 1470a88393ceSDevin Teske $device get capacity disksize || continue 1471a88393ceSDevin Teske [ ${disksize:-0} -ge 0 ] || disksize=0 1472cd88b886SDevin Teske disksize=$(( $disksize - $minsize )) 1473cd88b886SDevin Teske [ $disksize -lt $minsize ] && 1474cd88b886SDevin Teske teeny_disks="$teeny_disks $disk" 1475cd88b886SDevin Teske done 1476cd88b886SDevin Teske if [ "$teeny_disks" ]; then 14777cae6aabSDevin Teske f_dprintf "swapsize=[%s] bootsize[%s] %s" \ 1478bc4a673fSDevin Teske "$ZFSBOOT_SWAP_SIZE" \ 14797cae6aabSDevin Teske "$ZFSBOOT_BOOT_POOL_SIZE" \ 14807cae6aabSDevin Teske "minsize=[$minsize]" 1481bc4a673fSDevin Teske f_dprintf "These disks are too small: %s" \ 1482bc4a673fSDevin Teske "$teeny_disks" 1483bc4a673fSDevin Teske f_show_err "$msg_these_disks_are_too_small" \ 1484cd88b886SDevin Teske "$ZFSBOOT_SWAP_SIZE" \ 14857cae6aabSDevin Teske "$ZFSBOOT_BOOT_POOL_SIZE" \ 1486cd88b886SDevin Teske "$teeny_disks" 1487cd88b886SDevin Teske continue 1488cd88b886SDevin Teske fi 1489cd88b886SDevin Teske fi 1490cd88b886SDevin Teske 1491cd88b886SDevin Teske # 1492cd88b886SDevin Teske # Last Chance! 1493cd88b886SDevin Teske # 1494bc4a673fSDevin Teske if f_interactive; then 1495bc4a673fSDevin Teske dialog_last_chance $ZFSBOOT_DISKS || continue 1496cd88b886SDevin Teske fi 1497cd88b886SDevin Teske 1498cd88b886SDevin Teske # 1499cd88b886SDevin Teske # Let's do this 1500cd88b886SDevin Teske # 1501cd88b886SDevin Teske 1502cd88b886SDevin Teske vdev_type="$ZFSBOOT_VDEV_TYPE" 1503cd88b886SDevin Teske 1504cd88b886SDevin Teske # Blank the vdev type for the default layout 1505cd88b886SDevin Teske [ "$vdev_type" = "stripe" ] && vdev_type= 1506cd88b886SDevin Teske 1507bc4a673fSDevin Teske zfs_create_boot "$ZFSBOOT_POOL_NAME" \ 1508bc4a673fSDevin Teske "$vdev_type" $ZFSBOOT_DISKS || continue 1509cd88b886SDevin Teske 1510cd88b886SDevin Teske break # to success 1511cd88b886SDevin Teske ;; 1512bc4a673fSDevin Teske ?" $msg_pool_type_disks") 1513bc4a673fSDevin Teske ZFSBOOT_CONFIRM_LAYOUT=1 1514bc4a673fSDevin Teske dialog_menu_layout 1515bc4a673fSDevin Teske # User has poked settings, disable later confirmation 1516bc4a673fSDevin Teske ZFSBOOT_CONFIRM_LAYOUT= 1517bc4a673fSDevin Teske ;; 1518cd88b886SDevin Teske "- $msg_rescan_devices") f_device_rescan ;; 1519cd88b886SDevin Teske "- $msg_disk_info") dialog_menu_diskinfo ;; 1520cd88b886SDevin Teske ?" $msg_pool_name") 1521cd88b886SDevin Teske # Prompt the user to input/change the name for the new pool 1522cd88b886SDevin Teske f_dialog_input input \ 1523cd88b886SDevin Teske "$msg_please_enter_a_name_for_your_zpool" \ 1524cd88b886SDevin Teske "$ZFSBOOT_POOL_NAME" && 1525cd88b886SDevin Teske ZFSBOOT_POOL_NAME="$input" 1526cd88b886SDevin Teske ;; 1527cd88b886SDevin Teske ?" $msg_force_4k_sectors") 1528cd88b886SDevin Teske # Toggle the variable referenced both by the menu and later 1529b4843bd6SSteven Hartland if [ "$ZFSBOOT_FORCE_4K_SECTORS" ]; then 1530b4843bd6SSteven Hartland ZFSBOOT_FORCE_4K_SECTORS= 1531cd88b886SDevin Teske else 1532b4843bd6SSteven Hartland ZFSBOOT_FORCE_4K_SECTORS=1 1533cd88b886SDevin Teske fi 1534cd88b886SDevin Teske ;; 1535bc4a673fSDevin Teske ?" $msg_encrypt_disks") 1536cd88b886SDevin Teske # Toggle the variable referenced both by the menu and later 1537cd88b886SDevin Teske if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then 1538cd88b886SDevin Teske ZFSBOOT_GELI_ENCRYPTION= 1539cd88b886SDevin Teske else 1540b4843bd6SSteven Hartland ZFSBOOT_FORCE_4K_SECTORS=1 1541cd88b886SDevin Teske ZFSBOOT_GELI_ENCRYPTION=1 1542cd88b886SDevin Teske fi 1543cd88b886SDevin Teske ;; 1544cd88b886SDevin Teske ?" $msg_partition_scheme") 1545cd88b886SDevin Teske # Toggle between GPT and MBR 1546cd88b886SDevin Teske if [ "$ZFSBOOT_PARTITION_SCHEME" = GPT ]; then 1547cd88b886SDevin Teske ZFSBOOT_PARTITION_SCHEME=MBR 1548cd88b886SDevin Teske else 1549cd88b886SDevin Teske ZFSBOOT_PARTITION_SCHEME=GPT 1550cd88b886SDevin Teske fi 1551cd88b886SDevin Teske ;; 1552cd88b886SDevin Teske ?" $msg_swap_size") 1553cd88b886SDevin Teske # Prompt the user to input/change the swap size for each disk 1554cd88b886SDevin Teske f_dialog_input input \ 1555cd88b886SDevin Teske "$msg_please_enter_amount_of_swap_space" \ 1556cd88b886SDevin Teske "$ZFSBOOT_SWAP_SIZE" && 155730c8ebe9SDevin Teske ZFSBOOT_SWAP_SIZE="${input:-0}" 1558cd88b886SDevin Teske ;; 15592875e59fSOllivier Robert ?" $msg_swap_mirror") 15602875e59fSOllivier Robert # Toggle the variable referenced both by the menu and later 15612875e59fSOllivier Robert if [ "$ZFSBOOT_SWAP_MIRROR" ]; then 15622875e59fSOllivier Robert ZFSBOOT_SWAP_MIRROR= 15632875e59fSOllivier Robert else 15642875e59fSOllivier Robert ZFSBOOT_SWAP_MIRROR=1 15652875e59fSOllivier Robert fi 15662875e59fSOllivier Robert ;; 15672875e59fSOllivier Robert ?" $msg_swap_encrypt") 15682875e59fSOllivier Robert # Toggle the variable referenced both by the menu and later 15692875e59fSOllivier Robert if [ "$ZFSBOOT_SWAP_ENCRYPTION" ]; then 15702875e59fSOllivier Robert ZFSBOOT_SWAP_ENCRYPTION= 15712875e59fSOllivier Robert else 15722875e59fSOllivier Robert ZFSBOOT_SWAP_ENCRYPTION=1 15732875e59fSOllivier Robert fi 15742875e59fSOllivier Robert ;; 1575cd88b886SDevin Teske esac 1576cd88b886SDevin Teskedone 1577cd88b886SDevin Teske 1578cd88b886SDevin Teskereturn $SUCCESS 1579cd88b886SDevin Teske 1580cd88b886SDevin Teske################################################################################ 1581cd88b886SDevin Teske# END 1582cd88b886SDevin Teske################################################################################ 1583