1cd88b886SDevin Teske#!/bin/sh 2cd88b886SDevin Teske#- 3a1b8f55cSAllan Jude# Copyright (c) 2013-2016 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# 585e38260cSBaptiste Daroussin# Default name for the primary 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# 1120edc8cc8SAllan Jude: ${ZFSBOOT_PARTITION_SCHEME:=} 1130edc8cc8SAllan Jude 1140edc8cc8SAllan Jude# 1154d41f472SAllan Jude# Default boot type to use on disks 1160edc8cc8SAllan Jude# 1170edc8cc8SAllan Jude: ${ZFSBOOT_BOOT_TYPE:=} 118cd88b886SDevin Teske 119cd88b886SDevin Teske# 120cd88b886SDevin Teske# How much swap to put on each block device in the boot zpool 121cd88b886SDevin Teske# NOTE: Value passed to gpart(8); which supports SI unit suffixes. 122cd88b886SDevin Teske# 123cd88b886SDevin Teske: ${ZFSBOOT_SWAP_SIZE:=2g} 124cd88b886SDevin Teske 125cd88b886SDevin Teske# 1262875e59fSOllivier Robert# Should we use geli(8) to encrypt the swap? 1272875e59fSOllivier Robert# 1282875e59fSOllivier Robert: ${ZFSBOOT_SWAP_ENCRYPTION=} 1292875e59fSOllivier Robert 1302875e59fSOllivier Robert# 1312875e59fSOllivier Robert# Should we use gmirror(8) to mirror the swap? 1322875e59fSOllivier Robert# 1332875e59fSOllivier Robert: ${ZFSBOOT_SWAP_MIRROR=} 1342875e59fSOllivier Robert 1352875e59fSOllivier Robert# 136bc4a673fSDevin Teske# Default ZFS datasets for root zpool 137cd88b886SDevin Teske# 138cd88b886SDevin Teske# NOTE: Requires /tmp, /var/tmp, /$ZFSBOOT_BOOTFS_NAME/$ZFSBOOT_BOOTFS_NAME 139cd88b886SDevin Teske# NOTE: Anything after pound/hash character [#] is ignored as a comment. 140cd88b886SDevin Teske# 141cd88b886SDevin Teskef_isset ZFSBOOT_DATASETS || ZFSBOOT_DATASETS=" 142cd88b886SDevin Teske # DATASET OPTIONS (comma or space separated; or both) 143cd88b886SDevin Teske 144cd88b886SDevin Teske # Boot Environment [BE] root and default boot dataset 145cd88b886SDevin Teske /$ZFSBOOT_BEROOT_NAME mountpoint=none 146dcf36219SAllan Jude /$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOTFS_NAME mountpoint=/ 147cd88b886SDevin Teske 148cd88b886SDevin Teske # Compress /tmp, allow exec but not setuid 149ed8690e3SOllivier Robert /tmp mountpoint=/tmp,exec=on,setuid=off 150cd88b886SDevin Teske 151cd88b886SDevin Teske # Don't mount /usr so that 'base' files go to the BEROOT 152cd88b886SDevin Teske /usr mountpoint=/usr,canmount=off 153cd88b886SDevin Teske 154cd88b886SDevin Teske # Home directories separated so they are common to all BEs 155bc4a673fSDevin Teske /usr/home # NB: /home is a symlink to /usr/home 156cd88b886SDevin Teske 157cd88b886SDevin Teske # Ports tree 158ed8690e3SOllivier Robert /usr/ports setuid=off 159cd88b886SDevin Teske 160cd88b886SDevin Teske # Source tree (compressed) 161ed8690e3SOllivier Robert /usr/src 162cd88b886SDevin Teske 163cd88b886SDevin Teske # Create /var and friends 1641aec0f4fSAllan Jude /var mountpoint=/var,canmount=off 1651bc08043SAllan Jude /var/audit exec=off,setuid=off 166ed8690e3SOllivier Robert /var/crash exec=off,setuid=off 167ed8690e3SOllivier Robert /var/log exec=off,setuid=off 168ed8690e3SOllivier Robert /var/mail atime=on 169ed8690e3SOllivier Robert /var/tmp setuid=off 170cd88b886SDevin Teske" # END-QUOTE 171cd88b886SDevin Teske 172bc4a673fSDevin Teske# 173bc4a673fSDevin Teske# If interactive and the user has not explicitly chosen a vdev type or disks, 174bc4a673fSDevin Teske# make the user confirm scripted/default choices when proceeding to install. 175bc4a673fSDevin Teske# 176bc4a673fSDevin Teske: ${ZFSBOOT_CONFIRM_LAYOUT:=1} 177bc4a673fSDevin Teske 178cd88b886SDevin Teske############################################################ GLOBALS 179cd88b886SDevin Teske 180cd88b886SDevin Teske# 181bc4a673fSDevin Teske# Format of a line in printf(1) syntax to add to fstab(5) 182bc4a673fSDevin Teske# 183bc4a673fSDevin TeskeFSTAB_FMT="%s\t\t%s\t%s\t%s\t\t%s\t%s\n" 184bc4a673fSDevin Teske 185bc4a673fSDevin Teske# 186bc4a673fSDevin Teske# Command strings for various tasks 187bc4a673fSDevin Teske# 188bc4a673fSDevin TeskeCHMOD_MODE='chmod %s "%s"' 189bc4a673fSDevin TeskeDD_WITH_OPTIONS='dd if="%s" of="%s" %s' 190bc4a673fSDevin TeskeECHO_APPEND='echo "%s" >> "%s"' 191bc4a673fSDevin TeskeGELI_ATTACH='geli attach -j - -k "%s" "%s"' 192a1b8f55cSAllan JudeGELI_ATTACH_NOKEY='geli attach -j - "%s"' 193a622223fSDevin TeskeGELI_DETACH_F='geli detach -f "%s"' 194bc4a673fSDevin TeskeGELI_PASSWORD_INIT='geli init -b -B "%s" -e %s -J - -K "%s" -l 256 -s 4096 "%s"' 195a1b8f55cSAllan JudeGELI_PASSWORD_GELIBOOT_INIT='geli init -bg -e %s -J - -l 256 -s 4096 "%s"' 19669e4b249SAllan JudeGPART_ADD_ALIGN='gpart add %s -t %s "%s"' 19769e4b249SAllan JudeGPART_ADD_ALIGN_INDEX='gpart add %s -i %s -t %s "%s"' 19869e4b249SAllan JudeGPART_ADD_ALIGN_INDEX_WITH_SIZE='gpart add %s -i %s -t %s -s %s "%s"' 19969e4b249SAllan JudeGPART_ADD_ALIGN_LABEL='gpart add %s -l %s -t %s "%s"' 20069e4b249SAllan JudeGPART_ADD_ALIGN_LABEL_WITH_SIZE='gpart add %s -l %s -t %s -s %s "%s"' 201bc4a673fSDevin TeskeGPART_BOOTCODE='gpart bootcode -b "%s" "%s"' 202bc4a673fSDevin TeskeGPART_BOOTCODE_PART='gpart bootcode -b "%s" -p "%s" -i %s "%s"' 2030edc8cc8SAllan JudeGPART_BOOTCODE_PARTONLY='gpart bootcode -p "%s" -i %s "%s"' 204bc4a673fSDevin TeskeGPART_CREATE='gpart create -s %s "%s"' 205a622223fSDevin TeskeGPART_DESTROY_F='gpart destroy -F "%s"' 206bc4a673fSDevin TeskeGPART_SET_ACTIVE='gpart set -a active -i %s "%s"' 2077059fa6fSAllan JudeGPART_SET_LENOVOFIX='gpart set -a lenovofix "%s"' 2087059fa6fSAllan JudeGPART_SET_PMBR_ACTIVE='gpart set -a active "%s"' 209a622223fSDevin TeskeGRAID_DELETE='graid delete "%s"' 210a1b8f55cSAllan JudeKLDLOAD='kldload %s' 211bc4a673fSDevin TeskeLN_SF='ln -sf "%s" "%s"' 212bc4a673fSDevin TeskeMKDIR_P='mkdir -p "%s"' 213bc4a673fSDevin TeskeMOUNT_TYPE='mount -t %s "%s" "%s"' 214bc4a673fSDevin TeskePRINTF_CONF="printf '%s=\"%%s\"\\\n' %s >> \"%s\"" 215bc4a673fSDevin TeskePRINTF_FSTAB='printf "$FSTAB_FMT" "%s" "%s" "%s" "%s" "%s" "%s" >> "%s"' 216bc4a673fSDevin TeskeSHELL_TRUNCATE=':> "%s"' 2172875e59fSOllivier RobertSWAP_GMIRROR_LABEL='gmirror label swap %s' 218b4843bd6SSteven HartlandSYSCTL_ZFS_MIN_ASHIFT_12='sysctl vfs.zfs.min_auto_ashift=12' 219a622223fSDevin TeskeUMOUNT='umount "%s"' 220bc4a673fSDevin TeskeZFS_CREATE_WITH_OPTIONS='zfs create %s "%s"' 221ca13d5d2SAllan JudeZFS_MOUNT='zfs mount "%s"' 222bc4a673fSDevin TeskeZFS_SET='zfs set "%s" "%s"' 223bc4a673fSDevin TeskeZFS_UNMOUNT='zfs unmount "%s"' 224bc4a673fSDevin TeskeZPOOL_CREATE_WITH_OPTIONS='zpool create %s "%s" %s %s' 225a88393ceSDevin TeskeZPOOL_DESTROY='zpool destroy "%s"' 226bc4a673fSDevin TeskeZPOOL_EXPORT='zpool export "%s"' 2271b63cafbSAllan JudeZPOOL_EXPORT_F='zpool export -f "%s"' 228bc4a673fSDevin TeskeZPOOL_IMPORT_WITH_OPTIONS='zpool import %s "%s"' 229a622223fSDevin TeskeZPOOL_LABELCLEAR_F='zpool labelclear -f "%s"' 230bc4a673fSDevin TeskeZPOOL_SET='zpool set %s "%s"' 231bc4a673fSDevin Teske 232bc4a673fSDevin Teske# 233cd88b886SDevin Teske# Strings that should be moved to an i18n file and loaded with f_include_lang() 234cd88b886SDevin Teske# 235cd88b886SDevin Teskehline_alnum_arrows_punc_tab_enter="Use alnum, arrows, punctuation, TAB or ENTER" 236cd88b886SDevin Teskehline_arrows_space_tab_enter="Use arrows, SPACE, TAB or ENTER" 237cd88b886SDevin Teskehline_arrows_tab_enter="Press arrows, TAB or ENTER" 238bc4a673fSDevin Teskemsg_an_unknown_error_occurred="An unknown error occurred" 239cd88b886SDevin Teskemsg_back="Back" 240cd88b886SDevin Teskemsg_cancel="Cancel" 241bc4a673fSDevin Teskemsg_change_selection="Change Selection" 242cd88b886SDevin Teskemsg_configure_options="Configure Options:" 243cd88b886SDevin 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" 244cd88b886SDevin Teskemsg_disk_info="Disk Info" 245cd88b886SDevin Teskemsg_disk_info_help="Get detailed information on disk device(s)" 246695a612fSOllivier Robertmsg_disk_singular="disk" 247695a612fSOllivier Robertmsg_disk_plural="disks" 248bc4a673fSDevin Teskemsg_encrypt_disks="Encrypt Disks?" 249bc4a673fSDevin Teskemsg_encrypt_disks_help="Use geli(8) to encrypt all data partitions" 250bc4a673fSDevin Teskemsg_error="Error" 251cd88b886SDevin Teskemsg_force_4k_sectors="Force 4K Sectors?" 25269e4b249SAllan Judemsg_force_4k_sectors_help="Align partitions to 4K sector boundries and set vfs.zfs.min_auto_ashift=12" 253cd88b886SDevin Teskemsg_freebsd_installer="FreeBSD Installer" 254cd88b886SDevin 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" 2557a434c5cSDevin Teskemsg_geli_setup="Initializing encryption on selected disks,\n this will take several seconds per disk" 256bc4a673fSDevin Teskemsg_install="Install" 257bc4a673fSDevin Teskemsg_install_desc="Proceed with Installation" 258bc4a673fSDevin Teskemsg_install_help="Create ZFS boot pool with displayed options" 2597cae6aabSDevin Teskemsg_invalid_boot_pool_size="Invalid boot pool size \`%s'" 260bc4a673fSDevin Teskemsg_invalid_disk_argument="Invalid disk argument \`%s'" 261bc4a673fSDevin Teskemsg_invalid_index_argument="Invalid index argument \`%s'" 262bc4a673fSDevin Teskemsg_invalid_swap_size="Invalid swap size \`%s'" 263cd88b886SDevin Teskemsg_invalid_virtual_device_type="Invalid Virtual Device type \`%s'" 264bc4a673fSDevin 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" 265bc4a673fSDevin 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' 266cd88b886SDevin Teskemsg_mirror_desc="Mirror - n-Way Mirroring" 267cd88b886SDevin Teskemsg_mirror_help="[2+ Disks] Mirroring provides the best performance, but the least storage" 268bc4a673fSDevin Teskemsg_missing_disk_arguments="missing disk arguments" 269bc4a673fSDevin Teskemsg_missing_one_or_more_scripted_disks="Missing one or more scripted disks!" 270cd88b886SDevin Teskemsg_no="NO" 271cd88b886SDevin Teskemsg_no_disks_present_to_configure="No disk(s) present to configure" 272cd88b886SDevin Teskemsg_no_disks_selected="No disks selected." 273bc4a673fSDevin Teskemsg_not_enough_disks_selected="Not enough disks selected. (%u < %u minimum)" 274bc4a673fSDevin Teskemsg_null_disk_argument="NULL disk argument" 275bc4a673fSDevin Teskemsg_null_index_argument="NULL index argument" 276bc4a673fSDevin Teskemsg_null_poolname="NULL poolname" 277bb4fd0a0SAllan Judemsg_odd_disk_selected="An even number of disks must be selected to create a RAID 1+0. (%u selected)" 278cd88b886SDevin Teskemsg_ok="OK" 279cd88b886SDevin Teskemsg_partition_scheme="Partition Scheme" 2807059fa6fSAllan Judemsg_partition_scheme_help="Select partitioning scheme. GPT is recommended." 281cd88b886SDevin Teskemsg_please_enter_a_name_for_your_zpool="Please enter a name for your zpool:" 282cd88b886SDevin Teskemsg_please_enter_amount_of_swap_space="Please enter amount of swap space (SI-Unit suffixes\nrecommended; e.g., \`2g' for 2 Gigabytes):" 283cd88b886SDevin Teskemsg_please_select_one_or_more_disks="Please select one or more disks to create a zpool:" 284cd88b886SDevin Teskemsg_pool_name="Pool Name" 285cd88b886SDevin Teskemsg_pool_name_cannot_be_empty="Pool name cannot be empty." 286cd88b886SDevin Teskemsg_pool_name_help="Customize the name of the zpool to be created (Required)" 287bc4a673fSDevin Teskemsg_pool_type_disks="Pool Type/Disks:" 288bc4a673fSDevin Teskemsg_pool_type_disks_help="Choose type of ZFS Virtual Device and disks to use (Required)" 289cd88b886SDevin Teskemsg_processing_selection="Processing selection..." 290bb4fd0a0SAllan Judemsg_raid10_desc="RAID 1+0 - n x 2-Way Mirrors" 291bb4fd0a0SAllan Judemsg_raid10_help="[4+ Disks] Striped Mirrors provides the best performance, but the least storage" 292cd88b886SDevin Teskemsg_raidz1_desc="RAID-Z1 - Single Redundant RAID" 293cd88b886SDevin Teskemsg_raidz1_help="[3+ Disks] Withstand failure of 1 disk. Recommended for: 3, 5 or 9 disks" 294cd88b886SDevin Teskemsg_raidz2_desc="RAID-Z2 - Double Redundant RAID" 295cd88b886SDevin Teskemsg_raidz2_help="[4+ Disks] Withstand failure of 2 disks. Recommended for: 4, 6 or 10 disks" 296cd88b886SDevin Teskemsg_raidz3_desc="RAID-Z3 - Triple Redundant RAID" 297cd88b886SDevin Teskemsg_raidz3_help="[5+ Disks] Withstand failure of 3 disks. Recommended for: 5, 7 or 11 disks" 298cd88b886SDevin Teskemsg_rescan_devices="Rescan Devices" 299cd88b886SDevin Teskemsg_rescan_devices_help="Scan for device changes" 300cd88b886SDevin Teskemsg_select="Select" 301cd88b886SDevin Teskemsg_select_a_disk_device="Select a disk device" 302cd88b886SDevin Teskemsg_select_virtual_device_type="Select Virtual Device type:" 303cd88b886SDevin Teskemsg_stripe_desc="Stripe - No Redundancy" 304cd88b886SDevin Teskemsg_stripe_help="[1+ Disks] Striping provides maximum storage but no redundancy" 3052875e59fSOllivier Robertmsg_swap_encrypt="Encrypt Swap?" 3062875e59fSOllivier Robertmsg_swap_encrypt_help="Encrypt swap partitions with temporary keys, discarded on reboot" 307169ff110SAllan Judemsg_swap_invalid="The selected swap size (%s) is invalid. Enter a number optionally followed by units. Example: 2G" 3082875e59fSOllivier Robertmsg_swap_mirror="Mirror Swap?" 3092875e59fSOllivier Robertmsg_swap_mirror_help="Mirror swap partitions for redundancy, breaks crash dumps" 310cd88b886SDevin Teskemsg_swap_size="Swap Size" 311cd88b886SDevin Teskemsg_swap_size_help="Customize how much swap space is allocated to each selected disk" 312169ff110SAllan Judemsg_swap_toosmall="The selected swap size (%s) is to small. Please enter a value greater than 100MB or enter 0 for no swap" 3136203e46bSAllan Judemsg_these_disks_are_too_small="These disks are smaller than the amount of requested\nswap (%s) and/or geli(8) (%s) partitions, which would\ntake 100%% or more of each of the following selected disks:\n\n %s\n\nRecommend changing partition size(s) and/or selecting a\ndifferent set of disks." 314bc4a673fSDevin Teskemsg_unable_to_get_disk_capacity="Unable to get disk capacity of \`%s'" 315bc4a673fSDevin Teskemsg_unsupported_partition_scheme="%s is an unsupported partition scheme" 316bc4a673fSDevin Teskemsg_user_cancelled="User Cancelled." 317cd88b886SDevin Teskemsg_yes="YES" 318cd88b886SDevin Teskemsg_zfs_configuration="ZFS Configuration" 319cd88b886SDevin Teske 320cd88b886SDevin Teske############################################################ FUNCTIONS 321cd88b886SDevin Teske 322cd88b886SDevin Teske# dialog_menu_main 323cd88b886SDevin Teske# 324cd88b886SDevin Teske# Display the dialog(1)-based application main menu. 325cd88b886SDevin Teske# 326cd88b886SDevin Teskedialog_menu_main() 327cd88b886SDevin Teske{ 328cd88b886SDevin Teske local title="$DIALOG_TITLE" 329cd88b886SDevin Teske local btitle="$DIALOG_BACKTITLE" 330cd88b886SDevin Teske local prompt="$msg_configure_options" 331cd88b886SDevin Teske local force4k="$msg_no" 332cd88b886SDevin Teske local usegeli="$msg_no" 3332875e59fSOllivier Robert local swapgeli="$msg_no" 3342875e59fSOllivier Robert local swapmirror="$msg_no" 335b4843bd6SSteven Hartland [ "$ZFSBOOT_FORCE_4K_SECTORS" ] && force4k="$msg_yes" 336cd88b886SDevin Teske [ "$ZFSBOOT_GELI_ENCRYPTION" ] && usegeli="$msg_yes" 3372875e59fSOllivier Robert [ "$ZFSBOOT_SWAP_ENCRYPTION" ] && swapgeli="$msg_yes" 3382875e59fSOllivier Robert [ "$ZFSBOOT_SWAP_MIRROR" ] && swapmirror="$msg_yes" 339695a612fSOllivier Robert local disks n disks_grammar 340a88393ceSDevin Teske f_count n $ZFSBOOT_DISKS 341695a612fSOllivier Robert { [ $n -eq 1 ] && disks_grammar=$msg_disk_singular; } || 342695a612fSOllivier Robert disks_grammar=$msg_disk_plural # grammar 343cd88b886SDevin Teske local menu_list=" 344bc4a673fSDevin Teske '>>> $msg_install' '$msg_install_desc' 345bc4a673fSDevin Teske '$msg_install_help' 34633112d9eSDevin Teske 'T $msg_pool_type_disks' 34733112d9eSDevin Teske '$ZFSBOOT_VDEV_TYPE: $n $disks_grammar' 348bc4a673fSDevin Teske '$msg_pool_type_disks_help' 349cd88b886SDevin Teske '- $msg_rescan_devices' '*' 350cd88b886SDevin Teske '$msg_rescan_devices_help' 351cd88b886SDevin Teske '- $msg_disk_info' '*' 352cd88b886SDevin Teske '$msg_disk_info_help' 353bc4a673fSDevin Teske 'N $msg_pool_name' '$ZFSBOOT_POOL_NAME' 354cd88b886SDevin Teske '$msg_pool_name_help' 35533112d9eSDevin Teske '4 $msg_force_4k_sectors' 35633112d9eSDevin Teske '$force4k' 357cd88b886SDevin Teske '$msg_force_4k_sectors_help' 358bc4a673fSDevin Teske 'E $msg_encrypt_disks' '$usegeli' 359bc4a673fSDevin Teske '$msg_encrypt_disks_help' 36033112d9eSDevin Teske 'P $msg_partition_scheme' 3610edc8cc8SAllan Jude '$ZFSBOOT_PARTITION_SCHEME ($ZFSBOOT_BOOT_TYPE)' 362cd88b886SDevin Teske '$msg_partition_scheme_help' 363bc4a673fSDevin Teske 'S $msg_swap_size' '$ZFSBOOT_SWAP_SIZE' 364cd88b886SDevin Teske '$msg_swap_size_help' 3652875e59fSOllivier Robert 'M $msg_swap_mirror' '$swapmirror' 3662875e59fSOllivier Robert '$msg_swap_mirror_help' 3672875e59fSOllivier Robert 'W $msg_swap_encrypt' '$swapgeli' 3682875e59fSOllivier Robert '$msg_swap_encrypt_help' 369cd88b886SDevin Teske " # END-QUOTE 370cd88b886SDevin Teske local defaultitem= # Calculated below 371cd88b886SDevin Teske local hline="$hline_alnum_arrows_punc_tab_enter" 372cd88b886SDevin Teske 373cd88b886SDevin Teske local height width rows 374cd88b886SDevin Teske eval f_dialog_menu_with_help_size height width rows \ 375cd88b886SDevin Teske \"\$title\" \"\$btitle\" \"\$prompt\" \"\$hline\" $menu_list 376cd88b886SDevin Teske 377cd88b886SDevin Teske # Obtain default-item from previously stored selection 378cd88b886SDevin Teske f_dialog_default_fetch defaultitem 379cd88b886SDevin Teske 380cd88b886SDevin Teske local menu_choice 381cd88b886SDevin Teske menu_choice=$( eval $DIALOG \ 382cd88b886SDevin Teske --title \"\$title\" \ 383cd88b886SDevin Teske --backtitle \"\$btitle\" \ 384cd88b886SDevin Teske --hline \"\$hline\" \ 385cd88b886SDevin Teske --item-help \ 386cd88b886SDevin Teske --ok-label \"\$msg_select\" \ 387cd88b886SDevin Teske --cancel-label \"\$msg_cancel\" \ 388cd88b886SDevin Teske --default-item \"\$defaultitem\" \ 389cd88b886SDevin Teske --menu \"\$prompt\" \ 390cd88b886SDevin Teske $height $width $rows \ 391cd88b886SDevin Teske $menu_list \ 392cd88b886SDevin Teske 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 393cd88b886SDevin Teske ) 394cd88b886SDevin Teske local retval=$? 395cd88b886SDevin Teske f_dialog_data_sanitize menu_choice 396cd88b886SDevin Teske f_dialog_menutag_store "$menu_choice" 397cd88b886SDevin Teske 398cd88b886SDevin Teske # Only update default-item on success 399cd88b886SDevin Teske [ $retval -eq $DIALOG_OK ] && f_dialog_default_store "$menu_choice" 400cd88b886SDevin Teske 401cd88b886SDevin Teske return $retval 402cd88b886SDevin Teske} 403cd88b886SDevin Teske 404bc4a673fSDevin Teske# dialog_last_chance $disks ... 405cd88b886SDevin Teske# 406bc4a673fSDevin Teske# Display a list of the disks that the user is about to destroy. The default 407bc4a673fSDevin Teske# action is to return error status unless the user explicitly (non-default) 408bc4a673fSDevin Teske# selects "Yes" from the noyes dialog. 409cd88b886SDevin Teske# 410bc4a673fSDevin Teskedialog_last_chance() 411cd88b886SDevin Teske{ 412cd88b886SDevin Teske local title="$DIALOG_TITLE" 413cd88b886SDevin Teske local btitle="$DIALOG_BACKTITLE" 414bc4a673fSDevin Teske local prompt # Calculated below 415bc4a673fSDevin Teske local hline="$hline_arrows_tab_enter" 416cd88b886SDevin Teske 417bc4a673fSDevin Teske local height=8 width=50 prefix=" " 418bc4a673fSDevin Teske local plen=${#prefix} list= line= 419bc4a673fSDevin Teske local max_width=$(( $width - 3 - $plen )) 420bc4a673fSDevin Teske 421bc4a673fSDevin Teske local yes no defaultno extra_args format 422bc4a673fSDevin Teske if [ "$USE_XDIALOG" ]; then 423bc4a673fSDevin Teske yes=ok no=cancel defaultno=default-no 424bc4a673fSDevin Teske extra_args="--wrap --left" 425bc4a673fSDevin Teske format="$msg_last_chance_are_you_sure" 426bc4a673fSDevin Teske else 427bc4a673fSDevin Teske yes=yes no=no defaultno=defaultno 428bc4a673fSDevin Teske extra_args="--colors --cr-wrap" 429bc4a673fSDevin Teske format="$msg_last_chance_are_you_sure_color" 430bc4a673fSDevin Teske fi 431bc4a673fSDevin Teske 432bc4a673fSDevin Teske local disk line_width 433bc4a673fSDevin Teske for disk in $*; do 434bc4a673fSDevin Teske if [ "$line" ]; then 435bc4a673fSDevin Teske line_width=${#line} 436bc4a673fSDevin Teske else 437bc4a673fSDevin Teske line_width=$plen 438bc4a673fSDevin Teske fi 439bc4a673fSDevin Teske line_width=$(( $line_width + 1 + ${#disk} )) 440bc4a673fSDevin Teske # Add newline before disk if it would exceed max_width 441bc4a673fSDevin Teske if [ $line_width -gt $max_width ]; then 442bc4a673fSDevin Teske list="$list$line\n" 443bc4a673fSDevin Teske line="$prefix" 444bc4a673fSDevin Teske height=$(( $height + 1 )) 445bc4a673fSDevin Teske fi 446bc4a673fSDevin Teske # Add the disk to the list 447bc4a673fSDevin Teske line="$line $disk" 448bc4a673fSDevin Teske done 449bc4a673fSDevin Teske # Append the left-overs 450bc4a673fSDevin Teske if [ "${line#$prefix}" ]; then 451bc4a673fSDevin Teske list="$list$line" 452bc4a673fSDevin Teske height=$(( $height + 1 )) 453bc4a673fSDevin Teske fi 454bc4a673fSDevin Teske 455bc4a673fSDevin Teske # Add height for Xdialog(1) 456bc4a673fSDevin Teske [ "$USE_XDIALOG" ] && height=$(( $height + $height / 5 + 3 )) 457bc4a673fSDevin Teske 458bc4a673fSDevin Teske prompt=$( printf "$format" "$list" ) 459bc4a673fSDevin Teske f_dprintf "%s: Last Chance!" "$0" 460bc4a673fSDevin Teske $DIALOG \ 461bc4a673fSDevin Teske --title "$title" \ 462bc4a673fSDevin Teske --backtitle "$btitle" \ 463bc4a673fSDevin Teske --hline "$hline" \ 464bc4a673fSDevin Teske --$defaultno \ 465bc4a673fSDevin Teske --$yes-label "$msg_yes" \ 466bc4a673fSDevin Teske --$no-label "$msg_no" \ 467bc4a673fSDevin Teske $extra_args \ 468bc4a673fSDevin Teske --yesno "$prompt" $height $width 469bc4a673fSDevin Teske} 470bc4a673fSDevin Teske 471bc4a673fSDevin Teske# dialog_menu_layout 472cd88b886SDevin Teske# 473bc4a673fSDevin Teske# Configure Virtual Device type and disks to use for the ZFS boot pool. User 474bc4a673fSDevin Teske# must select enough disks to satisfy the chosen vdev type. 475cd88b886SDevin Teske# 476bc4a673fSDevin Teskedialog_menu_layout() 477bc4a673fSDevin Teske{ 478bc4a673fSDevin Teske local funcname=dialog_menu_layout 479bc4a673fSDevin Teske local title="$DIALOG_TITLE" 480bc4a673fSDevin Teske local btitle="$DIALOG_BACKTITLE" 481bc4a673fSDevin Teske local vdev_prompt="$msg_select_virtual_device_type" 482bc4a673fSDevin Teske local disk_prompt="$msg_please_select_one_or_more_disks" 483bc4a673fSDevin Teske local vdev_menu_list=" 484bc4a673fSDevin Teske 'stripe' '$msg_stripe_desc' '$msg_stripe_help' 485bc4a673fSDevin Teske 'mirror' '$msg_mirror_desc' '$msg_mirror_help' 486bb4fd0a0SAllan Jude 'raid10' '$msg_raid10_desc' '$msg_raid10_help' 487bc4a673fSDevin Teske 'raidz1' '$msg_raidz1_desc' '$msg_raidz1_help' 488bc4a673fSDevin Teske 'raidz2' '$msg_raidz2_desc' '$msg_raidz2_help' 489bc4a673fSDevin Teske 'raidz3' '$msg_raidz3_desc' '$msg_raidz3_help' 490bc4a673fSDevin Teske " # END-QUOTE 491bc4a673fSDevin Teske local disk_check_list= # Calculated below 492bc4a673fSDevin Teske local vdev_hline="$hline_arrows_tab_enter" 493bc4a673fSDevin Teske local disk_hline="$hline_arrows_space_tab_enter" 494bc4a673fSDevin Teske 495bc4a673fSDevin Teske # Warn the user if vdev type is not valid 496bc4a673fSDevin Teske case "$ZFSBOOT_VDEV_TYPE" in 497bb4fd0a0SAllan Jude stripe|mirror|raid10|raidz1|raidz2|raidz3) : known good ;; 498bc4a673fSDevin Teske *) 499bc4a673fSDevin Teske f_dprintf "%s: Invalid virtual device type \`%s'" \ 500bc4a673fSDevin Teske $funcname "$ZFSBOOT_VDEV_TYPE" 501bc4a673fSDevin Teske f_show_err "$msg_invalid_virtual_device_type" \ 502bc4a673fSDevin Teske "$ZFSBOOT_VDEV_TYPE" 503bc4a673fSDevin Teske f_interactive || return $FAILURE 504bc4a673fSDevin Teske esac 505bc4a673fSDevin Teske 506bc4a673fSDevin Teske # Calculate size of vdev menu once only 507bc4a673fSDevin Teske local vheight vwidth vrows 508bc4a673fSDevin Teske eval f_dialog_menu_with_help_size vheight vwidth vrows \ 509bc4a673fSDevin Teske \"\$title\" \"\$btitle\" \"\$vdev_prompt\" \"\$vdev_hline\" \ 510bc4a673fSDevin Teske $vdev_menu_list 511bc4a673fSDevin Teske 512bc4a673fSDevin Teske # Get a list of probed disk devices 513bc4a673fSDevin Teske local disks= 514a88393ceSDevin Teske debug= f_device_find "" $DEVICE_TYPE_DISK disks 515a88393ceSDevin Teske 516a88393ceSDevin Teske # Prune out mounted md(4) devices that may be part of the boot process 517a88393ceSDevin Teske local disk name new_list= 518a88393ceSDevin Teske for disk in $disks; do 519a88393ceSDevin Teske debug= $disk get name name 520a88393ceSDevin Teske case "$name" in 521a88393ceSDevin Teske md[0-9]*) f_mounted -b "/dev/$name" && continue ;; 522a88393ceSDevin Teske esac 523a88393ceSDevin Teske new_list="$new_list $disk" 524a88393ceSDevin Teske done 525a88393ceSDevin Teske disks="${new_list# }" 526a88393ceSDevin Teske 527a88393ceSDevin Teske # Debugging 528a88393ceSDevin Teske if [ "$debug" ]; then 529a88393ceSDevin Teske local disk_names= 530a88393ceSDevin Teske for disk in $disks; do 531a88393ceSDevin Teske debug= $disk get name name 532a88393ceSDevin Teske disk_names="$disk_names $name" 533a88393ceSDevin Teske done 534a88393ceSDevin Teske f_dprintf "$funcname: disks=[%s]" "${disk_names# }" 535a88393ceSDevin Teske fi 536a88393ceSDevin Teske 537cd88b886SDevin Teske if [ ! "$disks" ]; then 538bc4a673fSDevin Teske f_dprintf "No disk(s) present to configure" 539bc4a673fSDevin Teske f_show_err "$msg_no_disks_present_to_configure" 540cd88b886SDevin Teske return $FAILURE 541cd88b886SDevin Teske fi 542cd88b886SDevin Teske 543cd88b886SDevin Teske # Lets sort the disks array to be more user friendly 544a88393ceSDevin Teske f_device_sort_by name disks disks 545cd88b886SDevin Teske 546cd88b886SDevin Teske # 547bc4a673fSDevin Teske # Operate in a loop so we can (if interactive) repeat if not enough 548bc4a673fSDevin Teske # disks are selected to satisfy the chosen vdev type or user wants to 549bc4a673fSDevin Teske # back-up to the previous menu. 550cd88b886SDevin Teske # 551a88393ceSDevin Teske local vardisk ndisks onoff selections vdev_choice breakout device 552a88393ceSDevin Teske local valid_disks all_valid want_disks desc height width rows 553bc4a673fSDevin Teske while :; do 554cd88b886SDevin Teske # 555bc4a673fSDevin Teske # Confirm the vdev type that was selected 556cd88b886SDevin Teske # 557bc4a673fSDevin Teske if f_interactive && [ "$ZFSBOOT_CONFIRM_LAYOUT" ]; then 558bc4a673fSDevin Teske vdev_choice=$( eval $DIALOG \ 559cd88b886SDevin Teske --title \"\$title\" \ 560cd88b886SDevin Teske --backtitle \"\$btitle\" \ 561bc4a673fSDevin Teske --hline \"\$vdev_hline\" \ 562cd88b886SDevin Teske --ok-label \"\$msg_ok\" \ 563cd88b886SDevin Teske --cancel-label \"\$msg_cancel\" \ 564cd88b886SDevin Teske --item-help \ 565bc4a673fSDevin Teske --default-item \"\$ZFSBOOT_VDEV_TYPE\" \ 566bc4a673fSDevin Teske --menu \"\$vdev_prompt\" \ 567bc4a673fSDevin Teske $vheight $vwidth $vrows \ 568bc4a673fSDevin Teske $vdev_menu_list \ 569cd88b886SDevin Teske 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 570bc4a673fSDevin Teske ) || return $? 571bc4a673fSDevin Teske # Exit if user pressed ESC or chose Cancel/No 572bc4a673fSDevin Teske f_dialog_data_sanitize vdev_choice 573cd88b886SDevin Teske 574bc4a673fSDevin Teske ZFSBOOT_VDEV_TYPE="$vdev_choice" 575bc4a673fSDevin Teske f_dprintf "$funcname: ZFSBOOT_VDEV_TYPE=[%s]" \ 576bc4a673fSDevin Teske "$ZFSBOOT_VDEV_TYPE" 577bc4a673fSDevin Teske fi 578bc4a673fSDevin Teske 579bc4a673fSDevin Teske # Determine the number of disks needed for this vdev type 580a88393ceSDevin Teske want_disks=0 581bc4a673fSDevin Teske case "$ZFSBOOT_VDEV_TYPE" in 582cd88b886SDevin Teske stripe) want_disks=1 ;; 583cd88b886SDevin Teske mirror) want_disks=2 ;; 584bb4fd0a0SAllan Jude raid10) want_disks=4 ;; 585cd88b886SDevin Teske raidz1) want_disks=3 ;; 586cd88b886SDevin Teske raidz2) want_disks=4 ;; 587cd88b886SDevin Teske raidz3) want_disks=5 ;; 588cd88b886SDevin Teske esac 589bc4a673fSDevin Teske 590a88393ceSDevin Teske # 591bc4a673fSDevin Teske # Warn the user if any scripted disks are invalid 592a88393ceSDevin Teske # 593a88393ceSDevin Teske valid_disks= all_valid=${ZFSBOOT_DISKS:+1} # optimism 594bc4a673fSDevin Teske for disk in $ZFSBOOT_DISKS; do 595a88393ceSDevin Teske if debug= f_device_find -1 \ 596a88393ceSDevin Teske $disk $DEVICE_TYPE_DISK device 597a88393ceSDevin Teske then 598bc4a673fSDevin Teske valid_disks="$valid_disks $disk" 599bc4a673fSDevin Teske continue 600cd88b886SDevin Teske fi 601bc4a673fSDevin Teske f_dprintf "$funcname: \`%s' is not a real disk" "$disk" 602bc4a673fSDevin Teske all_valid= 603bc4a673fSDevin Teske done 604bc4a673fSDevin Teske if [ ! "$all_valid" ]; then 605bc4a673fSDevin Teske if [ "$ZFSBOOT_DISKS" ]; then 606bc4a673fSDevin Teske f_show_err \ 607bc4a673fSDevin Teske "$msg_missing_one_or_more_scripted_disks" 608bc4a673fSDevin Teske else 609bc4a673fSDevin Teske f_dprintf "No disks selected." 610bc4a673fSDevin Teske f_interactive || 611bc4a673fSDevin Teske f_show_err "$msg_no_disks_selected" 612bc4a673fSDevin Teske fi 613bc4a673fSDevin Teske f_interactive || return $FAILURE 614bc4a673fSDevin Teske fi 615bc4a673fSDevin Teske ZFSBOOT_DISKS="${valid_disks# }" 616bc4a673fSDevin Teske 617bc4a673fSDevin Teske # 618bc4a673fSDevin Teske # Short-circuit if we're running non-interactively 619bc4a673fSDevin Teske # 620bc4a673fSDevin Teske if ! f_interactive || [ ! "$ZFSBOOT_CONFIRM_LAYOUT" ]; then 621a88393ceSDevin Teske f_count ndisks $ZFSBOOT_DISKS 622bc4a673fSDevin Teske [ $ndisks -ge $want_disks ] && break # to success 623bc4a673fSDevin Teske 624bc4a673fSDevin Teske # Not enough disks selected 625bc4a673fSDevin Teske f_dprintf "$funcname: %s: %s (%u < %u minimum)" \ 626bc4a673fSDevin Teske "$ZFSBOOT_VDEV_TYPE" \ 627bc4a673fSDevin Teske "Not enough disks selected." \ 628bc4a673fSDevin Teske $ndisks $want_disks 629bc4a673fSDevin Teske f_interactive || return $FAILURE 630bc4a673fSDevin Teske msg_yes="$msg_change_selection" msg_no="$msg_cancel" \ 631bc4a673fSDevin Teske f_yesno "%s: $msg_not_enough_disks_selected" \ 632bc4a673fSDevin Teske "$ZFSBOOT_VDEV_TYPE" $ndisks $want_disks || 633bc4a673fSDevin Teske return $FAILURE 634bc4a673fSDevin Teske fi 635bc4a673fSDevin Teske 636bc4a673fSDevin Teske # 637bc4a673fSDevin Teske # Confirm the disks that were selected 638bc4a673fSDevin Teske # Loop until the user cancels or selects enough disks 639bc4a673fSDevin Teske # 640a88393ceSDevin Teske breakout= 641bc4a673fSDevin Teske while :; do 642bc4a673fSDevin Teske # Loop over list of available disks, resetting state 643a88393ceSDevin Teske for disk in $disks; do 644a88393ceSDevin Teske f_isset _${disk}_status && _${disk}_status= 645a88393ceSDevin Teske done 646bc4a673fSDevin Teske 647bc4a673fSDevin Teske # Loop over list of selected disks and create temporary 648bc4a673fSDevin Teske # locals to map statuses onto up-to-date list of disks 649bc4a673fSDevin Teske for disk in $ZFSBOOT_DISKS; do 650a88393ceSDevin Teske debug= f_device_find -1 \ 651a88393ceSDevin Teske $disk $DEVICE_TYPE_DISK disk 652a88393ceSDevin Teske f_isset _${disk}_status || 653a88393ceSDevin Teske local _${disk}_status 654a88393ceSDevin Teske _${disk}_status=on 655bc4a673fSDevin Teske done 656bc4a673fSDevin Teske 657bc4a673fSDevin Teske # Create the checklist menu of discovered disk devices 658bc4a673fSDevin Teske disk_check_list= 659bc4a673fSDevin Teske for disk in $disks; do 660a88393ceSDevin Teske desc= 661a88393ceSDevin Teske $disk get name name 662a88393ceSDevin Teske $disk get desc desc 663bc4a673fSDevin Teske f_shell_escape "$desc" desc 664bc4a673fSDevin Teske f_getvar _${disk}_status:-off onoff 665bc4a673fSDevin Teske disk_check_list="$disk_check_list 666a88393ceSDevin Teske $name '$desc' $onoff" 667bc4a673fSDevin Teske done 668bc4a673fSDevin Teske 669bc4a673fSDevin Teske eval f_dialog_checklist_size height width rows \ 670bc4a673fSDevin Teske \"\$title\" \"\$btitle\" \"\$prompt\" \ 671bc4a673fSDevin Teske \"\$hline\" $disk_check_list 672bc4a673fSDevin Teske 673bc4a673fSDevin Teske selections=$( eval $DIALOG \ 674bc4a673fSDevin Teske --title \"\$DIALOG_TITLE\" \ 675bc4a673fSDevin Teske --backtitle \"\$DIALOG_BACKTITLE\" \ 676751952aeSDevin Teske --separate-output \ 677bc4a673fSDevin Teske --hline \"\$hline\" \ 678bc4a673fSDevin Teske --ok-label \"\$msg_ok\" \ 679bc4a673fSDevin Teske --cancel-label \"\$msg_back\" \ 680bc4a673fSDevin Teske --checklist \"\$prompt\" \ 681bc4a673fSDevin Teske $height $width $rows \ 682bc4a673fSDevin Teske $disk_check_list \ 683bc4a673fSDevin Teske 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 684bc4a673fSDevin Teske ) || break 685bc4a673fSDevin Teske # Loop if user pressed ESC or chose Cancel/No 686bc4a673fSDevin Teske f_dialog_data_sanitize selections 687bc4a673fSDevin Teske 688bc4a673fSDevin Teske ZFSBOOT_DISKS="$selections" 689bc4a673fSDevin Teske f_dprintf "$funcname: ZFSBOOT_DISKS=[%s]" \ 690bc4a673fSDevin Teske "$ZFSBOOT_DISKS" 691bc4a673fSDevin Teske 692a88393ceSDevin Teske f_count ndisks $ZFSBOOT_DISKS 693bb4fd0a0SAllan Jude 694bb4fd0a0SAllan Jude if [ "$ZFSBOOT_VDEV_TYPE" == "raid10" ] && 695bb4fd0a0SAllan Jude [ $(( $ndisks % 2 )) -ne 0 ]; then 696bb4fd0a0SAllan Jude f_dprintf "$funcname: %s: %s (%u %% 2 = %u)" \ 697bb4fd0a0SAllan Jude "$ZFSBOOT_VDEV_TYPE" \ 698bb4fd0a0SAllan Jude "Number of disks not even:" \ 699bb4fd0a0SAllan Jude $ndisks $(( $ndisks % 2 )) 700bb4fd0a0SAllan Jude msg_yes="$msg_change_selection" \ 701bb4fd0a0SAllan Jude msg_no="$msg_cancel" \ 702bb4fd0a0SAllan Jude f_yesno "%s: $msg_odd_disk_selected" \ 703bb4fd0a0SAllan Jude "$ZFSBOOT_VDEV_TYPE" $ndisks || 704bb4fd0a0SAllan Jude break 705bb4fd0a0SAllan Jude continue 706bb4fd0a0SAllan Jude fi 707bb4fd0a0SAllan Jude 708bc4a673fSDevin Teske [ $ndisks -ge $want_disks ] && 709bc4a673fSDevin Teske breakout=break && break 710bc4a673fSDevin Teske 711bc4a673fSDevin Teske # Not enough disks selected 712bc4a673fSDevin Teske f_dprintf "$funcname: %s: %s (%u < %u minimum)" \ 713bc4a673fSDevin Teske "$ZFSBOOT_VDEV_TYPE" \ 714bc4a673fSDevin Teske "Not enough disks selected." \ 715bc4a673fSDevin Teske $ndisks $want_disks 716bc4a673fSDevin Teske msg_yes="$msg_change_selection" msg_no="$msg_cancel" \ 717bc4a673fSDevin Teske f_yesno "%s: $msg_not_enough_disks_selected" \ 718bc4a673fSDevin Teske "$ZFSBOOT_VDEV_TYPE" $ndisks $want_disks || 719bc4a673fSDevin Teske break 720bc4a673fSDevin Teske done 721bc4a673fSDevin Teske [ "$breakout" = "break" ] && break 722bc4a673fSDevin Teske [ "$ZFSBOOT_CONFIRM_LAYOUT" ] || return $FAILURE 723bc4a673fSDevin Teske done 724bc4a673fSDevin Teske 725bc4a673fSDevin Teske return $DIALOG_OK 726cd88b886SDevin Teske} 727cd88b886SDevin Teske 728cd88b886SDevin Teske# zfs_create_diskpart $disk $index 729cd88b886SDevin Teske# 730cd88b886SDevin Teske# For each block device to be used in the zpool, rather than just create the 731cd88b886SDevin Teske# zpool with the raw block devices (e.g., da0, da1, etc.) we create partitions 732cd88b886SDevin Teske# so we can have some real swap. This also provides wiggle room incase your 733cd88b886SDevin Teske# replacement drivers do not have the exact same sector counts. 734cd88b886SDevin Teske# 7357cae6aabSDevin Teske# NOTE: $swapsize and $bootsize should be defined by the calling function. 736a622223fSDevin Teske# NOTE: Sets $bootpart and $targetpart for the calling function. 737cd88b886SDevin Teske# 738cd88b886SDevin Teskezfs_create_diskpart() 739cd88b886SDevin Teske{ 740cd88b886SDevin Teske local funcname=zfs_create_diskpart 741bc4a673fSDevin Teske local disk="$1" index="$2" 742cd88b886SDevin Teske 743cd88b886SDevin Teske # Check arguments 744bc4a673fSDevin Teske if [ ! "$disk" ]; then 745bc4a673fSDevin Teske f_dprintf "$funcname: NULL disk argument" 746bc4a673fSDevin Teske msg_error="$msg_error: $funcname" \ 747bc4a673fSDevin Teske f_show_err "$msg_null_disk_argument" 748bc4a673fSDevin Teske return $FAILURE 749bc4a673fSDevin Teske fi 750bc4a673fSDevin Teske if [ "${disk#*[$IFS]}" != "$disk" ]; then 751bc4a673fSDevin Teske f_dprintf "$funcname: Invalid disk argument \`%s'" "$disk" 752bc4a673fSDevin Teske msg_error="$msg_error: $funcname" \ 753bc4a673fSDevin Teske f_show_err "$msg_invalid_disk_argument" "$disk" 754bc4a673fSDevin Teske return $FAILURE 755bc4a673fSDevin Teske fi 756bc4a673fSDevin Teske if [ ! "$index" ]; then 757bc4a673fSDevin Teske f_dprintf "$funcname: NULL index argument" 758bc4a673fSDevin Teske msg_error="$msg_error: $funcname" \ 759bc4a673fSDevin Teske f_show_err "$msg_null_index_argument" 760bc4a673fSDevin Teske return $FAILURE 761bc4a673fSDevin Teske fi 762bc4a673fSDevin Teske if ! f_isinteger "$index"; then 763bc4a673fSDevin Teske f_dprintf "$funcname: Invalid index argument \`%s'" "$index" 764bc4a673fSDevin Teske msg_error="$msg_error: $funcname" \ 765bc4a673fSDevin Teske f_show_err "$msg_invalid_index_argument" "$index" 766bc4a673fSDevin Teske return $FAILURE 767bc4a673fSDevin Teske fi 768bc4a673fSDevin Teske f_dprintf "$funcname: disk=[%s] index=[%s]" "$disk" "$index" 769cd88b886SDevin Teske 770d4d729e4SDevin Teske # Check for unknown partition scheme before proceeding further 771d4d729e4SDevin Teske case "$ZFSBOOT_PARTITION_SCHEME" in 7727059fa6fSAllan Jude ""|MBR|GPT*) : known good ;; 773d4d729e4SDevin Teske *) 774d4d729e4SDevin Teske f_dprintf "$funcname: %s is an unsupported partition scheme" \ 775d4d729e4SDevin Teske "$ZFSBOOT_PARTITION_SCHEME" 776d4d729e4SDevin Teske msg_error="$msg_error: $funcname" f_show_err \ 777d4d729e4SDevin Teske "$msg_unsupported_partition_scheme" \ 778d4d729e4SDevin Teske "$ZFSBOOT_PARTITION_SCHEME" 779d4d729e4SDevin Teske return $FAILURE 780d4d729e4SDevin Teske esac 781d4d729e4SDevin Teske 782cd88b886SDevin Teske # 783cd88b886SDevin Teske # Destroy whatever partition layout is currently on disk. 784cd88b886SDevin Teske # NOTE: `-F' required to destroy if partitions still exist. 785cd88b886SDevin Teske # NOTE: Failure is ok here, blank disk will have nothing to destroy. 786cd88b886SDevin Teske # 7871b63cafbSAllan Jude f_dprintf "$funcname: Exporting ZFS pools..." 7881b63cafbSAllan Jude zpool list -Ho name | while read z_name; do 7891b63cafbSAllan Jude f_eval_catch -d $funcname zpool "$ZPOOL_EXPORT_F" $z_name 7901b63cafbSAllan Jude done 7911b63cafbSAllan Jude f_dprintf "$funcname: Detaching all GELI providers..." 7921b63cafbSAllan Jude geli status | tail -n +2 | while read g_name g_status g_component; do 7931b63cafbSAllan Jude f_eval_catch -d $funcname geli "$GELI_DETACH_F" $g_name 7941b63cafbSAllan Jude done 795bc4a673fSDevin Teske f_dprintf "$funcname: Destroying all data/layouts on \`%s'..." "$disk" 796a622223fSDevin Teske f_eval_catch -d $funcname gpart "$GPART_DESTROY_F" $disk 797a622223fSDevin Teske f_eval_catch -d $funcname graid "$GRAID_DELETE" $disk 798a622223fSDevin Teske f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" /dev/$disk 799cd88b886SDevin Teske 800cd88b886SDevin Teske # Make doubly-sure backup GPT is destroyed 801a622223fSDevin Teske f_eval_catch -d $funcname gpart "$GPART_CREATE" gpt $disk 802a622223fSDevin Teske f_eval_catch -d $funcname gpart "$GPART_DESTROY_F" $disk 803cd88b886SDevin Teske 8047cae6aabSDevin Teske # 805cd88b886SDevin Teske # Lay down the desired type of partition scheme 806cd88b886SDevin Teske # 80769e4b249SAllan Jude local setsize mbrindex align_small align_big 80869e4b249SAllan Jude # 80969e4b249SAllan Jude # If user has requested 4 K alignment, add these params to the 81069e4b249SAllan Jude # gpart add calls. With GPT, we align large partitions to 1 M for 81169e4b249SAllan Jude # improved performance on SSDs. MBR does not always play well with gaps 81269e4b249SAllan Jude # between partitions, so all alignment is only 4k for that case. 81369e4b249SAllan Jude # With MBR, we align the BSD partition that contains the MBR, otherwise 81469e4b249SAllan Jude # the system fails to boot. 81569e4b249SAllan Jude # 81669e4b249SAllan Jude if [ "$ZFSBOOT_FORCE_4K_SECTORS" ]; then 81769e4b249SAllan Jude align_small="-a 4k" 81869e4b249SAllan Jude align_big="-a 1m" 81969e4b249SAllan Jude fi 82069e4b249SAllan Jude 821cd88b886SDevin Teske case "$ZFSBOOT_PARTITION_SCHEME" in 8227059fa6fSAllan Jude ""|GPT*) f_dprintf "$funcname: Creating GPT layout..." 823cd88b886SDevin Teske # 824cd88b886SDevin Teske # 1. Create GPT layout using labels 825cd88b886SDevin Teske # 826a622223fSDevin Teske f_eval_catch $funcname gpart "$GPART_CREATE" gpt $disk || 827bc4a673fSDevin Teske return $FAILURE 828cd88b886SDevin Teske 829cd88b886SDevin Teske # 8307059fa6fSAllan Jude # Apply workarounds if requested by the user 8317059fa6fSAllan Jude # 8327059fa6fSAllan Jude if [ "$ZFSBOOT_PARTITION_SCHEME" = "GPT + Lenovo Fix" ]; then 8337059fa6fSAllan Jude f_eval_catch $funcname gpart "$GPART_SET_LENOVOFIX" \ 8347059fa6fSAllan Jude $disk || return $FAILURE 8357059fa6fSAllan Jude elif [ "$ZFSBOOT_PARTITION_SCHEME" = "GPT + Active" ]; then 8367059fa6fSAllan Jude f_eval_catch $funcname gpart "$GPART_SET_PMBR_ACTIVE" \ 8377059fa6fSAllan Jude $disk || return $FAILURE 8387059fa6fSAllan Jude fi 8397059fa6fSAllan Jude 8407059fa6fSAllan Jude # 841a1b8f55cSAllan Jude # 2. Add small freebsd-boot and/or efi partition 842cd88b886SDevin Teske # 8434d41f472SAllan Jude if [ "$ZFSBOOT_BOOT_TYPE" = "UEFI" -o "$ZFSBOOT_BOOT_TYPE" = "BIOS+UEFI" ]; then 844a1b8f55cSAllan Jude # 845a1b8f55cSAllan Jude # Enable boot pool if encryption is desired 846a1b8f55cSAllan Jude # 847a1b8f55cSAllan Jude [ "$ZFSBOOT_GELI_ENCRYPTION" ] && ZFSBOOT_BOOT_POOL=1 848a1b8f55cSAllan Jude 8490edc8cc8SAllan Jude f_eval_catch $funcname gpart \ 8500edc8cc8SAllan Jude "$GPART_ADD_ALIGN_LABEL_WITH_SIZE" \ 8510edc8cc8SAllan Jude "$align_small" efiboot$index efi 800k $disk || 852cd88b886SDevin Teske return $FAILURE 8530edc8cc8SAllan Jude f_eval_catch $funcname gpart "$GPART_BOOTCODE_PARTONLY" \ 8540edc8cc8SAllan Jude /boot/boot1.efifat 1 $disk || 8550edc8cc8SAllan Jude return $FAILURE 8564d41f472SAllan Jude fi 8574d41f472SAllan Jude 8584d41f472SAllan Jude if [ "$ZFSBOOT_BOOT_TYPE" = "BIOS" -o "$ZFSBOOT_BOOT_TYPE" = "BIOS+UEFI" ]; then 8590edc8cc8SAllan Jude f_eval_catch $funcname gpart \ 8600edc8cc8SAllan Jude "$GPART_ADD_ALIGN_LABEL_WITH_SIZE" \ 8610edc8cc8SAllan Jude "$align_small" gptboot$index freebsd-boot \ 8620edc8cc8SAllan Jude 512k $disk || return $FAILURE 8634d41f472SAllan Jude if [ "$ZFSBOOT_BOOT_TYPE" = "BIOS" ]; then 864bc4a673fSDevin Teske f_eval_catch $funcname gpart "$GPART_BOOTCODE_PART" \ 865a622223fSDevin Teske /boot/pmbr /boot/gptzfsboot 1 $disk || 866cd88b886SDevin Teske return $FAILURE 8674d41f472SAllan Jude else 8684d41f472SAllan Jude f_eval_catch $funcname gpart "$GPART_BOOTCODE_PART" \ 8694d41f472SAllan Jude /boot/pmbr /boot/gptzfsboot 2 $disk || 8704d41f472SAllan Jude return $FAILURE 8714d41f472SAllan Jude fi 8720edc8cc8SAllan Jude fi 873cd88b886SDevin Teske 874a622223fSDevin Teske # NB: zpool will use the `zfs#' GPT labels 8754d41f472SAllan Jude if [ "$ZFSBOOT_BOOT_TYPE" = "BIOS+UEFI" ]; then 8764d41f472SAllan Jude if [ "$ZFSBOOT_BOOT_POOL" ]; then 8774d41f472SAllan Jude bootpart=p3 swappart=p4 targetpart=p4 8784d41f472SAllan Jude [ ${swapsize:-0} -gt 0 ] && targetpart=p5 8794d41f472SAllan Jude else 8804d41f472SAllan Jude # Bootpart unused 8814d41f472SAllan Jude bootpart=p3 swappart=p3 targetpart=p3 8824d41f472SAllan Jude [ ${swapsize:-0} -gt 0 ] && targetpart=p4 8834d41f472SAllan Jude fi 8844d41f472SAllan Jude else 8854d41f472SAllan Jude if [ "$ZFSBOOT_BOOT_POOL" ]; then 8864d41f472SAllan Jude bootpart=p2 swappart=p3 targetpart=p3 8874d41f472SAllan Jude [ ${swapsize:-0} -gt 0 ] && targetpart=p4 8884d41f472SAllan Jude else 8894d41f472SAllan Jude # Bootpart unused 8902875e59fSOllivier Robert bootpart=p2 swappart=p2 targetpart=p2 8917cae6aabSDevin Teske [ ${swapsize:-0} -gt 0 ] && targetpart=p3 8924d41f472SAllan Jude fi 8934d41f472SAllan Jude fi 894cd88b886SDevin Teske 8957cae6aabSDevin Teske # 8967cae6aabSDevin Teske # Prepare boot pool if enabled (e.g., for geli(8)) 8977cae6aabSDevin Teske # 8987cae6aabSDevin Teske if [ "$ZFSBOOT_BOOT_POOL" ]; then 899bc4a673fSDevin Teske f_eval_catch $funcname gpart \ 90069e4b249SAllan Jude "$GPART_ADD_ALIGN_LABEL_WITH_SIZE" \ 90169e4b249SAllan Jude "$align_big" boot$index freebsd-zfs \ 90269e4b249SAllan Jude ${bootsize}b $disk || 903bc4a673fSDevin Teske return $FAILURE 9047cae6aabSDevin Teske # Pedantically nuke any old labels 905a622223fSDevin Teske f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 906a622223fSDevin Teske /dev/$disk$bootpart 9077cae6aabSDevin Teske if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then 9087cae6aabSDevin Teske # Pedantically detach targetpart for later 9097cae6aabSDevin Teske f_eval_catch -d $funcname geli \ 9107cae6aabSDevin Teske "$GELI_DETACH_F" \ 911a622223fSDevin Teske /dev/$disk$targetpart 912cd88b886SDevin Teske fi 9137cae6aabSDevin Teske fi 914cd88b886SDevin Teske 915cd88b886SDevin Teske # 9167cae6aabSDevin Teske # 3. Add freebsd-swap partition labeled `swap#' 917cd88b886SDevin Teske # 918bc4a673fSDevin Teske if [ ${swapsize:-0} -gt 0 ]; then 919bc4a673fSDevin Teske f_eval_catch $funcname gpart \ 92069e4b249SAllan Jude "$GPART_ADD_ALIGN_LABEL_WITH_SIZE" \ 92169e4b249SAllan Jude "$align_big" swap$index freebsd-swap \ 92269e4b249SAllan Jude ${swapsize}b $disk || 923cd88b886SDevin Teske return $FAILURE 924cf9c3e56SDevin Teske # Pedantically nuke any old labels on the swap 925cf9c3e56SDevin Teske f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 9262875e59fSOllivier Robert /dev/$disk$swappart 927cd88b886SDevin Teske fi 9287cae6aabSDevin Teske 9297cae6aabSDevin Teske # 9307cae6aabSDevin Teske # 4. Add freebsd-zfs partition labeled `zfs#' for zroot 9317cae6aabSDevin Teske # 93269e4b249SAllan Jude f_eval_catch $funcname gpart "$GPART_ADD_ALIGN_LABEL" \ 93369e4b249SAllan Jude "$align_big" zfs$index freebsd-zfs $disk || 93469e4b249SAllan Jude return $FAILURE 9357cae6aabSDevin Teske f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 9367cae6aabSDevin Teske /dev/$disk$targetpart 937cd88b886SDevin Teske ;; 938cd88b886SDevin Teske 939bc4a673fSDevin Teske MBR) f_dprintf "$funcname: Creating MBR layout..." 940cd88b886SDevin Teske # 941a1b8f55cSAllan Jude # Enable boot pool if encryption is desired 942a1b8f55cSAllan Jude # 943a1b8f55cSAllan Jude [ "$ZFSBOOT_GELI_ENCRYPTION" ] && ZFSBOOT_BOOT_POOL=1 944a1b8f55cSAllan Jude # 945cd88b886SDevin Teske # 1. Create MBR layout (no labels) 946cd88b886SDevin Teske # 947a622223fSDevin Teske f_eval_catch $funcname gpart "$GPART_CREATE" mbr $disk || 948bc4a673fSDevin Teske return $FAILURE 9492925848dSDevin Teske f_eval_catch $funcname gpart "$GPART_BOOTCODE" /boot/mbr \ 950a622223fSDevin Teske $disk || return $FAILURE 951cd88b886SDevin Teske 952cd88b886SDevin Teske # 953cd88b886SDevin Teske # 2. Add freebsd slice with all available space 954cd88b886SDevin Teske # 95569e4b249SAllan Jude f_eval_catch $funcname gpart "$GPART_ADD_ALIGN" "$align_small" \ 95669e4b249SAllan Jude freebsd $disk || 957bc4a673fSDevin Teske return $FAILURE 958a622223fSDevin Teske f_eval_catch $funcname gpart "$GPART_SET_ACTIVE" 1 $disk || 959bc4a673fSDevin Teske return $FAILURE 960a622223fSDevin Teske # Pedantically nuke any old labels 961a622223fSDevin Teske f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 962a622223fSDevin Teske /dev/${disk}s1 963a622223fSDevin Teske # Pedantically nuke any old scheme 964a622223fSDevin Teske f_eval_catch -d $funcname gpart "$GPART_DESTROY_F" ${disk}s1 965cd88b886SDevin Teske 966cd88b886SDevin Teske # 967bc4a673fSDevin Teske # 3. Write BSD scheme to the freebsd slice 968cd88b886SDevin Teske # 969a622223fSDevin Teske f_eval_catch $funcname gpart "$GPART_CREATE" BSD ${disk}s1 || 970bc4a673fSDevin Teske return $FAILURE 971cd88b886SDevin Teske 9727cae6aabSDevin Teske # NB: zpool will use s1a (no labels) 9732875e59fSOllivier Robert bootpart=s1a swappart=s1b targetpart=s1d mbrindex=4 974cd88b886SDevin Teske 9757cae6aabSDevin Teske # 9767cae6aabSDevin Teske # Always prepare a boot pool on MBR 977a94af954SAllan Jude # Do not align this partition, there must not be a gap 9787cae6aabSDevin Teske # 9797cae6aabSDevin Teske ZFSBOOT_BOOT_POOL=1 980bc4a673fSDevin Teske f_eval_catch $funcname gpart \ 98169e4b249SAllan Jude "$GPART_ADD_ALIGN_INDEX_WITH_SIZE" \ 982a94af954SAllan Jude "" 1 freebsd-zfs ${bootsize}b ${disk}s1 || 983bc4a673fSDevin Teske return $FAILURE 984a622223fSDevin Teske # Pedantically nuke any old labels 985a622223fSDevin Teske f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 986a622223fSDevin Teske /dev/$disk$bootpart 9877cae6aabSDevin Teske if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then 988a622223fSDevin Teske # Pedantically detach targetpart for later 989a622223fSDevin Teske f_eval_catch -d $funcname geli \ 990a622223fSDevin Teske "$GELI_DETACH_F" \ 991a622223fSDevin Teske /dev/$disk$targetpart 992cd88b886SDevin Teske fi 993cd88b886SDevin Teske 994cd88b886SDevin Teske # 9957cae6aabSDevin Teske # 4. Add freebsd-swap partition 996cd88b886SDevin Teske # 997bc4a673fSDevin Teske if [ ${swapsize:-0} -gt 0 ]; then 998bc4a673fSDevin Teske f_eval_catch $funcname gpart \ 99969e4b249SAllan Jude "$GPART_ADD_ALIGN_INDEX_WITH_SIZE" \ 100069e4b249SAllan Jude "$align_small" 2 freebsd-swap ${swapsize}b ${disk}s1 || 1001cd88b886SDevin Teske return $FAILURE 1002cf9c3e56SDevin Teske # Pedantically nuke any old labels on the swap 1003cf9c3e56SDevin Teske f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 1004cf9c3e56SDevin Teske /dev/${disk}s1b 1005cd88b886SDevin Teske fi 10067cae6aabSDevin Teske 10077cae6aabSDevin Teske # 10087cae6aabSDevin Teske # 5. Add freebsd-zfs partition for zroot 10097cae6aabSDevin Teske # 101069e4b249SAllan Jude f_eval_catch $funcname gpart "$GPART_ADD_ALIGN_INDEX" \ 101169e4b249SAllan Jude "$align_small" $mbrindex freebsd-zfs ${disk}s1 || return $FAILURE 10127cae6aabSDevin Teske f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 10137cae6aabSDevin Teske /dev/$disk$targetpart # Pedantic 10147cae6aabSDevin Teske f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \ 10157cae6aabSDevin Teske /boot/zfsboot /dev/${disk}s1 count=1 || 10167cae6aabSDevin Teske return $FAILURE 1017cd88b886SDevin Teske ;; 1018cd88b886SDevin Teske 1019cd88b886SDevin Teske esac # $ZFSBOOT_PARTITION_SCHEME 1020cd88b886SDevin Teske 10212875e59fSOllivier Robert # Update fstab(5) 1022caa3817dSAllan Jude local swapsize 1023caa3817dSAllan Jude f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize 10242875e59fSOllivier Robert if [ "$isswapmirror" ]; then 10252875e59fSOllivier Robert # This is not the first disk in the mirror, do nothing 10266b5e33baSAllan Jude elif [ ${swapsize:-0} -eq 0 ]; then 10276b5e33baSAllan Jude # If swap is 0 sized, don't add it to fstab 10282875e59fSOllivier Robert elif [ "$ZFSBOOT_SWAP_ENCRYPTION" -a "$ZFSBOOT_SWAP_MIRROR" ]; then 10292875e59fSOllivier Robert f_eval_catch $funcname printf "$PRINTF_FSTAB" \ 10302875e59fSOllivier Robert /dev/mirror/swap.eli none swap sw 0 0 \ 10312875e59fSOllivier Robert $BSDINSTALL_TMPETC/fstab || 10322875e59fSOllivier Robert return $FAILURE 10332875e59fSOllivier Robert isswapmirror=1 10342875e59fSOllivier Robert elif [ "$ZFSBOOT_SWAP_MIRROR" ]; then 10352875e59fSOllivier Robert f_eval_catch $funcname printf "$PRINTF_FSTAB" \ 10362875e59fSOllivier Robert /dev/mirror/swap none swap sw 0 0 \ 10372875e59fSOllivier Robert $BSDINSTALL_TMPETC/fstab || 10382875e59fSOllivier Robert return $FAILURE 10392875e59fSOllivier Robert isswapmirror=1 10402875e59fSOllivier Robert elif [ "$ZFSBOOT_SWAP_ENCRYPTION" ]; then 10412875e59fSOllivier Robert f_eval_catch $funcname printf "$PRINTF_FSTAB" \ 10422875e59fSOllivier Robert /dev/$disk${swappart}.eli none swap sw 0 0 \ 10432875e59fSOllivier Robert $BSDINSTALL_TMPETC/fstab || 10442875e59fSOllivier Robert return $FAILURE 10452875e59fSOllivier Robert else 10462875e59fSOllivier Robert f_eval_catch $funcname printf "$PRINTF_FSTAB" \ 10472875e59fSOllivier Robert /dev/$disk$swappart none swap sw 0 0 \ 10482875e59fSOllivier Robert $BSDINSTALL_TMPETC/fstab || 10492875e59fSOllivier Robert return $FAILURE 10502875e59fSOllivier Robert fi 10512875e59fSOllivier Robert 1052cd88b886SDevin Teske return $SUCCESS 1053cd88b886SDevin Teske} 1054cd88b886SDevin Teske 1055bc4a673fSDevin Teske# zfs_create_boot $poolname $vdev_type $disks ... 1056cd88b886SDevin Teske# 1057cd88b886SDevin Teske# Creates boot pool and dataset layout. Returns error if something goes wrong. 1058cd88b886SDevin Teske# Errors are printed to stderr for collection and display. 1059cd88b886SDevin Teske# 1060cd88b886SDevin Teskezfs_create_boot() 1061cd88b886SDevin Teske{ 1062cd88b886SDevin Teske local funcname=zfs_create_boot 10637cae6aabSDevin Teske local zroot_name="$1" 10647cae6aabSDevin Teske local zroot_vdevtype="$2" 10657cae6aabSDevin Teske local zroot_vdevs= # Calculated below 10662875e59fSOllivier Robert local swap_devs= # Calculated below 10677cae6aabSDevin Teske local boot_vdevs= # Used for geli(8) and/or MBR layouts 1068a622223fSDevin Teske shift 2 # poolname vdev_type 1069a622223fSDevin Teske local disks="$*" disk 10702875e59fSOllivier Robert local isswapmirror 10712875e59fSOllivier Robert local bootpart targetpart swappart # Set by zfs_create_diskpart() below 107247206692SDevin Teske local create_options 1073cd88b886SDevin Teske 1074a622223fSDevin Teske # 1075cd88b886SDevin Teske # Pedantic checks; should never be seen 1076a622223fSDevin Teske # 10777cae6aabSDevin Teske if [ ! "$zroot_name" ]; then 1078bc4a673fSDevin Teske f_dprintf "$funcname: NULL poolname" 1079bc4a673fSDevin Teske msg_error="$msg_error: $funcname" \ 1080bc4a673fSDevin Teske f_show_err "$msg_null_poolname" 1081cd88b886SDevin Teske return $FAILURE 1082cd88b886SDevin Teske fi 1083cd88b886SDevin Teske if [ $# -lt 1 ]; then 1084bc4a673fSDevin Teske f_dprintf "$funcname: missing disk arguments" 1085bc4a673fSDevin Teske msg_error="$msg_error: $funcname" \ 1086bc4a673fSDevin Teske f_show_err "$msg_missing_disk_arguments" 1087cd88b886SDevin Teske return $FAILURE 1088cd88b886SDevin Teske fi 1089bc4a673fSDevin Teske f_dprintf "$funcname: poolname=[%s] vdev_type=[%s]" \ 10907cae6aabSDevin Teske "$zroot_name" "$zroot_vdevtype" 1091cd88b886SDevin Teske 1092a622223fSDevin Teske # 1093cd88b886SDevin Teske # Initialize fstab(5) 1094a622223fSDevin Teske # 1095bc4a673fSDevin Teske f_dprintf "$funcname: Initializing temporary fstab(5) file..." 1096a622223fSDevin Teske f_eval_catch $funcname sh "$SHELL_TRUNCATE" $BSDINSTALL_TMPETC/fstab || 1097bc4a673fSDevin Teske return $FAILURE 1098bc4a673fSDevin Teske f_eval_catch $funcname printf "$PRINTF_FSTAB" \ 1099cd88b886SDevin Teske "# Device" Mountpoint FStype Options Dump "Pass#" \ 1100a622223fSDevin Teske $BSDINSTALL_TMPETC/fstab || return $FAILURE 1101cd88b886SDevin Teske 1102a622223fSDevin Teske # 1103cd88b886SDevin Teske # Expand SI units in desired sizes 1104a622223fSDevin Teske # 11057cae6aabSDevin Teske f_dprintf "$funcname: Expanding supplied size values..." 11067cae6aabSDevin Teske local swapsize bootsize 1107bc4a673fSDevin Teske if ! f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize; then 1108bc4a673fSDevin Teske f_dprintf "$funcname: Invalid swap size \`%s'" \ 1109bc4a673fSDevin Teske "$ZFSBOOT_SWAP_SIZE" 1110bc4a673fSDevin Teske f_show_err "$msg_invalid_swap_size" "$ZFSBOOT_SWAP_SIZE" 1111bc4a673fSDevin Teske return $FAILURE 1112bc4a673fSDevin Teske fi 11137cae6aabSDevin Teske if ! f_expand_number "$ZFSBOOT_BOOT_POOL_SIZE" bootsize; then 11147cae6aabSDevin Teske f_dprintf "$funcname: Invalid boot pool size \`%s'" \ 11157cae6aabSDevin Teske "$ZFSBOOT_BOOT_POOL_SIZE" 11167cae6aabSDevin Teske f_show_err "$msg_invalid_boot_pool_size" \ 11177cae6aabSDevin Teske "$ZFSBOOT_BOOT_POOL_SIZE" 1118bc4a673fSDevin Teske return $FAILURE 1119bc4a673fSDevin Teske fi 1120bc4a673fSDevin Teske f_dprintf "$funcname: ZFSBOOT_SWAP_SIZE=[%s] swapsize=[%s]" \ 1121bc4a673fSDevin Teske "$ZFSBOOT_SWAP_SIZE" "$swapsize" 11227cae6aabSDevin Teske f_dprintf "$funcname: ZFSBOOT_BOOT_POOL_SIZE=[%s] bootsize=[%s]" \ 11237cae6aabSDevin Teske "$ZFSBOOT_BOOT_POOL_SIZE" "$bootsize" 1124cd88b886SDevin Teske 1125a622223fSDevin Teske # 1126a88393ceSDevin Teske # Destroy the pool in-case this is our second time 'round (case of 1127a88393ceSDevin Teske # failure and installer presented ``Retry'' option to come back). 1128a88393ceSDevin Teske # 1129a88393ceSDevin Teske # NB: If we don't destroy the pool, later gpart(8) destroy commands 1130a88393ceSDevin Teske # that try to clear existing partitions (see zfs_create_diskpart()) 1131a88393ceSDevin Teske # will fail with a `Device Busy' error, leading to `GEOM exists'. 1132a88393ceSDevin Teske # 1133a88393ceSDevin Teske f_eval_catch -d $funcname zpool "$ZPOOL_DESTROY" "$zroot_name" 1134a88393ceSDevin Teske 1135a88393ceSDevin Teske # 11367cae6aabSDevin Teske # Prepare the disks and build pool device list(s) 1137a622223fSDevin Teske # 1138bc4a673fSDevin Teske f_dprintf "$funcname: Preparing disk partitions for ZFS pool..." 1139b4843bd6SSteven Hartland 1140b4843bd6SSteven Hartland # Force 4K sectors using vfs.zfs.min_auto_ashift=12 1141b4843bd6SSteven Hartland if [ "$ZFSBOOT_FORCE_4K_SECTORS" ]; then 1142b4843bd6SSteven Hartland f_dprintf "$funcname: With 4K sectors..." 1143b4843bd6SSteven Hartland f_eval_catch $funcname sysctl "$SYSCTL_ZFS_MIN_ASHIFT_12" \ 1144b4843bd6SSteven Hartland || return $FAILURE 114524d17f1eSAllan Jude sysctl kern.geom.part.mbr.enforce_chs=0 1146b4843bd6SSteven Hartland fi 1147cd88b886SDevin Teske local n=0 1148a622223fSDevin Teske for disk in $disks; do 1149cd88b886SDevin Teske zfs_create_diskpart $disk $n || return $FAILURE 11502875e59fSOllivier Robert # Now $bootpart, $targetpart, and $swappart are set (suffix 11512875e59fSOllivier Robert # for $disk) 11527cae6aabSDevin Teske if [ "$ZFSBOOT_BOOT_POOL" ]; then 11537cae6aabSDevin Teske boot_vdevs="$boot_vdevs $disk$bootpart" 11547cae6aabSDevin Teske fi 11557cae6aabSDevin Teske zroot_vdevs="$zroot_vdevs $disk$targetpart" 1156e751d176SSteven Hartland if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then 1157e751d176SSteven Hartland zroot_vdevs="$zroot_vdevs.eli" 1158e751d176SSteven Hartland fi 11597cae6aabSDevin Teske 11607cae6aabSDevin Teske n=$(( $n + 1 )) 11617cae6aabSDevin Teske done # disks 11627cae6aabSDevin Teske 11637cae6aabSDevin Teske # 11647cae6aabSDevin Teske # If we need/want a boot pool, create it 11657cae6aabSDevin Teske # 11667cae6aabSDevin Teske if [ "$ZFSBOOT_BOOT_POOL" ]; then 11677cae6aabSDevin Teske local bootpool_vdevtype= # Calculated below 11687cae6aabSDevin Teske local bootpool_options= # Calculated below 11697cae6aabSDevin Teske local bootpool_name="$ZFSBOOT_BOOT_POOL_NAME" 11707cae6aabSDevin Teske local bootpool="$BSDINSTALL_CHROOT/$bootpool_name" 11717cae6aabSDevin Teske local zroot_key="${ZFSBOOT_GELI_KEY_FILE#/}" 11727cae6aabSDevin Teske 11737cae6aabSDevin Teske f_dprintf "$funcname: Setting up boot pool..." 1174cd88b886SDevin Teske [ "$ZFSBOOT_GELI_ENCRYPTION" ] && 11757cae6aabSDevin Teske f_dprintf "$funcname: For encrypted root disk..." 1176cd88b886SDevin Teske 11777cae6aabSDevin Teske # Create parent directory for boot pool 1178a622223fSDevin Teske f_eval_catch -d $funcname umount "$UMOUNT" /mnt 1179bc4a673fSDevin Teske f_eval_catch $funcname mount "$MOUNT_TYPE" tmpfs none \ 1180a622223fSDevin Teske $BSDINSTALL_CHROOT || return $FAILURE 1181cd88b886SDevin Teske 11827cae6aabSDevin Teske # Create mirror across the boot partition on all disks 1183a88393ceSDevin Teske local nvdevs 1184a88393ceSDevin Teske f_count nvdevs $boot_vdevs 1185a88393ceSDevin Teske [ $nvdevs -gt 1 ] && bootpool_vdevtype=mirror 1186cd88b886SDevin Teske 118747206692SDevin Teske create_options="$ZFSBOOT_BOOT_POOL_CREATE_OPTIONS" 11887cae6aabSDevin Teske bootpool_options="-o altroot=$BSDINSTALL_CHROOT" 118947206692SDevin Teske bootpool_options="$bootpool_options $create_options" 11907cae6aabSDevin Teske bootpool_options="$bootpool_options -m \"/$bootpool_name\" -f" 1191bc4a673fSDevin Teske f_eval_catch $funcname zpool "$ZPOOL_CREATE_WITH_OPTIONS" \ 11927cae6aabSDevin Teske "$bootpool_options" "$bootpool_name" \ 11934b4b90d5SDevin Teske "$bootpool_vdevtype" "$boot_vdevs" || 11944b4b90d5SDevin Teske return $FAILURE 119545df402eSDevin Teske 11967cae6aabSDevin Teske f_eval_catch $funcname mkdir "$MKDIR_P" "$bootpool/boot" || 1197cd88b886SDevin Teske return $FAILURE 1198cd88b886SDevin Teske 11997cae6aabSDevin Teske if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then 1200cd88b886SDevin Teske # Generate an encryption key using random(4) 1201bc4a673fSDevin Teske f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \ 12027cae6aabSDevin Teske /dev/random "$bootpool/$zroot_key" \ 12037cae6aabSDevin Teske "bs=4096 count=1" || return $FAILURE 12041ebd9bd4SDevin Teske f_eval_catch $funcname chmod "$CHMOD_MODE" \ 12054ef40262SDevin Teske go-wrx "$bootpool/$zroot_key" || 12064ef40262SDevin Teske return $FAILURE 12077cae6aabSDevin Teske fi 12087cae6aabSDevin Teske 12097cae6aabSDevin Teske fi 1210cd88b886SDevin Teske 1211a622223fSDevin Teske # 1212cd88b886SDevin Teske # Create the geli(8) GEOMS 1213a622223fSDevin Teske # 12147cae6aabSDevin Teske if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then 1215a1b8f55cSAllan Jude # 1216a1b8f55cSAllan Jude # Load the AES-NI kernel module to accelerate encryption 1217a1b8f55cSAllan Jude # 1218a1b8f55cSAllan Jude f_eval_catch -d $funcname kldload "$KLDLOAD" "aesni" 12197cae6aabSDevin Teske # Prompt user for password (twice) 1220bc4a673fSDevin Teske if ! msg_enter_new_password="$msg_geli_password" \ 1221bc4a673fSDevin Teske f_dialog_input_password 1222bc4a673fSDevin Teske then 1223bc4a673fSDevin Teske f_dprintf "$funcname: User cancelled" 1224bc4a673fSDevin Teske f_show_err "$msg_user_cancelled" 1225bc4a673fSDevin Teske return $FAILURE 1226bc4a673fSDevin Teske fi 1227a622223fSDevin Teske 1228a622223fSDevin Teske # Initialize geli(8) on each of the target partitions 1229bc4a673fSDevin Teske for disk in $disks; do 1230cd88b886SDevin Teske f_dialog_info "$msg_geli_setup" \ 1231cd88b886SDevin Teske 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 1232a1b8f55cSAllan Jude if [ "$ZFSBOOT_BOOT_POOL" ]; then 1233a622223fSDevin Teske if ! echo "$pw_password" | f_eval_catch \ 1234a622223fSDevin Teske $funcname geli "$GELI_PASSWORD_INIT" \ 12357cae6aabSDevin Teske "$bootpool/boot/$disk$targetpart.eli" \ 12367cae6aabSDevin Teske AES-XTS "$bootpool/$zroot_key" \ 1237a622223fSDevin Teske $disk$targetpart 1238bc4a673fSDevin Teske then 1239bc4a673fSDevin Teske f_interactive || f_die 1240a622223fSDevin Teske unset pw_password # Sensitive info 1241cd88b886SDevin Teske return $FAILURE 1242bc4a673fSDevin Teske fi 1243a622223fSDevin Teske if ! echo "$pw_password" | f_eval_catch \ 1244a622223fSDevin Teske $funcname geli "$GELI_ATTACH" \ 12457cae6aabSDevin Teske "$bootpool/$zroot_key" $disk$targetpart 1246bc4a673fSDevin Teske then 1247bc4a673fSDevin Teske f_interactive || f_die 1248a622223fSDevin Teske unset pw_password # Sensitive info 1249bc4a673fSDevin Teske return $FAILURE 1250bc4a673fSDevin Teske fi 1251a1b8f55cSAllan Jude else 1252a1b8f55cSAllan Jude # With no bootpool, there is no place to store 1253a1b8f55cSAllan Jude # the key files, use only a password 1254a1b8f55cSAllan Jude if ! echo "$pw_password" | f_eval_catch \ 1255a1b8f55cSAllan Jude $funcname geli \ 1256a1b8f55cSAllan Jude "$GELI_PASSWORD_GELIBOOT_INIT" AES-XTS \ 1257a1b8f55cSAllan Jude $disk$targetpart 1258a1b8f55cSAllan Jude then 1259a1b8f55cSAllan Jude f_interactive || f_die 1260a1b8f55cSAllan Jude unset pw_password # Sensitive info 1261a1b8f55cSAllan Jude return $FAILURE 1262a1b8f55cSAllan Jude fi 1263a1b8f55cSAllan Jude if ! echo "$pw_password" | f_eval_catch \ 1264a1b8f55cSAllan Jude $funcname geli "$GELI_ATTACH_NOKEY" \ 1265a1b8f55cSAllan Jude $disk$targetpart 1266a1b8f55cSAllan Jude then 1267a1b8f55cSAllan Jude f_interactive || f_die 1268a1b8f55cSAllan Jude unset pw_password # Sensitive info 1269a1b8f55cSAllan Jude return $FAILURE 1270a1b8f55cSAllan Jude fi 1271a1b8f55cSAllan Jude fi 1272cd88b886SDevin Teske done 1273a622223fSDevin Teske unset pw_password # Sensitive info 1274a1b8f55cSAllan Jude fi 1275a622223fSDevin Teske 1276a1b8f55cSAllan Jude if [ "$ZFSBOOT_BOOT_POOL" ]; then 1277a622223fSDevin Teske # Clean up 12787cae6aabSDevin Teske f_eval_catch $funcname zfs "$ZFS_UNMOUNT" "$bootpool_name" || 12797cae6aabSDevin Teske return $FAILURE 1280a622223fSDevin Teske f_eval_catch -d $funcname umount "$UMOUNT" /mnt # tmpfs 1281cd88b886SDevin Teske fi 128233112d9eSDevin Teske 12832875e59fSOllivier Robert # 12842875e59fSOllivier Robert # Create the gmirror(8) GEOMS for swap 12852875e59fSOllivier Robert # 128606445fc0SAllan Jude if [ ${swapsize:-0} -gt 0 -a "$ZFSBOOT_SWAP_MIRROR" ]; then 12872875e59fSOllivier Robert for disk in $disks; do 12882875e59fSOllivier Robert swap_devs="$swap_devs $disk$swappart" 12892875e59fSOllivier Robert done 12902875e59fSOllivier Robert f_eval_catch $funcname gmirror "$SWAP_GMIRROR_LABEL" \ 12912875e59fSOllivier Robert "$swap_devs" || return $FAILURE 12922875e59fSOllivier Robert fi 1293cd88b886SDevin Teske 1294cd88b886SDevin Teske # 1295a622223fSDevin Teske # Create the ZFS root pool with desired type and disk devices 1296cd88b886SDevin Teske # 12977cae6aabSDevin Teske f_dprintf "$funcname: Creating root pool..." 129847206692SDevin Teske create_options="$ZFSBOOT_POOL_CREATE_OPTIONS" 1299bb4fd0a0SAllan Jude if [ "$zroot_vdevtype" == "raid10" ]; then 1300bb4fd0a0SAllan Jude raid10_vdevs="" 1301bb4fd0a0SAllan Jude for vdev in $zroot_vdevs; do 1302bb4fd0a0SAllan Jude f_count nvdev $raid10_vdevs 1303bb4fd0a0SAllan Jude if [ $(( $nvdev % 3 )) -eq 0 ]; then 1304bb4fd0a0SAllan Jude raid10_vdevs="$raid10_vdevs mirror" 1305bb4fd0a0SAllan Jude fi 1306bb4fd0a0SAllan Jude raid10_vdevs="$raid10_vdevs $vdev" 1307bb4fd0a0SAllan Jude done 1308bb4fd0a0SAllan Jude f_eval_catch $funcname zpool "$ZPOOL_CREATE_WITH_OPTIONS" \ 1309bb4fd0a0SAllan Jude "-o altroot=$BSDINSTALL_CHROOT $create_options -m none -f" \ 1310bb4fd0a0SAllan Jude "$zroot_name" "" "$raid10_vdevs" || 1311bb4fd0a0SAllan Jude return $FAILURE 1312bb4fd0a0SAllan Jude else 1313bc4a673fSDevin Teske f_eval_catch $funcname zpool "$ZPOOL_CREATE_WITH_OPTIONS" \ 131447206692SDevin Teske "-o altroot=$BSDINSTALL_CHROOT $create_options -m none -f" \ 13154b4b90d5SDevin Teske "$zroot_name" "$zroot_vdevtype" "$zroot_vdevs" || 13164b4b90d5SDevin Teske return $FAILURE 1317bb4fd0a0SAllan Jude fi 1318cd88b886SDevin Teske 1319cd88b886SDevin Teske # 13207cae6aabSDevin Teske # Create ZFS dataset layout within the new root pool 1321cd88b886SDevin Teske # 1322bc4a673fSDevin Teske f_dprintf "$funcname: Creating ZFS datasets..." 1323cd88b886SDevin Teske echo "$ZFSBOOT_DATASETS" | while read dataset options; do 1324cd88b886SDevin Teske # Skip blank lines and comments 1325cd88b886SDevin Teske case "$dataset" in "#"*|"") continue; esac 1326cd88b886SDevin Teske # Remove potential inline comments in options 1327cd88b886SDevin Teske options="${options%%#*}" 1328cd88b886SDevin Teske # Replace tabs with spaces 1329cd88b886SDevin Teske f_replaceall "$options" " " " " options 1330cd88b886SDevin Teske # Reduce contiguous runs of space to one single space 1331cd88b886SDevin Teske oldoptions= 1332cd88b886SDevin Teske while [ "$oldoptions" != "$options" ]; do 1333cd88b886SDevin Teske oldoptions="$options" 1334cd88b886SDevin Teske f_replaceall "$options" " " " " options 1335cd88b886SDevin Teske done 1336cd88b886SDevin Teske # Replace both commas and spaces with ` -o ' 1337cd88b886SDevin Teske f_replaceall "$options" "[ ,]" " -o " options 1338cd88b886SDevin Teske # Create the dataset with desired options 1339bc4a673fSDevin Teske f_eval_catch $funcname zfs "$ZFS_CREATE_WITH_OPTIONS" \ 13407cae6aabSDevin Teske "${options:+-o $options}" "$zroot_name$dataset" || 1341cd88b886SDevin Teske return $FAILURE 1342cd88b886SDevin Teske done 1343cd88b886SDevin Teske 13447e3ebc5bSAllan Jude # 13457e3ebc5bSAllan Jude # Set a mountpoint for the root of the pool so newly created datasets 13467e3ebc5bSAllan Jude # have a mountpoint to inherit 13477e3ebc5bSAllan Jude # 13487e3ebc5bSAllan Jude f_dprintf "$funcname: Setting mountpoint for root of the pool..." 13497e3ebc5bSAllan Jude f_eval_catch $funcname zfs "$ZFS_SET" \ 13507e3ebc5bSAllan Jude "mountpoint=/$zroot_name" "$zroot_name" || 13517e3ebc5bSAllan Jude return $FAILURE 13527e3ebc5bSAllan Jude 1353cd88b886SDevin Teske # Touch up permissions on the tmp directories 1354bc4a673fSDevin Teske f_dprintf "$funcname: Modifying directory permissions..." 1355bc4a673fSDevin Teske local dir 1356bc4a673fSDevin Teske for dir in /tmp /var/tmp; do 1357b3f7b139SAllan Jude f_eval_catch $funcname mkdir "$MKDIR_P" \ 1358b3f7b139SAllan Jude $BSDINSTALL_CHROOT$dir || return $FAILURE 1359bc4a673fSDevin Teske f_eval_catch $funcname chmod "$CHMOD_MODE" 1777 \ 13604ffa3da5SAllan Jude $BSDINSTALL_CHROOT$dir || return $FAILURE 1361bc4a673fSDevin Teske done 1362cd88b886SDevin Teske 1363cd88b886SDevin Teske # Set bootfs property 13647cae6aabSDevin Teske local zroot_bootfs="$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOTFS_NAME" 1365bc4a673fSDevin Teske f_dprintf "$funcname: Setting bootfs property..." 1366bc4a673fSDevin Teske f_eval_catch $funcname zpool "$ZPOOL_SET" \ 13677cae6aabSDevin Teske "bootfs=\"$zroot_name/$zroot_bootfs\"" "$zroot_name" || 13687cae6aabSDevin Teske return $FAILURE 1369cd88b886SDevin Teske 1370b06bc65eSAllan Jude # MBR boot loader touch-up 1371b06bc65eSAllan Jude if [ "$ZFSBOOT_PARTITION_SCHEME" = "MBR" ]; then 1372cd88b886SDevin Teske # Export the pool(s) 1373bc4a673fSDevin Teske f_dprintf "$funcname: Temporarily exporting ZFS pool(s)..." 13747cae6aabSDevin Teske f_eval_catch $funcname zpool "$ZPOOL_EXPORT" "$zroot_name" || 1375bc4a673fSDevin Teske return $FAILURE 13767cae6aabSDevin Teske if [ "$ZFSBOOT_BOOT_POOL" ]; then 1377bc4a673fSDevin Teske f_eval_catch $funcname zpool "$ZPOOL_EXPORT" \ 13787cae6aabSDevin Teske "$bootpool_name" || return $FAILURE 1379bc4a673fSDevin Teske fi 1380cd88b886SDevin Teske 1381bc4a673fSDevin Teske f_dprintf "$funcname: Updating MBR boot loader on disks..." 1382ec65e4f8SPedro F. Giffuni # Stick the ZFS boot loader in the "convenient hole" after 1383cd88b886SDevin Teske # the ZFS internal metadata 1384bc4a673fSDevin Teske for disk in $disks; do 1385bc4a673fSDevin Teske f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \ 1386a622223fSDevin Teske /boot/zfsboot /dev/$disk$bootpart \ 1387bc4a673fSDevin Teske "skip=1 seek=1024" || return $FAILURE 1388cd88b886SDevin Teske done 1389cd88b886SDevin Teske 1390cd88b886SDevin Teske # Re-import the ZFS pool(s) 1391bc4a673fSDevin Teske f_dprintf "$funcname: Re-importing ZFS pool(s)..." 1392bc4a673fSDevin Teske f_eval_catch $funcname zpool "$ZPOOL_IMPORT_WITH_OPTIONS" \ 13937cae6aabSDevin Teske "-o altroot=\"$BSDINSTALL_CHROOT\"" "$zroot_name" || 1394bc4a673fSDevin Teske return $FAILURE 13957cae6aabSDevin Teske if [ "$ZFSBOOT_BOOT_POOL" ]; then 13964487af02SAllan Jude # Import the bootpool, but do not mount it yet 1397bc4a673fSDevin Teske f_eval_catch $funcname zpool "$ZPOOL_IMPORT_WITH_OPTIONS" \ 13984487af02SAllan Jude "-o altroot=\"$BSDINSTALL_CHROOT\" -N" \ 13997cae6aabSDevin Teske "$bootpool_name" || return $FAILURE 1400bc4a673fSDevin Teske fi 1401b06bc65eSAllan Jude fi 1402cd88b886SDevin Teske 1403ca13d5d2SAllan Jude # Remount bootpool and create symlink(s) 1404ca13d5d2SAllan Jude if [ "$ZFSBOOT_BOOT_POOL" ]; then 1405ca13d5d2SAllan Jude f_eval_catch $funcname zfs "$ZFS_MOUNT" "$bootpool_name" || 1406ca13d5d2SAllan Jude return $FAILURE 1407ca13d5d2SAllan Jude f_dprintf "$funcname: Creating /boot symlink for boot pool..." 1408ca13d5d2SAllan Jude f_eval_catch $funcname ln "$LN_SF" "$bootpool_name/boot" \ 1409ca13d5d2SAllan Jude $BSDINSTALL_CHROOT/boot || return $FAILURE 1410ca13d5d2SAllan Jude fi 1411ca13d5d2SAllan Jude 1412ca13d5d2SAllan Jude # zpool.cache is required to mount more than one pool at boot time 14136311cc9eSDevin Teske f_dprintf "$funcname: Configuring zpool.cache for zroot..." 1414a622223fSDevin Teske f_eval_catch $funcname mkdir "$MKDIR_P" $BSDINSTALL_CHROOT/boot/zfs || 1415bc4a673fSDevin Teske return $FAILURE 1416bc4a673fSDevin Teske f_eval_catch $funcname zpool "$ZPOOL_SET" \ 1417a622223fSDevin Teske "cachefile=\"$BSDINSTALL_CHROOT/boot/zfs/zpool.cache\"" \ 14187cae6aabSDevin Teske "$zroot_name" || return $FAILURE 1419cd88b886SDevin Teske 142052fffe93SAllan Jude if [ "$ZFSBOOT_BOOT_POOL" ]; then 142152fffe93SAllan Jude f_eval_catch $funcname printf "$PRINTF_CONF" \ 142252fffe93SAllan Jude vfs.root.mountfrom "\"zfs:$zroot_name/$zroot_bootfs\"" \ 142352fffe93SAllan Jude $BSDINSTALL_TMPBOOT/loader.conf.root || return $FAILURE 142452fffe93SAllan Jude fi 1425b06bc65eSAllan Jude # 1426b06bc65eSAllan Jude # Set canmount=noauto so that the default Boot Environment (BE) does not 1427b06bc65eSAllan Jude # get mounted if a different BE is selected from the beastie menu 1428b06bc65eSAllan Jude # 1429b06bc65eSAllan Jude f_dprintf "$funcname: Set canmount=noauto for the root of the pool..." 1430b06bc65eSAllan Jude f_eval_catch $funcname zfs "$ZFS_SET" "canmount=noauto" \ 1431b06bc65eSAllan Jude "$zroot_name/$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOTFS_NAME" 1432b06bc65eSAllan Jude 143313d8e1ceSDevin Teske # Last, but not least... required lines for rc.conf(5)/loader.conf(5) 1434cd88b886SDevin Teske # NOTE: We later concatenate these into their destination 1435bc4a673fSDevin Teske f_dprintf "%s: Configuring rc.conf(5)/loader.conf(5) additions..." \ 1436bc4a673fSDevin Teske "$funcname" 1437bc4a673fSDevin Teske f_eval_catch $funcname echo "$ECHO_APPEND" 'zfs_enable=\"YES\"' \ 1438a622223fSDevin Teske $BSDINSTALL_TMPETC/rc.conf.zfs || return $FAILURE 1439ee482f2cSDevin Teske f_eval_catch $funcname echo "$ECHO_APPEND" \ 1440ee482f2cSDevin Teske 'kern.geom.label.disk_ident.enable=\"0\"' \ 1441ee482f2cSDevin Teske $BSDINSTALL_TMPBOOT/loader.conf.zfs || return $FAILURE 14422875e59fSOllivier Robert f_eval_catch $funcname echo "$ECHO_APPEND" \ 14432875e59fSOllivier Robert 'kern.geom.label.gptid.enable=\"0\"' \ 14442875e59fSOllivier Robert $BSDINSTALL_TMPBOOT/loader.conf.zfs || return $FAILURE 14452875e59fSOllivier Robert 1446*46c380e6SAllan Jude if [ "$ZFSBOOT_FORCE_4K_SECTORS" ]; then 1447*46c380e6SAllan Jude f_eval_catch $funcname echo "$ECHO_APPEND" \ 1448*46c380e6SAllan Jude 'vfs.zfs.min_auto_ashift=12' \ 1449*46c380e6SAllan Jude $BSDINSTALL_TMPBOOT/loader.conf.zfs || return $FAILURE 1450*46c380e6SAllan Jude fi 1451*46c380e6SAllan Jude 14522875e59fSOllivier Robert if [ "$ZFSBOOT_SWAP_MIRROR" ]; then 145333112d9eSDevin Teske f_eval_catch $funcname echo "$ECHO_APPEND" \ 145433112d9eSDevin Teske 'geom_mirror_load=\"YES\"' \ 145533112d9eSDevin Teske $BSDINSTALL_TMPBOOT/loader.conf.gmirror || 145633112d9eSDevin Teske return $FAILURE 14572875e59fSOllivier Robert fi 1458cd88b886SDevin Teske 14597cae6aabSDevin Teske # We're all done unless we should go on to do encryption 14607cae6aabSDevin Teske [ "$ZFSBOOT_GELI_ENCRYPTION" ] || return $SUCCESS 146113d8e1ceSDevin Teske 1462cd88b886SDevin Teske # 1463cd88b886SDevin Teske # Configure geli(8)-based encryption 1464cd88b886SDevin Teske # 1465bc4a673fSDevin Teske f_dprintf "$funcname: Configuring disk encryption..." 1466bc4a673fSDevin Teske f_eval_catch $funcname echo "$ECHO_APPEND" 'aesni_load=\"YES\"' \ 1467a622223fSDevin Teske $BSDINSTALL_TMPBOOT/loader.conf.aesni || return $FAILURE 1468bc4a673fSDevin Teske f_eval_catch $funcname echo "$ECHO_APPEND" 'geom_eli_load=\"YES\"' \ 1469a622223fSDevin Teske $BSDINSTALL_TMPBOOT/loader.conf.geli || return $FAILURE 1470a1b8f55cSAllan Jude 1471a1b8f55cSAllan Jude # We're all done unless we should go on for boot pool 1472a1b8f55cSAllan Jude [ "$ZFSBOOT_BOOT_POOL" ] || return $SUCCESS 1473a1b8f55cSAllan Jude 1474bc4a673fSDevin Teske for disk in $disks; do 1475bc4a673fSDevin Teske f_eval_catch $funcname printf "$PRINTF_CONF" \ 1476a622223fSDevin Teske geli_%s_keyfile0_load "$disk$targetpart YES" \ 1477a622223fSDevin Teske $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart || 1478cd88b886SDevin Teske return $FAILURE 1479bc4a673fSDevin Teske f_eval_catch $funcname printf "$PRINTF_CONF" \ 1480bc4a673fSDevin Teske geli_%s_keyfile0_type \ 1481a622223fSDevin Teske "$disk$targetpart $disk$targetpart:geli_keyfile0" \ 1482a622223fSDevin Teske $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart || 1483cd88b886SDevin Teske return $FAILURE 1484bc4a673fSDevin Teske f_eval_catch $funcname printf "$PRINTF_CONF" \ 1485bc4a673fSDevin Teske geli_%s_keyfile0_name \ 1486a622223fSDevin Teske "$disk$targetpart \"$ZFSBOOT_GELI_KEY_FILE\"" \ 1487a622223fSDevin Teske $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart || 1488cd88b886SDevin Teske return $FAILURE 1489cd88b886SDevin Teske done 1490cd88b886SDevin Teske 1491a1b8f55cSAllan Jude # Set cachefile for boot pool so it auto-imports at system start 1492a1b8f55cSAllan Jude f_dprintf "$funcname: Configuring zpool.cache for boot pool..." 1493a1b8f55cSAllan Jude f_eval_catch $funcname zpool "$ZPOOL_SET" \ 1494a1b8f55cSAllan Jude "cachefile=\"$BSDINSTALL_CHROOT/boot/zfs/zpool.cache\"" \ 1495a1b8f55cSAllan Jude "$bootpool_name" || return $FAILURE 1496a1b8f55cSAllan Jude 1497a1b8f55cSAllan Jude # Some additional geli(8) requirements for loader.conf(5) 1498a1b8f55cSAllan Jude for option in \ 1499a1b8f55cSAllan Jude 'zpool_cache_load=\"YES\"' \ 1500a1b8f55cSAllan Jude 'zpool_cache_type=\"/boot/zfs/zpool.cache\"' \ 1501a1b8f55cSAllan Jude 'zpool_cache_name=\"/boot/zfs/zpool.cache\"' \ 1502a1b8f55cSAllan Jude 'geom_eli_passphrase_prompt=\"YES\"' \ 1503a1b8f55cSAllan Jude ; do 1504a1b8f55cSAllan Jude f_eval_catch $funcname echo "$ECHO_APPEND" "$option" \ 1505a1b8f55cSAllan Jude $BSDINSTALL_TMPBOOT/loader.conf.zfs || 1506a1b8f55cSAllan Jude return $FAILURE 1507a1b8f55cSAllan Jude done 1508cd88b886SDevin Teske return $SUCCESS 1509cd88b886SDevin Teske} 1510cd88b886SDevin Teske 1511cd88b886SDevin Teske# dialog_menu_diskinfo 1512cd88b886SDevin Teske# 1513cd88b886SDevin Teske# Prompt the user to select a disk and then provide detailed info on it. 1514cd88b886SDevin Teske# 1515cd88b886SDevin Teskedialog_menu_diskinfo() 1516cd88b886SDevin Teske{ 1517a88393ceSDevin Teske local device disk 1518cd88b886SDevin Teske 1519cd88b886SDevin Teske # 1520cd88b886SDevin Teske # Break from loop when user cancels disk selection 1521cd88b886SDevin Teske # 1522cd88b886SDevin Teske while :; do 1523a88393ceSDevin Teske device=$( msg_cancel="$msg_back" f_device_menu \ 1524cd88b886SDevin Teske "$DIALOG_TITLE" "$msg_select_a_disk_device" "" \ 1525cd88b886SDevin Teske $DEVICE_TYPE_DISK 2>&1 ) || break 1526a88393ceSDevin Teske $device get name disk 1527cd88b886SDevin Teske 1528cd88b886SDevin Teske # Show gpart(8) `show' and camcontrol(8) `inquiry' data 1529cd88b886SDevin Teske f_show_msg "$msg_detailed_disk_info" \ 1530cd88b886SDevin Teske "$disk" "$( gpart show $disk 2> /dev/null )" \ 1531cd88b886SDevin Teske "$disk" "$( camcontrol inquiry $disk 2> /dev/null )" \ 1532cd88b886SDevin Teske "$disk" "$( camcontrol identify $disk 2> /dev/null )" 1533cd88b886SDevin Teske done 1534cd88b886SDevin Teske 1535cd88b886SDevin Teske return $SUCCESS 1536cd88b886SDevin Teske} 1537cd88b886SDevin Teske 1538cd88b886SDevin Teske############################################################ MAIN 1539cd88b886SDevin Teske 1540cd88b886SDevin Teske# 1541cd88b886SDevin Teske# Initialize 1542cd88b886SDevin Teske# 1543cd88b886SDevin Teskef_dialog_title "$msg_zfs_configuration" 1544cd88b886SDevin Teskef_dialog_backtitle "$msg_freebsd_installer" 1545cd88b886SDevin Teske 1546cd88b886SDevin Teske# User may have specifically requested ZFS-related operations be interactive 1547cd88b886SDevin Teske! f_interactive && f_zfsinteractive && unset $VAR_NONINTERACTIVE 1548cd88b886SDevin Teske 1549cd88b886SDevin Teske# 1550bc4a673fSDevin Teske# Debugging 1551bc4a673fSDevin Teske# 1552bc4a673fSDevin Teskef_dprintf "BSDINSTALL_CHROOT=[%s]" "$BSDINSTALL_CHROOT" 1553bc4a673fSDevin Teskef_dprintf "BSDINSTALL_TMPETC=[%s]" "$BSDINSTALL_TMPETC" 1554a622223fSDevin Teskef_dprintf "FSTAB_FMT=[%s]" "$FSTAB_FMT" 1555bc4a673fSDevin Teske 1556bc4a673fSDevin Teske# 15570edc8cc8SAllan Jude# If the system was booted with UEFI, set the default boot type to UEFI 155812307018SAllan Jude# 155912307018SAllan Judebootmethod=$( sysctl -n machdep.bootmethod ) 156012307018SAllan Judef_dprintf "machdep.bootmethod=[%s]" "$bootmethod" 15610edc8cc8SAllan Judeif [ "$bootmethod" = "UEFI" ]; then 15624d41f472SAllan Jude : ${ZFSBOOT_BOOT_TYPE:=BIOS+UEFI} 15630edc8cc8SAllan Jude : ${ZFSBOOT_PARTITION_SCHEME:=GPT} 15640edc8cc8SAllan Judeelse 15650edc8cc8SAllan Jude : ${ZFSBOOT_BOOT_TYPE:=BIOS} 15660edc8cc8SAllan Jude : ${ZFSBOOT_PARTITION_SCHEME:=GPT} 156712307018SAllan Judefi 156812307018SAllan Jude 156912307018SAllan Jude# 1570cd88b886SDevin Teske# Loop over the main menu until we've accomplished what we came here to do 1571cd88b886SDevin Teske# 1572cd88b886SDevin Teskewhile :; do 1573cd88b886SDevin Teske if ! f_interactive; then 1574cd88b886SDevin Teske retval=$DIALOG_OK 1575bc4a673fSDevin Teske mtag=">>> $msg_install" 1576cd88b886SDevin Teske else 1577cd88b886SDevin Teske dialog_menu_main 1578cd88b886SDevin Teske retval=$? 1579cd88b886SDevin Teske f_dialog_menutag_fetch mtag 1580cd88b886SDevin Teske fi 1581cd88b886SDevin Teske 1582bc4a673fSDevin Teske f_dprintf "retval=%u mtag=[%s]" $retval "$mtag" 1583cd88b886SDevin Teske [ $retval -eq $DIALOG_OK ] || f_die 1584cd88b886SDevin Teske 1585cd88b886SDevin Teske case "$mtag" in 1586bc4a673fSDevin Teske ">>> $msg_install") 1587cd88b886SDevin Teske # 1588cd88b886SDevin Teske # First, validate the user's selections 1589cd88b886SDevin Teske # 1590cd88b886SDevin Teske 1591cd88b886SDevin Teske # Make sure they gave us a name for the pool 1592cd88b886SDevin Teske if [ ! "$ZFSBOOT_POOL_NAME" ]; then 1593bc4a673fSDevin Teske f_dprintf "Pool name cannot be empty." 1594bc4a673fSDevin Teske f_show_err "$msg_pool_name_cannot_be_empty" 1595cd88b886SDevin Teske continue 1596cd88b886SDevin Teske fi 1597bc4a673fSDevin Teske 1598bc4a673fSDevin Teske # Validate vdev type against number of disks selected/scripted 1599bc4a673fSDevin Teske # (also validates that ZFSBOOT_DISKS are real [probed] disks) 1600bc4a673fSDevin Teske # NB: dialog_menu_layout supports running non-interactively 1601bc4a673fSDevin Teske dialog_menu_layout || continue 1602bc4a673fSDevin Teske 16036203e46bSAllan Jude # Make sure each disk will have room for ZFS 1604cd88b886SDevin Teske if f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize && 16056203e46bSAllan Jude f_expand_number "$ZFSBOOT_BOOT_POOL_SIZE" bootsize && 16066203e46bSAllan Jude f_expand_number "1g" zpoolmin 1607cd88b886SDevin Teske then 16086203e46bSAllan Jude minsize=$(( $swapsize + $zpoolmin )) teeny_disks= 16097cae6aabSDevin Teske [ "$ZFSBOOT_BOOT_POOL" ] && 16107cae6aabSDevin Teske minsize=$(( $minsize + $bootsize )) 1611bc4a673fSDevin Teske for disk in $ZFSBOOT_DISKS; do 1612a88393ceSDevin Teske debug= f_device_find -1 \ 1613a88393ceSDevin Teske $disk $DEVICE_TYPE_DISK device 1614a88393ceSDevin Teske $device get capacity disksize || continue 1615a88393ceSDevin Teske [ ${disksize:-0} -ge 0 ] || disksize=0 1616cd88b886SDevin Teske [ $disksize -lt $minsize ] && 1617cd88b886SDevin Teske teeny_disks="$teeny_disks $disk" 1618cd88b886SDevin Teske done 1619cd88b886SDevin Teske if [ "$teeny_disks" ]; then 16207cae6aabSDevin Teske f_dprintf "swapsize=[%s] bootsize[%s] %s" \ 1621bc4a673fSDevin Teske "$ZFSBOOT_SWAP_SIZE" \ 16227cae6aabSDevin Teske "$ZFSBOOT_BOOT_POOL_SIZE" \ 16237cae6aabSDevin Teske "minsize=[$minsize]" 1624bc4a673fSDevin Teske f_dprintf "These disks are too small: %s" \ 1625bc4a673fSDevin Teske "$teeny_disks" 1626bc4a673fSDevin Teske f_show_err "$msg_these_disks_are_too_small" \ 1627cd88b886SDevin Teske "$ZFSBOOT_SWAP_SIZE" \ 16287cae6aabSDevin Teske "$ZFSBOOT_BOOT_POOL_SIZE" \ 1629cd88b886SDevin Teske "$teeny_disks" 1630cd88b886SDevin Teske continue 1631cd88b886SDevin Teske fi 1632cd88b886SDevin Teske fi 1633cd88b886SDevin Teske 1634cd88b886SDevin Teske # 1635cd88b886SDevin Teske # Last Chance! 1636cd88b886SDevin Teske # 1637bc4a673fSDevin Teske if f_interactive; then 1638bc4a673fSDevin Teske dialog_last_chance $ZFSBOOT_DISKS || continue 1639cd88b886SDevin Teske fi 1640cd88b886SDevin Teske 1641cd88b886SDevin Teske # 1642cd88b886SDevin Teske # Let's do this 1643cd88b886SDevin Teske # 1644cd88b886SDevin Teske 1645cd88b886SDevin Teske vdev_type="$ZFSBOOT_VDEV_TYPE" 1646cd88b886SDevin Teske 1647cd88b886SDevin Teske # Blank the vdev type for the default layout 1648cd88b886SDevin Teske [ "$vdev_type" = "stripe" ] && vdev_type= 1649cd88b886SDevin Teske 1650bc4a673fSDevin Teske zfs_create_boot "$ZFSBOOT_POOL_NAME" \ 1651bc4a673fSDevin Teske "$vdev_type" $ZFSBOOT_DISKS || continue 1652cd88b886SDevin Teske 1653cd88b886SDevin Teske break # to success 1654cd88b886SDevin Teske ;; 1655bc4a673fSDevin Teske ?" $msg_pool_type_disks") 1656bc4a673fSDevin Teske ZFSBOOT_CONFIRM_LAYOUT=1 1657bc4a673fSDevin Teske dialog_menu_layout 1658bc4a673fSDevin Teske # User has poked settings, disable later confirmation 1659bc4a673fSDevin Teske ZFSBOOT_CONFIRM_LAYOUT= 1660bc4a673fSDevin Teske ;; 1661cd88b886SDevin Teske "- $msg_rescan_devices") f_device_rescan ;; 1662cd88b886SDevin Teske "- $msg_disk_info") dialog_menu_diskinfo ;; 1663cd88b886SDevin Teske ?" $msg_pool_name") 1664cd88b886SDevin Teske # Prompt the user to input/change the name for the new pool 1665cd88b886SDevin Teske f_dialog_input input \ 1666cd88b886SDevin Teske "$msg_please_enter_a_name_for_your_zpool" \ 1667cd88b886SDevin Teske "$ZFSBOOT_POOL_NAME" && 1668cd88b886SDevin Teske ZFSBOOT_POOL_NAME="$input" 1669cd88b886SDevin Teske ;; 1670cd88b886SDevin Teske ?" $msg_force_4k_sectors") 1671cd88b886SDevin Teske # Toggle the variable referenced both by the menu and later 1672b4843bd6SSteven Hartland if [ "$ZFSBOOT_FORCE_4K_SECTORS" ]; then 1673b4843bd6SSteven Hartland ZFSBOOT_FORCE_4K_SECTORS= 1674cd88b886SDevin Teske else 1675b4843bd6SSteven Hartland ZFSBOOT_FORCE_4K_SECTORS=1 1676cd88b886SDevin Teske fi 1677cd88b886SDevin Teske ;; 1678bc4a673fSDevin Teske ?" $msg_encrypt_disks") 1679cd88b886SDevin Teske # Toggle the variable referenced both by the menu and later 1680cd88b886SDevin Teske if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then 1681cd88b886SDevin Teske ZFSBOOT_GELI_ENCRYPTION= 1682cd88b886SDevin Teske else 1683b4843bd6SSteven Hartland ZFSBOOT_FORCE_4K_SECTORS=1 1684cd88b886SDevin Teske ZFSBOOT_GELI_ENCRYPTION=1 1685cd88b886SDevin Teske fi 1686cd88b886SDevin Teske ;; 1687cd88b886SDevin Teske ?" $msg_partition_scheme") 16880edc8cc8SAllan Jude # Toggle between GPT (BIOS), GPT (UEFI) and MBR 16890edc8cc8SAllan Jude if [ "$ZFSBOOT_PARTITION_SCHEME" = "GPT" -a "$ZFSBOOT_BOOT_TYPE" = "BIOS" ]; then 16900edc8cc8SAllan Jude ZFSBOOT_PARTITION_SCHEME="GPT" 16910edc8cc8SAllan Jude ZFSBOOT_BOOT_TYPE="UEFI" 16924d41f472SAllan Jude elif [ "$ZFSBOOT_PARTITION_SCHEME" = "GPT" -a "$ZFSBOOT_BOOT_TYPE" = "UEFI" ]; then 16934d41f472SAllan Jude ZFSBOOT_PARTITION_SCHEME="GPT" 16944d41f472SAllan Jude ZFSBOOT_BOOT_TYPE="BIOS+UEFI" 16950edc8cc8SAllan Jude elif [ "$ZFSBOOT_PARTITION_SCHEME" = "GPT" ]; then 16960edc8cc8SAllan Jude ZFSBOOT_PARTITION_SCHEME="MBR" 16970edc8cc8SAllan Jude ZFSBOOT_BOOT_TYPE="BIOS" 16980edc8cc8SAllan Jude elif [ "$ZFSBOOT_PARTITION_SCHEME" = "MBR" ]; then 16997059fa6fSAllan Jude ZFSBOOT_PARTITION_SCHEME="GPT + Active" 17000edc8cc8SAllan Jude ZFSBOOT_BOOT_TYPE="BIOS" 17017059fa6fSAllan Jude elif [ "$ZFSBOOT_PARTITION_SCHEME" = "GPT + Active" ]; then 17027059fa6fSAllan Jude ZFSBOOT_PARTITION_SCHEME="GPT + Lenovo Fix" 17030edc8cc8SAllan Jude ZFSBOOT_BOOT_TYPE="BIOS" 1704cd88b886SDevin Teske else 17050edc8cc8SAllan Jude ZFSBOOT_PARTITION_SCHEME="GPT" 17060edc8cc8SAllan Jude ZFSBOOT_BOOT_TYPE="BIOS" 1707cd88b886SDevin Teske fi 1708cd88b886SDevin Teske ;; 1709cd88b886SDevin Teske ?" $msg_swap_size") 1710cd88b886SDevin Teske # Prompt the user to input/change the swap size for each disk 1711169ff110SAllan Jude while :; do 1712cd88b886SDevin Teske f_dialog_input input \ 1713cd88b886SDevin Teske "$msg_please_enter_amount_of_swap_space" \ 1714cd88b886SDevin Teske "$ZFSBOOT_SWAP_SIZE" && 171530c8ebe9SDevin Teske ZFSBOOT_SWAP_SIZE="${input:-0}" 1716169ff110SAllan Jude if f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize 1717169ff110SAllan Jude then 1718169ff110SAllan Jude if [ $swapsize -ne 0 -a $swapsize -lt 104857600 ]; then 1719169ff110SAllan Jude f_show_err "$msg_swap_toosmall" \ 1720169ff110SAllan Jude "$ZFSBOOT_SWAP_SIZE" 1721169ff110SAllan Jude continue; 1722169ff110SAllan Jude else 1723169ff110SAllan Jude break; 1724169ff110SAllan Jude fi 1725169ff110SAllan Jude else 1726169ff110SAllan Jude f_show_err "$msg_swap_invalid" \ 1727169ff110SAllan Jude "$ZFSBOOT_SWAP_SIZE" 1728169ff110SAllan Jude continue; 1729169ff110SAllan Jude fi 1730169ff110SAllan Jude done 1731cd88b886SDevin Teske ;; 17322875e59fSOllivier Robert ?" $msg_swap_mirror") 17332875e59fSOllivier Robert # Toggle the variable referenced both by the menu and later 17342875e59fSOllivier Robert if [ "$ZFSBOOT_SWAP_MIRROR" ]; then 17352875e59fSOllivier Robert ZFSBOOT_SWAP_MIRROR= 17362875e59fSOllivier Robert else 17372875e59fSOllivier Robert ZFSBOOT_SWAP_MIRROR=1 17382875e59fSOllivier Robert fi 17392875e59fSOllivier Robert ;; 17402875e59fSOllivier Robert ?" $msg_swap_encrypt") 17412875e59fSOllivier Robert # Toggle the variable referenced both by the menu and later 17422875e59fSOllivier Robert if [ "$ZFSBOOT_SWAP_ENCRYPTION" ]; then 17432875e59fSOllivier Robert ZFSBOOT_SWAP_ENCRYPTION= 17442875e59fSOllivier Robert else 17452875e59fSOllivier Robert ZFSBOOT_SWAP_ENCRYPTION=1 17462875e59fSOllivier Robert fi 17472875e59fSOllivier Robert ;; 1748cd88b886SDevin Teske esac 1749cd88b886SDevin Teskedone 1750cd88b886SDevin Teske 175165f36140SDevin Teskeexit $SUCCESS 1752cd88b886SDevin Teske 1753cd88b886SDevin Teske################################################################################ 1754cd88b886SDevin Teske# END 1755cd88b886SDevin Teske################################################################################ 1756