1#!/bin/sh 2#- 3# Copyright (c) 2013-2016 Allan Jude 4# Copyright (c) 2013-2015 Devin Teske 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions 9# are met: 10# 1. Redistributions of source code must retain the above copyright 11# notice, this list of conditions and the following disclaimer. 12# 2. Redistributions in binary form must reproduce the above copyright 13# notice, this list of conditions and the following disclaimer in the 14# documentation and/or other materials provided with the distribution. 15# 16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26# SUCH DAMAGE. 27# 28# $FreeBSD$ 29# 30############################################################ INCLUDES 31 32BSDCFG_SHARE="/usr/share/bsdconfig" 33. $BSDCFG_SHARE/common.subr || exit 1 34f_dprintf "%s: loading includes..." "$0" 35f_include $BSDCFG_SHARE/device.subr 36f_include $BSDCFG_SHARE/dialog.subr 37f_include $BSDCFG_SHARE/password/password.subr 38f_include $BSDCFG_SHARE/variable.subr 39 40############################################################ CONFIGURATION 41 42# 43# Default name of the boot-pool 44# 45: ${ZFSBOOT_POOL_NAME:=zroot} 46 47# 48# Default options to use when creating zroot pool 49# 50: ${ZFSBOOT_POOL_CREATE_OPTIONS:=-O compress=lz4 -O atime=off} 51 52# 53# Default name for the boot environment parent dataset 54# 55: ${ZFSBOOT_BEROOT_NAME:=ROOT} 56 57# 58# Default name for the primary boot environment 59# 60: ${ZFSBOOT_BOOTFS_NAME:=default} 61 62# 63# Default Virtual Device (vdev) type to create 64# 65: ${ZFSBOOT_VDEV_TYPE:=stripe} 66 67# 68# Should we use sysctl(8) vfs.zfs.min_auto_ashift=12 to force 4K sectors? 69# 70: ${ZFSBOOT_FORCE_4K_SECTORS:=1} 71 72# 73# Should we use geli(8) to encrypt the drives? 74# NB: Automatically enables ZFSBOOT_BOOT_POOL 75# 76: ${ZFSBOOT_GELI_ENCRYPTION=} 77 78# 79# Default path to the geli(8) keyfile used in drive encryption 80# 81: ${ZFSBOOT_GELI_KEY_FILE:=/boot/encryption.key} 82 83# 84# Create a separate boot pool? 85# NB: Automatically set when using geli(8) or MBR 86# 87: ${ZFSBOOT_BOOT_POOL=} 88 89# 90# Options to use when creating separate boot pool (if any) 91# 92: ${ZFSBOOT_BOOT_POOL_CREATE_OPTIONS:=} 93 94# 95# Default name for boot pool when enabled (e.g., geli(8) or MBR) 96# 97: ${ZFSBOOT_BOOT_POOL_NAME:=bootpool} 98 99# 100# Default size for boot pool when enabled (e.g., geli(8) or MBR) 101# 102: ${ZFSBOOT_BOOT_POOL_SIZE:=2g} 103 104# 105# Default disks to use (always empty unless being scripted) 106# 107: ${ZFSBOOT_DISKS:=} 108 109# 110# Default partitioning scheme to use on disks 111# 112: ${ZFSBOOT_PARTITION_SCHEME:=} 113 114# 115# Default boot type to use on disks 116# 117: ${ZFSBOOT_BOOT_TYPE:=} 118 119# 120# How much swap to put on each block device in the boot zpool 121# NOTE: Value passed to gpart(8); which supports SI unit suffixes. 122# 123: ${ZFSBOOT_SWAP_SIZE:=2g} 124 125# 126# Should we use geli(8) to encrypt the swap? 127# 128: ${ZFSBOOT_SWAP_ENCRYPTION=} 129 130# 131# Should we use gmirror(8) to mirror the swap? 132# 133: ${ZFSBOOT_SWAP_MIRROR=} 134 135# 136# Default ZFS datasets for root zpool 137# 138# NOTE: Requires /tmp, /var/tmp, /$ZFSBOOT_BOOTFS_NAME/$ZFSBOOT_BOOTFS_NAME 139# NOTE: Anything after pound/hash character [#] is ignored as a comment. 140# 141f_isset ZFSBOOT_DATASETS || ZFSBOOT_DATASETS=" 142 # DATASET OPTIONS (comma or space separated; or both) 143 144 # Boot Environment [BE] root and default boot dataset 145 /$ZFSBOOT_BEROOT_NAME mountpoint=none 146 /$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOTFS_NAME mountpoint=/ 147 148 # Compress /tmp, allow exec but not setuid 149 /tmp mountpoint=/tmp,exec=on,setuid=off 150 151 # Don't mount /usr so that 'base' files go to the BEROOT 152 /usr mountpoint=/usr,canmount=off 153 154 # Home directories separated so they are common to all BEs 155 /usr/home # NB: /home is a symlink to /usr/home 156 157 # Ports tree 158 /usr/ports setuid=off 159 160 # Source tree (compressed) 161 /usr/src 162 163 # Create /var and friends 164 /var mountpoint=/var,canmount=off 165 /var/audit exec=off,setuid=off 166 /var/crash exec=off,setuid=off 167 /var/log exec=off,setuid=off 168 /var/mail atime=on 169 /var/tmp setuid=off 170" # END-QUOTE 171 172# 173# If interactive and the user has not explicitly chosen a vdev type or disks, 174# make the user confirm scripted/default choices when proceeding to install. 175# 176: ${ZFSBOOT_CONFIRM_LAYOUT:=1} 177 178############################################################ GLOBALS 179 180# 181# Format of a line in printf(1) syntax to add to fstab(5) 182# 183FSTAB_FMT="%s\t\t%s\t%s\t%s\t\t%s\t%s\n" 184 185# 186# Command strings for various tasks 187# 188CHMOD_MODE='chmod %s "%s"' 189DD_WITH_OPTIONS='dd if="%s" of="%s" %s' 190ECHO_APPEND='echo "%s" >> "%s"' 191GELI_ATTACH='geli attach -j - -k "%s" "%s"' 192GELI_ATTACH_NOKEY='geli attach -j - "%s"' 193GELI_DETACH_F='geli detach -f "%s"' 194GELI_PASSWORD_INIT='geli init -b -B "%s" -e %s -J - -K "%s" -l 256 -s 4096 "%s"' 195GELI_PASSWORD_GELIBOOT_INIT='geli init -bg -e %s -J - -l 256 -s 4096 "%s"' 196GPART_ADD_ALIGN='gpart add %s -t %s "%s"' 197GPART_ADD_ALIGN_INDEX='gpart add %s -i %s -t %s "%s"' 198GPART_ADD_ALIGN_INDEX_WITH_SIZE='gpart add %s -i %s -t %s -s %s "%s"' 199GPART_ADD_ALIGN_LABEL='gpart add %s -l %s -t %s "%s"' 200GPART_ADD_ALIGN_LABEL_WITH_SIZE='gpart add %s -l %s -t %s -s %s "%s"' 201GPART_BOOTCODE='gpart bootcode -b "%s" "%s"' 202GPART_BOOTCODE_PART='gpart bootcode -b "%s" -p "%s" -i %s "%s"' 203GPART_BOOTCODE_PARTONLY='gpart bootcode -p "%s" -i %s "%s"' 204GPART_CREATE='gpart create -s %s "%s"' 205GPART_DESTROY_F='gpart destroy -F "%s"' 206GPART_SET_ACTIVE='gpart set -a active -i %s "%s"' 207GPART_SET_LENOVOFIX='gpart set -a lenovofix "%s"' 208GPART_SET_PMBR_ACTIVE='gpart set -a active "%s"' 209GRAID_DELETE='graid delete "%s"' 210KLDLOAD='kldload %s' 211LN_SF='ln -sf "%s" "%s"' 212MKDIR_P='mkdir -p "%s"' 213MOUNT_TYPE='mount -t %s "%s" "%s"' 214PRINTF_CONF="printf '%s=\"%%s\"\\\n' %s >> \"%s\"" 215PRINTF_FSTAB='printf "$FSTAB_FMT" "%s" "%s" "%s" "%s" "%s" "%s" >> "%s"' 216SHELL_TRUNCATE=':> "%s"' 217SWAP_GMIRROR_LABEL='gmirror label swap %s' 218SYSCTL_ZFS_MIN_ASHIFT_12='sysctl vfs.zfs.min_auto_ashift=12' 219UMOUNT='umount "%s"' 220ZFS_CREATE_WITH_OPTIONS='zfs create %s "%s"' 221ZFS_SET='zfs set "%s" "%s"' 222ZFS_UNMOUNT='zfs unmount "%s"' 223ZPOOL_CREATE_WITH_OPTIONS='zpool create %s "%s" %s %s' 224ZPOOL_DESTROY='zpool destroy "%s"' 225ZPOOL_EXPORT='zpool export "%s"' 226ZPOOL_IMPORT_WITH_OPTIONS='zpool import %s "%s"' 227ZPOOL_LABELCLEAR_F='zpool labelclear -f "%s"' 228ZPOOL_SET='zpool set %s "%s"' 229 230# 231# Strings that should be moved to an i18n file and loaded with f_include_lang() 232# 233hline_alnum_arrows_punc_tab_enter="Use alnum, arrows, punctuation, TAB or ENTER" 234hline_arrows_space_tab_enter="Use arrows, SPACE, TAB or ENTER" 235hline_arrows_tab_enter="Press arrows, TAB or ENTER" 236msg_an_unknown_error_occurred="An unknown error occurred" 237msg_back="Back" 238msg_cancel="Cancel" 239msg_change_selection="Change Selection" 240msg_configure_options="Configure Options:" 241msg_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" 242msg_disk_info="Disk Info" 243msg_disk_info_help="Get detailed information on disk device(s)" 244msg_disk_singular="disk" 245msg_disk_plural="disks" 246msg_encrypt_disks="Encrypt Disks?" 247msg_encrypt_disks_help="Use geli(8) to encrypt all data partitions" 248msg_error="Error" 249msg_force_4k_sectors="Force 4K Sectors?" 250msg_force_4k_sectors_help="Align partitions to 4K sector boundries and set vfs.zfs.min_auto_ashift=12" 251msg_freebsd_installer="FreeBSD Installer" 252msg_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" 253msg_geli_setup="Initializing encryption on selected disks,\n this will take several seconds per disk" 254msg_install="Install" 255msg_install_desc="Proceed with Installation" 256msg_install_help="Create ZFS boot pool with displayed options" 257msg_invalid_boot_pool_size="Invalid boot pool size \`%s'" 258msg_invalid_disk_argument="Invalid disk argument \`%s'" 259msg_invalid_index_argument="Invalid index argument \`%s'" 260msg_invalid_swap_size="Invalid swap size \`%s'" 261msg_invalid_virtual_device_type="Invalid Virtual Device type \`%s'" 262msg_last_chance_are_you_sure="Last Chance! Are you sure you want to destroy\nthe current contents of the following disks:\n\n %s" 263msg_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' 264msg_mirror_desc="Mirror - n-Way Mirroring" 265msg_mirror_help="[2+ Disks] Mirroring provides the best performance, but the least storage" 266msg_missing_disk_arguments="missing disk arguments" 267msg_missing_one_or_more_scripted_disks="Missing one or more scripted disks!" 268msg_no="NO" 269msg_no_disks_present_to_configure="No disk(s) present to configure" 270msg_no_disks_selected="No disks selected." 271msg_not_enough_disks_selected="Not enough disks selected. (%u < %u minimum)" 272msg_null_disk_argument="NULL disk argument" 273msg_null_index_argument="NULL index argument" 274msg_null_poolname="NULL poolname" 275msg_odd_disk_selected="An even number of disks must be selected to create a RAID 1+0. (%u selected)" 276msg_ok="OK" 277msg_partition_scheme="Partition Scheme" 278msg_partition_scheme_help="Select partitioning scheme. GPT is recommended." 279msg_please_enter_a_name_for_your_zpool="Please enter a name for your zpool:" 280msg_please_enter_amount_of_swap_space="Please enter amount of swap space (SI-Unit suffixes\nrecommended; e.g., \`2g' for 2 Gigabytes):" 281msg_please_select_one_or_more_disks="Please select one or more disks to create a zpool:" 282msg_pool_name="Pool Name" 283msg_pool_name_cannot_be_empty="Pool name cannot be empty." 284msg_pool_name_help="Customize the name of the zpool to be created (Required)" 285msg_pool_type_disks="Pool Type/Disks:" 286msg_pool_type_disks_help="Choose type of ZFS Virtual Device and disks to use (Required)" 287msg_processing_selection="Processing selection..." 288msg_raid10_desc="RAID 1+0 - n x 2-Way Mirrors" 289msg_raid10_help="[4+ Disks] Striped Mirrors provides the best performance, but the least storage" 290msg_raidz1_desc="RAID-Z1 - Single Redundant RAID" 291msg_raidz1_help="[3+ Disks] Withstand failure of 1 disk. Recommended for: 3, 5 or 9 disks" 292msg_raidz2_desc="RAID-Z2 - Double Redundant RAID" 293msg_raidz2_help="[4+ Disks] Withstand failure of 2 disks. Recommended for: 4, 6 or 10 disks" 294msg_raidz3_desc="RAID-Z3 - Triple Redundant RAID" 295msg_raidz3_help="[5+ Disks] Withstand failure of 3 disks. Recommended for: 5, 7 or 11 disks" 296msg_rescan_devices="Rescan Devices" 297msg_rescan_devices_help="Scan for device changes" 298msg_select="Select" 299msg_select_a_disk_device="Select a disk device" 300msg_select_virtual_device_type="Select Virtual Device type:" 301msg_stripe_desc="Stripe - No Redundancy" 302msg_stripe_help="[1+ Disks] Striping provides maximum storage but no redundancy" 303msg_swap_encrypt="Encrypt Swap?" 304msg_swap_encrypt_help="Encrypt swap partitions with temporary keys, discarded on reboot" 305msg_swap_invalid="The selected swap size (%s) is invalid. Enter a number optionally followed by units. Example: 2G" 306msg_swap_mirror="Mirror Swap?" 307msg_swap_mirror_help="Mirror swap partitions for redundancy, breaks crash dumps" 308msg_swap_size="Swap Size" 309msg_swap_size_help="Customize how much swap space is allocated to each selected disk" 310msg_swap_toosmall="The selected swap size (%s) is to small. Please enter a value greater than 100MB or enter 0 for no swap" 311msg_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." 312msg_unable_to_get_disk_capacity="Unable to get disk capacity of \`%s'" 313msg_unsupported_partition_scheme="%s is an unsupported partition scheme" 314msg_user_cancelled="User Cancelled." 315msg_yes="YES" 316msg_zfs_configuration="ZFS Configuration" 317 318############################################################ FUNCTIONS 319 320# dialog_menu_main 321# 322# Display the dialog(1)-based application main menu. 323# 324dialog_menu_main() 325{ 326 local title="$DIALOG_TITLE" 327 local btitle="$DIALOG_BACKTITLE" 328 local prompt="$msg_configure_options" 329 local force4k="$msg_no" 330 local usegeli="$msg_no" 331 local swapgeli="$msg_no" 332 local swapmirror="$msg_no" 333 [ "$ZFSBOOT_FORCE_4K_SECTORS" ] && force4k="$msg_yes" 334 [ "$ZFSBOOT_GELI_ENCRYPTION" ] && usegeli="$msg_yes" 335 [ "$ZFSBOOT_SWAP_ENCRYPTION" ] && swapgeli="$msg_yes" 336 [ "$ZFSBOOT_SWAP_MIRROR" ] && swapmirror="$msg_yes" 337 local disks n disks_grammar 338 f_count n $ZFSBOOT_DISKS 339 { [ $n -eq 1 ] && disks_grammar=$msg_disk_singular; } || 340 disks_grammar=$msg_disk_plural # grammar 341 local menu_list=" 342 '>>> $msg_install' '$msg_install_desc' 343 '$msg_install_help' 344 'T $msg_pool_type_disks' 345 '$ZFSBOOT_VDEV_TYPE: $n $disks_grammar' 346 '$msg_pool_type_disks_help' 347 '- $msg_rescan_devices' '*' 348 '$msg_rescan_devices_help' 349 '- $msg_disk_info' '*' 350 '$msg_disk_info_help' 351 'N $msg_pool_name' '$ZFSBOOT_POOL_NAME' 352 '$msg_pool_name_help' 353 '4 $msg_force_4k_sectors' 354 '$force4k' 355 '$msg_force_4k_sectors_help' 356 'E $msg_encrypt_disks' '$usegeli' 357 '$msg_encrypt_disks_help' 358 'P $msg_partition_scheme' 359 '$ZFSBOOT_PARTITION_SCHEME ($ZFSBOOT_BOOT_TYPE)' 360 '$msg_partition_scheme_help' 361 'S $msg_swap_size' '$ZFSBOOT_SWAP_SIZE' 362 '$msg_swap_size_help' 363 'M $msg_swap_mirror' '$swapmirror' 364 '$msg_swap_mirror_help' 365 'W $msg_swap_encrypt' '$swapgeli' 366 '$msg_swap_encrypt_help' 367 " # END-QUOTE 368 local defaultitem= # Calculated below 369 local hline="$hline_alnum_arrows_punc_tab_enter" 370 371 local height width rows 372 eval f_dialog_menu_with_help_size height width rows \ 373 \"\$title\" \"\$btitle\" \"\$prompt\" \"\$hline\" $menu_list 374 375 # Obtain default-item from previously stored selection 376 f_dialog_default_fetch defaultitem 377 378 local menu_choice 379 menu_choice=$( eval $DIALOG \ 380 --title \"\$title\" \ 381 --backtitle \"\$btitle\" \ 382 --hline \"\$hline\" \ 383 --item-help \ 384 --ok-label \"\$msg_select\" \ 385 --cancel-label \"\$msg_cancel\" \ 386 --default-item \"\$defaultitem\" \ 387 --menu \"\$prompt\" \ 388 $height $width $rows \ 389 $menu_list \ 390 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 391 ) 392 local retval=$? 393 f_dialog_data_sanitize menu_choice 394 f_dialog_menutag_store "$menu_choice" 395 396 # Only update default-item on success 397 [ $retval -eq $DIALOG_OK ] && f_dialog_default_store "$menu_choice" 398 399 return $retval 400} 401 402# dialog_last_chance $disks ... 403# 404# Display a list of the disks that the user is about to destroy. The default 405# action is to return error status unless the user explicitly (non-default) 406# selects "Yes" from the noyes dialog. 407# 408dialog_last_chance() 409{ 410 local title="$DIALOG_TITLE" 411 local btitle="$DIALOG_BACKTITLE" 412 local prompt # Calculated below 413 local hline="$hline_arrows_tab_enter" 414 415 local height=8 width=50 prefix=" " 416 local plen=${#prefix} list= line= 417 local max_width=$(( $width - 3 - $plen )) 418 419 local yes no defaultno extra_args format 420 if [ "$USE_XDIALOG" ]; then 421 yes=ok no=cancel defaultno=default-no 422 extra_args="--wrap --left" 423 format="$msg_last_chance_are_you_sure" 424 else 425 yes=yes no=no defaultno=defaultno 426 extra_args="--colors --cr-wrap" 427 format="$msg_last_chance_are_you_sure_color" 428 fi 429 430 local disk line_width 431 for disk in $*; do 432 if [ "$line" ]; then 433 line_width=${#line} 434 else 435 line_width=$plen 436 fi 437 line_width=$(( $line_width + 1 + ${#disk} )) 438 # Add newline before disk if it would exceed max_width 439 if [ $line_width -gt $max_width ]; then 440 list="$list$line\n" 441 line="$prefix" 442 height=$(( $height + 1 )) 443 fi 444 # Add the disk to the list 445 line="$line $disk" 446 done 447 # Append the left-overs 448 if [ "${line#$prefix}" ]; then 449 list="$list$line" 450 height=$(( $height + 1 )) 451 fi 452 453 # Add height for Xdialog(1) 454 [ "$USE_XDIALOG" ] && height=$(( $height + $height / 5 + 3 )) 455 456 prompt=$( printf "$format" "$list" ) 457 f_dprintf "%s: Last Chance!" "$0" 458 $DIALOG \ 459 --title "$title" \ 460 --backtitle "$btitle" \ 461 --hline "$hline" \ 462 --$defaultno \ 463 --$yes-label "$msg_yes" \ 464 --$no-label "$msg_no" \ 465 $extra_args \ 466 --yesno "$prompt" $height $width 467} 468 469# dialog_menu_layout 470# 471# Configure Virtual Device type and disks to use for the ZFS boot pool. User 472# must select enough disks to satisfy the chosen vdev type. 473# 474dialog_menu_layout() 475{ 476 local funcname=dialog_menu_layout 477 local title="$DIALOG_TITLE" 478 local btitle="$DIALOG_BACKTITLE" 479 local vdev_prompt="$msg_select_virtual_device_type" 480 local disk_prompt="$msg_please_select_one_or_more_disks" 481 local vdev_menu_list=" 482 'stripe' '$msg_stripe_desc' '$msg_stripe_help' 483 'mirror' '$msg_mirror_desc' '$msg_mirror_help' 484 'raid10' '$msg_raid10_desc' '$msg_raid10_help' 485 'raidz1' '$msg_raidz1_desc' '$msg_raidz1_help' 486 'raidz2' '$msg_raidz2_desc' '$msg_raidz2_help' 487 'raidz3' '$msg_raidz3_desc' '$msg_raidz3_help' 488 " # END-QUOTE 489 local disk_check_list= # Calculated below 490 local vdev_hline="$hline_arrows_tab_enter" 491 local disk_hline="$hline_arrows_space_tab_enter" 492 493 # Warn the user if vdev type is not valid 494 case "$ZFSBOOT_VDEV_TYPE" in 495 stripe|mirror|raid10|raidz1|raidz2|raidz3) : known good ;; 496 *) 497 f_dprintf "%s: Invalid virtual device type \`%s'" \ 498 $funcname "$ZFSBOOT_VDEV_TYPE" 499 f_show_err "$msg_invalid_virtual_device_type" \ 500 "$ZFSBOOT_VDEV_TYPE" 501 f_interactive || return $FAILURE 502 esac 503 504 # Calculate size of vdev menu once only 505 local vheight vwidth vrows 506 eval f_dialog_menu_with_help_size vheight vwidth vrows \ 507 \"\$title\" \"\$btitle\" \"\$vdev_prompt\" \"\$vdev_hline\" \ 508 $vdev_menu_list 509 510 # Get a list of probed disk devices 511 local disks= 512 debug= f_device_find "" $DEVICE_TYPE_DISK disks 513 514 # Prune out mounted md(4) devices that may be part of the boot process 515 local disk name new_list= 516 for disk in $disks; do 517 debug= $disk get name name 518 case "$name" in 519 md[0-9]*) f_mounted -b "/dev/$name" && continue ;; 520 esac 521 new_list="$new_list $disk" 522 done 523 disks="${new_list# }" 524 525 # Debugging 526 if [ "$debug" ]; then 527 local disk_names= 528 for disk in $disks; do 529 debug= $disk get name name 530 disk_names="$disk_names $name" 531 done 532 f_dprintf "$funcname: disks=[%s]" "${disk_names# }" 533 fi 534 535 if [ ! "$disks" ]; then 536 f_dprintf "No disk(s) present to configure" 537 f_show_err "$msg_no_disks_present_to_configure" 538 return $FAILURE 539 fi 540 541 # Lets sort the disks array to be more user friendly 542 f_device_sort_by name disks disks 543 544 # 545 # Operate in a loop so we can (if interactive) repeat if not enough 546 # disks are selected to satisfy the chosen vdev type or user wants to 547 # back-up to the previous menu. 548 # 549 local vardisk ndisks onoff selections vdev_choice breakout device 550 local valid_disks all_valid want_disks desc height width rows 551 while :; do 552 # 553 # Confirm the vdev type that was selected 554 # 555 if f_interactive && [ "$ZFSBOOT_CONFIRM_LAYOUT" ]; then 556 vdev_choice=$( eval $DIALOG \ 557 --title \"\$title\" \ 558 --backtitle \"\$btitle\" \ 559 --hline \"\$vdev_hline\" \ 560 --ok-label \"\$msg_ok\" \ 561 --cancel-label \"\$msg_cancel\" \ 562 --item-help \ 563 --default-item \"\$ZFSBOOT_VDEV_TYPE\" \ 564 --menu \"\$vdev_prompt\" \ 565 $vheight $vwidth $vrows \ 566 $vdev_menu_list \ 567 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 568 ) || return $? 569 # Exit if user pressed ESC or chose Cancel/No 570 f_dialog_data_sanitize vdev_choice 571 572 ZFSBOOT_VDEV_TYPE="$vdev_choice" 573 f_dprintf "$funcname: ZFSBOOT_VDEV_TYPE=[%s]" \ 574 "$ZFSBOOT_VDEV_TYPE" 575 fi 576 577 # Determine the number of disks needed for this vdev type 578 want_disks=0 579 case "$ZFSBOOT_VDEV_TYPE" in 580 stripe) want_disks=1 ;; 581 mirror) want_disks=2 ;; 582 raid10) want_disks=4 ;; 583 raidz1) want_disks=3 ;; 584 raidz2) want_disks=4 ;; 585 raidz3) want_disks=5 ;; 586 esac 587 588 # 589 # Warn the user if any scripted disks are invalid 590 # 591 valid_disks= all_valid=${ZFSBOOT_DISKS:+1} # optimism 592 for disk in $ZFSBOOT_DISKS; do 593 if debug= f_device_find -1 \ 594 $disk $DEVICE_TYPE_DISK device 595 then 596 valid_disks="$valid_disks $disk" 597 continue 598 fi 599 f_dprintf "$funcname: \`%s' is not a real disk" "$disk" 600 all_valid= 601 done 602 if [ ! "$all_valid" ]; then 603 if [ "$ZFSBOOT_DISKS" ]; then 604 f_show_err \ 605 "$msg_missing_one_or_more_scripted_disks" 606 else 607 f_dprintf "No disks selected." 608 f_interactive || 609 f_show_err "$msg_no_disks_selected" 610 fi 611 f_interactive || return $FAILURE 612 fi 613 ZFSBOOT_DISKS="${valid_disks# }" 614 615 # 616 # Short-circuit if we're running non-interactively 617 # 618 if ! f_interactive || [ ! "$ZFSBOOT_CONFIRM_LAYOUT" ]; then 619 f_count ndisks $ZFSBOOT_DISKS 620 [ $ndisks -ge $want_disks ] && break # to success 621 622 # Not enough disks selected 623 f_dprintf "$funcname: %s: %s (%u < %u minimum)" \ 624 "$ZFSBOOT_VDEV_TYPE" \ 625 "Not enough disks selected." \ 626 $ndisks $want_disks 627 f_interactive || return $FAILURE 628 msg_yes="$msg_change_selection" msg_no="$msg_cancel" \ 629 f_yesno "%s: $msg_not_enough_disks_selected" \ 630 "$ZFSBOOT_VDEV_TYPE" $ndisks $want_disks || 631 return $FAILURE 632 fi 633 634 # 635 # Confirm the disks that were selected 636 # Loop until the user cancels or selects enough disks 637 # 638 breakout= 639 while :; do 640 # Loop over list of available disks, resetting state 641 for disk in $disks; do 642 f_isset _${disk}_status && _${disk}_status= 643 done 644 645 # Loop over list of selected disks and create temporary 646 # locals to map statuses onto up-to-date list of disks 647 for disk in $ZFSBOOT_DISKS; do 648 debug= f_device_find -1 \ 649 $disk $DEVICE_TYPE_DISK disk 650 f_isset _${disk}_status || 651 local _${disk}_status 652 _${disk}_status=on 653 done 654 655 # Create the checklist menu of discovered disk devices 656 disk_check_list= 657 for disk in $disks; do 658 desc= 659 $disk get name name 660 $disk get desc desc 661 f_shell_escape "$desc" desc 662 f_getvar _${disk}_status:-off onoff 663 disk_check_list="$disk_check_list 664 $name '$desc' $onoff" 665 done 666 667 eval f_dialog_checklist_size height width rows \ 668 \"\$title\" \"\$btitle\" \"\$prompt\" \ 669 \"\$hline\" $disk_check_list 670 671 selections=$( eval $DIALOG \ 672 --title \"\$DIALOG_TITLE\" \ 673 --backtitle \"\$DIALOG_BACKTITLE\" \ 674 --separate-output \ 675 --hline \"\$hline\" \ 676 --ok-label \"\$msg_ok\" \ 677 --cancel-label \"\$msg_back\" \ 678 --checklist \"\$prompt\" \ 679 $height $width $rows \ 680 $disk_check_list \ 681 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 682 ) || break 683 # Loop if user pressed ESC or chose Cancel/No 684 f_dialog_data_sanitize selections 685 686 ZFSBOOT_DISKS="$selections" 687 f_dprintf "$funcname: ZFSBOOT_DISKS=[%s]" \ 688 "$ZFSBOOT_DISKS" 689 690 f_count ndisks $ZFSBOOT_DISKS 691 692 if [ "$ZFSBOOT_VDEV_TYPE" == "raid10" ] && 693 [ $(( $ndisks % 2 )) -ne 0 ]; then 694 f_dprintf "$funcname: %s: %s (%u %% 2 = %u)" \ 695 "$ZFSBOOT_VDEV_TYPE" \ 696 "Number of disks not even:" \ 697 $ndisks $(( $ndisks % 2 )) 698 msg_yes="$msg_change_selection" \ 699 msg_no="$msg_cancel" \ 700 f_yesno "%s: $msg_odd_disk_selected" \ 701 "$ZFSBOOT_VDEV_TYPE" $ndisks || 702 break 703 continue 704 fi 705 706 [ $ndisks -ge $want_disks ] && 707 breakout=break && break 708 709 # Not enough disks selected 710 f_dprintf "$funcname: %s: %s (%u < %u minimum)" \ 711 "$ZFSBOOT_VDEV_TYPE" \ 712 "Not enough disks selected." \ 713 $ndisks $want_disks 714 msg_yes="$msg_change_selection" msg_no="$msg_cancel" \ 715 f_yesno "%s: $msg_not_enough_disks_selected" \ 716 "$ZFSBOOT_VDEV_TYPE" $ndisks $want_disks || 717 break 718 done 719 [ "$breakout" = "break" ] && break 720 [ "$ZFSBOOT_CONFIRM_LAYOUT" ] || return $FAILURE 721 done 722 723 return $DIALOG_OK 724} 725 726# zfs_create_diskpart $disk $index 727# 728# For each block device to be used in the zpool, rather than just create the 729# zpool with the raw block devices (e.g., da0, da1, etc.) we create partitions 730# so we can have some real swap. This also provides wiggle room incase your 731# replacement drivers do not have the exact same sector counts. 732# 733# NOTE: $swapsize and $bootsize should be defined by the calling function. 734# NOTE: Sets $bootpart and $targetpart for the calling function. 735# 736zfs_create_diskpart() 737{ 738 local funcname=zfs_create_diskpart 739 local disk="$1" index="$2" 740 741 # Check arguments 742 if [ ! "$disk" ]; then 743 f_dprintf "$funcname: NULL disk argument" 744 msg_error="$msg_error: $funcname" \ 745 f_show_err "$msg_null_disk_argument" 746 return $FAILURE 747 fi 748 if [ "${disk#*[$IFS]}" != "$disk" ]; then 749 f_dprintf "$funcname: Invalid disk argument \`%s'" "$disk" 750 msg_error="$msg_error: $funcname" \ 751 f_show_err "$msg_invalid_disk_argument" "$disk" 752 return $FAILURE 753 fi 754 if [ ! "$index" ]; then 755 f_dprintf "$funcname: NULL index argument" 756 msg_error="$msg_error: $funcname" \ 757 f_show_err "$msg_null_index_argument" 758 return $FAILURE 759 fi 760 if ! f_isinteger "$index"; then 761 f_dprintf "$funcname: Invalid index argument \`%s'" "$index" 762 msg_error="$msg_error: $funcname" \ 763 f_show_err "$msg_invalid_index_argument" "$index" 764 return $FAILURE 765 fi 766 f_dprintf "$funcname: disk=[%s] index=[%s]" "$disk" "$index" 767 768 # Check for unknown partition scheme before proceeding further 769 case "$ZFSBOOT_PARTITION_SCHEME" in 770 ""|MBR|GPT*) : known good ;; 771 *) 772 f_dprintf "$funcname: %s is an unsupported partition scheme" \ 773 "$ZFSBOOT_PARTITION_SCHEME" 774 msg_error="$msg_error: $funcname" f_show_err \ 775 "$msg_unsupported_partition_scheme" \ 776 "$ZFSBOOT_PARTITION_SCHEME" 777 return $FAILURE 778 esac 779 780 # 781 # Destroy whatever partition layout is currently on disk. 782 # NOTE: `-F' required to destroy if partitions still exist. 783 # NOTE: Failure is ok here, blank disk will have nothing to destroy. 784 # 785 f_dprintf "$funcname: Destroying all data/layouts on \`%s'..." "$disk" 786 f_eval_catch -d $funcname gpart "$GPART_DESTROY_F" $disk 787 f_eval_catch -d $funcname graid "$GRAID_DELETE" $disk 788 f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" /dev/$disk 789 790 # Make doubly-sure backup GPT is destroyed 791 f_eval_catch -d $funcname gpart "$GPART_CREATE" gpt $disk 792 f_eval_catch -d $funcname gpart "$GPART_DESTROY_F" $disk 793 794 # 795 # Lay down the desired type of partition scheme 796 # 797 local setsize mbrindex align_small align_big 798 # 799 # If user has requested 4 K alignment, add these params to the 800 # gpart add calls. With GPT, we align large partitions to 1 M for 801 # improved performance on SSDs. MBR does not always play well with gaps 802 # between partitions, so all alignment is only 4k for that case. 803 # With MBR, we align the BSD partition that contains the MBR, otherwise 804 # the system fails to boot. 805 # 806 if [ "$ZFSBOOT_FORCE_4K_SECTORS" ]; then 807 align_small="-a 4k" 808 align_big="-a 1m" 809 fi 810 811 case "$ZFSBOOT_PARTITION_SCHEME" in 812 ""|GPT*) f_dprintf "$funcname: Creating GPT layout..." 813 # 814 # 1. Create GPT layout using labels 815 # 816 f_eval_catch $funcname gpart "$GPART_CREATE" gpt $disk || 817 return $FAILURE 818 819 # 820 # Apply workarounds if requested by the user 821 # 822 if [ "$ZFSBOOT_PARTITION_SCHEME" = "GPT + Lenovo Fix" ]; then 823 f_eval_catch $funcname gpart "$GPART_SET_LENOVOFIX" \ 824 $disk || return $FAILURE 825 elif [ "$ZFSBOOT_PARTITION_SCHEME" = "GPT + Active" ]; then 826 f_eval_catch $funcname gpart "$GPART_SET_PMBR_ACTIVE" \ 827 $disk || return $FAILURE 828 fi 829 830 # 831 # 2. Add small freebsd-boot and/or efi partition 832 # 833 if [ "$ZFSBOOT_BOOT_TYPE" = "UEFI" -o "$ZFSBOOT_BOOT_TYPE" = "BIOS+UEFI" ]; then 834 # 835 # Enable boot pool if encryption is desired 836 # 837 [ "$ZFSBOOT_GELI_ENCRYPTION" ] && ZFSBOOT_BOOT_POOL=1 838 839 f_eval_catch $funcname gpart \ 840 "$GPART_ADD_ALIGN_LABEL_WITH_SIZE" \ 841 "$align_small" efiboot$index efi 800k $disk || 842 return $FAILURE 843 f_eval_catch $funcname gpart "$GPART_BOOTCODE_PARTONLY" \ 844 /boot/boot1.efifat 1 $disk || 845 return $FAILURE 846 fi 847 848 if [ "$ZFSBOOT_BOOT_TYPE" = "BIOS" -o "$ZFSBOOT_BOOT_TYPE" = "BIOS+UEFI" ]; then 849 f_eval_catch $funcname gpart \ 850 "$GPART_ADD_ALIGN_LABEL_WITH_SIZE" \ 851 "$align_small" gptboot$index freebsd-boot \ 852 512k $disk || return $FAILURE 853 if [ "$ZFSBOOT_BOOT_TYPE" = "BIOS" ]; then 854 f_eval_catch $funcname gpart "$GPART_BOOTCODE_PART" \ 855 /boot/pmbr /boot/gptzfsboot 1 $disk || 856 return $FAILURE 857 else 858 f_eval_catch $funcname gpart "$GPART_BOOTCODE_PART" \ 859 /boot/pmbr /boot/gptzfsboot 2 $disk || 860 return $FAILURE 861 fi 862 fi 863 864 # NB: zpool will use the `zfs#' GPT labels 865 if [ "$ZFSBOOT_BOOT_TYPE" = "BIOS+UEFI" ]; then 866 if [ "$ZFSBOOT_BOOT_POOL" ]; then 867 bootpart=p3 swappart=p4 targetpart=p4 868 [ ${swapsize:-0} -gt 0 ] && targetpart=p5 869 else 870 # Bootpart unused 871 bootpart=p3 swappart=p3 targetpart=p3 872 [ ${swapsize:-0} -gt 0 ] && targetpart=p4 873 fi 874 else 875 if [ "$ZFSBOOT_BOOT_POOL" ]; then 876 bootpart=p2 swappart=p3 targetpart=p3 877 [ ${swapsize:-0} -gt 0 ] && targetpart=p4 878 else 879 # Bootpart unused 880 bootpart=p2 swappart=p2 targetpart=p2 881 [ ${swapsize:-0} -gt 0 ] && targetpart=p3 882 fi 883 fi 884 885 # 886 # Prepare boot pool if enabled (e.g., for geli(8)) 887 # 888 if [ "$ZFSBOOT_BOOT_POOL" ]; then 889 f_eval_catch $funcname gpart \ 890 "$GPART_ADD_ALIGN_LABEL_WITH_SIZE" \ 891 "$align_big" boot$index freebsd-zfs \ 892 ${bootsize}b $disk || 893 return $FAILURE 894 # Pedantically nuke any old labels 895 f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 896 /dev/$disk$bootpart 897 if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then 898 # Pedantically detach targetpart for later 899 f_eval_catch -d $funcname geli \ 900 "$GELI_DETACH_F" \ 901 /dev/$disk$targetpart 902 fi 903 fi 904 905 # 906 # 3. Add freebsd-swap partition labeled `swap#' 907 # 908 if [ ${swapsize:-0} -gt 0 ]; then 909 f_eval_catch $funcname gpart \ 910 "$GPART_ADD_ALIGN_LABEL_WITH_SIZE" \ 911 "$align_big" swap$index freebsd-swap \ 912 ${swapsize}b $disk || 913 return $FAILURE 914 # Pedantically nuke any old labels on the swap 915 f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 916 /dev/$disk$swappart 917 fi 918 919 # 920 # 4. Add freebsd-zfs partition labeled `zfs#' for zroot 921 # 922 f_eval_catch $funcname gpart "$GPART_ADD_ALIGN_LABEL" \ 923 "$align_big" zfs$index freebsd-zfs $disk || 924 return $FAILURE 925 f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 926 /dev/$disk$targetpart 927 ;; 928 929 MBR) f_dprintf "$funcname: Creating MBR layout..." 930 # 931 # Enable boot pool if encryption is desired 932 # 933 [ "$ZFSBOOT_GELI_ENCRYPTION" ] && ZFSBOOT_BOOT_POOL=1 934 # 935 # 1. Create MBR layout (no labels) 936 # 937 f_eval_catch $funcname gpart "$GPART_CREATE" mbr $disk || 938 return $FAILURE 939 f_eval_catch $funcname gpart "$GPART_BOOTCODE" /boot/mbr \ 940 $disk || return $FAILURE 941 942 # 943 # 2. Add freebsd slice with all available space 944 # 945 f_eval_catch $funcname gpart "$GPART_ADD_ALIGN" "$align_small" \ 946 freebsd $disk || 947 return $FAILURE 948 f_eval_catch $funcname gpart "$GPART_SET_ACTIVE" 1 $disk || 949 return $FAILURE 950 # Pedantically nuke any old labels 951 f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 952 /dev/${disk}s1 953 # Pedantically nuke any old scheme 954 f_eval_catch -d $funcname gpart "$GPART_DESTROY_F" ${disk}s1 955 956 # 957 # 3. Write BSD scheme to the freebsd slice 958 # 959 f_eval_catch $funcname gpart "$GPART_CREATE" BSD ${disk}s1 || 960 return $FAILURE 961 962 # NB: zpool will use s1a (no labels) 963 bootpart=s1a swappart=s1b targetpart=s1d mbrindex=4 964 965 # 966 # Always prepare a boot pool on MBR 967 # Do not align this partition, there must not be a gap 968 # 969 ZFSBOOT_BOOT_POOL=1 970 f_eval_catch $funcname gpart \ 971 "$GPART_ADD_ALIGN_INDEX_WITH_SIZE" \ 972 "" 1 freebsd-zfs ${bootsize}b ${disk}s1 || 973 return $FAILURE 974 # Pedantically nuke any old labels 975 f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 976 /dev/$disk$bootpart 977 if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then 978 # Pedantically detach targetpart for later 979 f_eval_catch -d $funcname geli \ 980 "$GELI_DETACH_F" \ 981 /dev/$disk$targetpart 982 fi 983 984 # 985 # 4. Add freebsd-swap partition 986 # 987 if [ ${swapsize:-0} -gt 0 ]; then 988 f_eval_catch $funcname gpart \ 989 "$GPART_ADD_ALIGN_INDEX_WITH_SIZE" \ 990 "$align_small" 2 freebsd-swap ${swapsize}b ${disk}s1 || 991 return $FAILURE 992 # Pedantically nuke any old labels on the swap 993 f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 994 /dev/${disk}s1b 995 fi 996 997 # 998 # 5. Add freebsd-zfs partition for zroot 999 # 1000 f_eval_catch $funcname gpart "$GPART_ADD_ALIGN_INDEX" \ 1001 "$align_small" $mbrindex freebsd-zfs ${disk}s1 || return $FAILURE 1002 f_eval_catch -d $funcname zpool "$ZPOOL_LABELCLEAR_F" \ 1003 /dev/$disk$targetpart # Pedantic 1004 f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \ 1005 /boot/zfsboot /dev/${disk}s1 count=1 || 1006 return $FAILURE 1007 ;; 1008 1009 esac # $ZFSBOOT_PARTITION_SCHEME 1010 1011 # Update fstab(5) 1012 local swapsize 1013 f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize 1014 if [ "$isswapmirror" ]; then 1015 # This is not the first disk in the mirror, do nothing 1016 elif [ ${swapsize:-0} -eq 0 ]; then 1017 # If swap is 0 sized, don't add it to fstab 1018 elif [ "$ZFSBOOT_SWAP_ENCRYPTION" -a "$ZFSBOOT_SWAP_MIRROR" ]; then 1019 f_eval_catch $funcname printf "$PRINTF_FSTAB" \ 1020 /dev/mirror/swap.eli none swap sw 0 0 \ 1021 $BSDINSTALL_TMPETC/fstab || 1022 return $FAILURE 1023 isswapmirror=1 1024 elif [ "$ZFSBOOT_SWAP_MIRROR" ]; then 1025 f_eval_catch $funcname printf "$PRINTF_FSTAB" \ 1026 /dev/mirror/swap none swap sw 0 0 \ 1027 $BSDINSTALL_TMPETC/fstab || 1028 return $FAILURE 1029 isswapmirror=1 1030 elif [ "$ZFSBOOT_SWAP_ENCRYPTION" ]; then 1031 f_eval_catch $funcname printf "$PRINTF_FSTAB" \ 1032 /dev/$disk${swappart}.eli none swap sw 0 0 \ 1033 $BSDINSTALL_TMPETC/fstab || 1034 return $FAILURE 1035 else 1036 f_eval_catch $funcname printf "$PRINTF_FSTAB" \ 1037 /dev/$disk$swappart none swap sw 0 0 \ 1038 $BSDINSTALL_TMPETC/fstab || 1039 return $FAILURE 1040 fi 1041 1042 return $SUCCESS 1043} 1044 1045# zfs_create_boot $poolname $vdev_type $disks ... 1046# 1047# Creates boot pool and dataset layout. Returns error if something goes wrong. 1048# Errors are printed to stderr for collection and display. 1049# 1050zfs_create_boot() 1051{ 1052 local funcname=zfs_create_boot 1053 local zroot_name="$1" 1054 local zroot_vdevtype="$2" 1055 local zroot_vdevs= # Calculated below 1056 local swap_devs= # Calculated below 1057 local boot_vdevs= # Used for geli(8) and/or MBR layouts 1058 shift 2 # poolname vdev_type 1059 local disks="$*" disk 1060 local isswapmirror 1061 local bootpart targetpart swappart # Set by zfs_create_diskpart() below 1062 local create_options 1063 1064 # 1065 # Pedantic checks; should never be seen 1066 # 1067 if [ ! "$zroot_name" ]; then 1068 f_dprintf "$funcname: NULL poolname" 1069 msg_error="$msg_error: $funcname" \ 1070 f_show_err "$msg_null_poolname" 1071 return $FAILURE 1072 fi 1073 if [ $# -lt 1 ]; then 1074 f_dprintf "$funcname: missing disk arguments" 1075 msg_error="$msg_error: $funcname" \ 1076 f_show_err "$msg_missing_disk_arguments" 1077 return $FAILURE 1078 fi 1079 f_dprintf "$funcname: poolname=[%s] vdev_type=[%s]" \ 1080 "$zroot_name" "$zroot_vdevtype" 1081 1082 # 1083 # Initialize fstab(5) 1084 # 1085 f_dprintf "$funcname: Initializing temporary fstab(5) file..." 1086 f_eval_catch $funcname sh "$SHELL_TRUNCATE" $BSDINSTALL_TMPETC/fstab || 1087 return $FAILURE 1088 f_eval_catch $funcname printf "$PRINTF_FSTAB" \ 1089 "# Device" Mountpoint FStype Options Dump "Pass#" \ 1090 $BSDINSTALL_TMPETC/fstab || return $FAILURE 1091 1092 # 1093 # Expand SI units in desired sizes 1094 # 1095 f_dprintf "$funcname: Expanding supplied size values..." 1096 local swapsize bootsize 1097 if ! f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize; then 1098 f_dprintf "$funcname: Invalid swap size \`%s'" \ 1099 "$ZFSBOOT_SWAP_SIZE" 1100 f_show_err "$msg_invalid_swap_size" "$ZFSBOOT_SWAP_SIZE" 1101 return $FAILURE 1102 fi 1103 if ! f_expand_number "$ZFSBOOT_BOOT_POOL_SIZE" bootsize; then 1104 f_dprintf "$funcname: Invalid boot pool size \`%s'" \ 1105 "$ZFSBOOT_BOOT_POOL_SIZE" 1106 f_show_err "$msg_invalid_boot_pool_size" \ 1107 "$ZFSBOOT_BOOT_POOL_SIZE" 1108 return $FAILURE 1109 fi 1110 f_dprintf "$funcname: ZFSBOOT_SWAP_SIZE=[%s] swapsize=[%s]" \ 1111 "$ZFSBOOT_SWAP_SIZE" "$swapsize" 1112 f_dprintf "$funcname: ZFSBOOT_BOOT_POOL_SIZE=[%s] bootsize=[%s]" \ 1113 "$ZFSBOOT_BOOT_POOL_SIZE" "$bootsize" 1114 1115 # 1116 # Destroy the pool in-case this is our second time 'round (case of 1117 # failure and installer presented ``Retry'' option to come back). 1118 # 1119 # NB: If we don't destroy the pool, later gpart(8) destroy commands 1120 # that try to clear existing partitions (see zfs_create_diskpart()) 1121 # will fail with a `Device Busy' error, leading to `GEOM exists'. 1122 # 1123 f_eval_catch -d $funcname zpool "$ZPOOL_DESTROY" "$zroot_name" 1124 1125 # 1126 # Prepare the disks and build pool device list(s) 1127 # 1128 f_dprintf "$funcname: Preparing disk partitions for ZFS pool..." 1129 1130 # Force 4K sectors using vfs.zfs.min_auto_ashift=12 1131 if [ "$ZFSBOOT_FORCE_4K_SECTORS" ]; then 1132 f_dprintf "$funcname: With 4K sectors..." 1133 f_eval_catch $funcname sysctl "$SYSCTL_ZFS_MIN_ASHIFT_12" \ 1134 || return $FAILURE 1135 sysctl kern.geom.part.mbr.enforce_chs=0 1136 fi 1137 local n=0 1138 for disk in $disks; do 1139 zfs_create_diskpart $disk $n || return $FAILURE 1140 # Now $bootpart, $targetpart, and $swappart are set (suffix 1141 # for $disk) 1142 if [ "$ZFSBOOT_BOOT_POOL" ]; then 1143 boot_vdevs="$boot_vdevs $disk$bootpart" 1144 fi 1145 zroot_vdevs="$zroot_vdevs $disk$targetpart" 1146 if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then 1147 zroot_vdevs="$zroot_vdevs.eli" 1148 fi 1149 1150 n=$(( $n + 1 )) 1151 done # disks 1152 1153 # 1154 # If we need/want a boot pool, create it 1155 # 1156 if [ "$ZFSBOOT_BOOT_POOL" ]; then 1157 local bootpool_vdevtype= # Calculated below 1158 local bootpool_options= # Calculated below 1159 local bootpool_name="$ZFSBOOT_BOOT_POOL_NAME" 1160 local bootpool="$BSDINSTALL_CHROOT/$bootpool_name" 1161 local zroot_key="${ZFSBOOT_GELI_KEY_FILE#/}" 1162 1163 f_dprintf "$funcname: Setting up boot pool..." 1164 [ "$ZFSBOOT_GELI_ENCRYPTION" ] && 1165 f_dprintf "$funcname: For encrypted root disk..." 1166 1167 # Create parent directory for boot pool 1168 f_eval_catch -d $funcname umount "$UMOUNT" /mnt 1169 f_eval_catch $funcname mount "$MOUNT_TYPE" tmpfs none \ 1170 $BSDINSTALL_CHROOT || return $FAILURE 1171 1172 # Create mirror across the boot partition on all disks 1173 local nvdevs 1174 f_count nvdevs $boot_vdevs 1175 [ $nvdevs -gt 1 ] && bootpool_vdevtype=mirror 1176 1177 create_options="$ZFSBOOT_BOOT_POOL_CREATE_OPTIONS" 1178 bootpool_options="-o altroot=$BSDINSTALL_CHROOT" 1179 bootpool_options="$bootpool_options $create_options" 1180 bootpool_options="$bootpool_options -m \"/$bootpool_name\" -f" 1181 f_eval_catch $funcname zpool "$ZPOOL_CREATE_WITH_OPTIONS" \ 1182 "$bootpool_options" "$bootpool_name" \ 1183 "$bootpool_vdevtype" "$boot_vdevs" || 1184 return $FAILURE 1185 1186 f_eval_catch $funcname mkdir "$MKDIR_P" "$bootpool/boot" || 1187 return $FAILURE 1188 1189 if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then 1190 # Generate an encryption key using random(4) 1191 f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \ 1192 /dev/random "$bootpool/$zroot_key" \ 1193 "bs=4096 count=1" || return $FAILURE 1194 f_eval_catch $funcname chmod "$CHMOD_MODE" \ 1195 go-wrx "$bootpool/$zroot_key" || 1196 return $FAILURE 1197 else 1198 # Clean up 1199 f_eval_catch $funcname zfs "$ZFS_UNMOUNT" \ 1200 "$bootpool_name" || return $FAILURE 1201 f_eval_catch -d $funcname umount "$UMOUNT" /mnt # tmpfs 1202 fi 1203 1204 fi 1205 1206 # 1207 # Create the geli(8) GEOMS 1208 # 1209 if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then 1210 # 1211 # Load the AES-NI kernel module to accelerate encryption 1212 # 1213 f_eval_catch -d $funcname kldload "$KLDLOAD" "aesni" 1214 # Prompt user for password (twice) 1215 if ! msg_enter_new_password="$msg_geli_password" \ 1216 f_dialog_input_password 1217 then 1218 f_dprintf "$funcname: User cancelled" 1219 f_show_err "$msg_user_cancelled" 1220 return $FAILURE 1221 fi 1222 1223 # Initialize geli(8) on each of the target partitions 1224 for disk in $disks; do 1225 f_dialog_info "$msg_geli_setup" \ 1226 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD 1227 if [ "$ZFSBOOT_BOOT_POOL" ]; then 1228 if ! echo "$pw_password" | f_eval_catch \ 1229 $funcname geli "$GELI_PASSWORD_INIT" \ 1230 "$bootpool/boot/$disk$targetpart.eli" \ 1231 AES-XTS "$bootpool/$zroot_key" \ 1232 $disk$targetpart 1233 then 1234 f_interactive || f_die 1235 unset pw_password # Sensitive info 1236 return $FAILURE 1237 fi 1238 if ! echo "$pw_password" | f_eval_catch \ 1239 $funcname geli "$GELI_ATTACH" \ 1240 "$bootpool/$zroot_key" $disk$targetpart 1241 then 1242 f_interactive || f_die 1243 unset pw_password # Sensitive info 1244 return $FAILURE 1245 fi 1246 else 1247 # With no bootpool, there is no place to store 1248 # the key files, use only a password 1249 if ! echo "$pw_password" | f_eval_catch \ 1250 $funcname geli \ 1251 "$GELI_PASSWORD_GELIBOOT_INIT" AES-XTS \ 1252 $disk$targetpart 1253 then 1254 f_interactive || f_die 1255 unset pw_password # Sensitive info 1256 return $FAILURE 1257 fi 1258 if ! echo "$pw_password" | f_eval_catch \ 1259 $funcname geli "$GELI_ATTACH_NOKEY" \ 1260 $disk$targetpart 1261 then 1262 f_interactive || f_die 1263 unset pw_password # Sensitive info 1264 return $FAILURE 1265 fi 1266 fi 1267 done 1268 unset pw_password # Sensitive info 1269 fi 1270 1271 if [ "$ZFSBOOT_BOOT_POOL" ]; then 1272 # Clean up 1273 f_eval_catch $funcname zfs "$ZFS_UNMOUNT" "$bootpool_name" || 1274 return $FAILURE 1275 f_eval_catch -d $funcname umount "$UMOUNT" /mnt # tmpfs 1276 fi 1277 1278 # 1279 # Create the gmirror(8) GEOMS for swap 1280 # 1281 if [ ${swapsize:-0} -gt 0 -a "$ZFSBOOT_SWAP_MIRROR" ]; then 1282 for disk in $disks; do 1283 swap_devs="$swap_devs $disk$swappart" 1284 done 1285 f_eval_catch $funcname gmirror "$SWAP_GMIRROR_LABEL" \ 1286 "$swap_devs" || return $FAILURE 1287 fi 1288 1289 # 1290 # Create the ZFS root pool with desired type and disk devices 1291 # 1292 f_dprintf "$funcname: Creating root pool..." 1293 create_options="$ZFSBOOT_POOL_CREATE_OPTIONS" 1294 if [ "$zroot_vdevtype" == "raid10" ]; then 1295 raid10_vdevs="" 1296 for vdev in $zroot_vdevs; do 1297 f_count nvdev $raid10_vdevs 1298 if [ $(( $nvdev % 3 )) -eq 0 ]; then 1299 raid10_vdevs="$raid10_vdevs mirror" 1300 fi 1301 raid10_vdevs="$raid10_vdevs $vdev" 1302 done 1303 f_eval_catch $funcname zpool "$ZPOOL_CREATE_WITH_OPTIONS" \ 1304 "-o altroot=$BSDINSTALL_CHROOT $create_options -m none -f" \ 1305 "$zroot_name" "" "$raid10_vdevs" || 1306 return $FAILURE 1307 else 1308 f_eval_catch $funcname zpool "$ZPOOL_CREATE_WITH_OPTIONS" \ 1309 "-o altroot=$BSDINSTALL_CHROOT $create_options -m none -f" \ 1310 "$zroot_name" "$zroot_vdevtype" "$zroot_vdevs" || 1311 return $FAILURE 1312 fi 1313 1314 # 1315 # Create ZFS dataset layout within the new root pool 1316 # 1317 f_dprintf "$funcname: Creating ZFS datasets..." 1318 echo "$ZFSBOOT_DATASETS" | while read dataset options; do 1319 # Skip blank lines and comments 1320 case "$dataset" in "#"*|"") continue; esac 1321 # Remove potential inline comments in options 1322 options="${options%%#*}" 1323 # Replace tabs with spaces 1324 f_replaceall "$options" " " " " options 1325 # Reduce contiguous runs of space to one single space 1326 oldoptions= 1327 while [ "$oldoptions" != "$options" ]; do 1328 oldoptions="$options" 1329 f_replaceall "$options" " " " " options 1330 done 1331 # Replace both commas and spaces with ` -o ' 1332 f_replaceall "$options" "[ ,]" " -o " options 1333 # Create the dataset with desired options 1334 f_eval_catch $funcname zfs "$ZFS_CREATE_WITH_OPTIONS" \ 1335 "${options:+-o $options}" "$zroot_name$dataset" || 1336 return $FAILURE 1337 done 1338 1339 # 1340 # Set a mountpoint for the root of the pool so newly created datasets 1341 # have a mountpoint to inherit 1342 # 1343 f_dprintf "$funcname: Setting mountpoint for root of the pool..." 1344 f_eval_catch $funcname zfs "$ZFS_SET" \ 1345 "mountpoint=/$zroot_name" "$zroot_name" || 1346 return $FAILURE 1347 1348 # Touch up permissions on the tmp directories 1349 f_dprintf "$funcname: Modifying directory permissions..." 1350 local dir 1351 for dir in /tmp /var/tmp; do 1352 f_eval_catch $funcname mkdir "$MKDIR_P" \ 1353 $BSDINSTALL_CHROOT$dir || return $FAILURE 1354 f_eval_catch $funcname chmod "$CHMOD_MODE" 1777 \ 1355 $BSDINSTALL_CHROOT$dir || return $FAILURE 1356 done 1357 1358 # Create symlink(s) 1359 if [ "$ZFSBOOT_BOOT_POOL" ]; then 1360 f_dprintf "$funcname: Creating /boot symlink for boot pool..." 1361 f_eval_catch $funcname ln "$LN_SF" "$bootpool_name/boot" \ 1362 $BSDINSTALL_CHROOT/boot || return $FAILURE 1363 fi 1364 1365 # Set bootfs property 1366 local zroot_bootfs="$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOTFS_NAME" 1367 f_dprintf "$funcname: Setting bootfs property..." 1368 f_eval_catch $funcname zpool "$ZPOOL_SET" \ 1369 "bootfs=\"$zroot_name/$zroot_bootfs\"" "$zroot_name" || 1370 return $FAILURE 1371 1372 # MBR boot loader touch-up 1373 if [ "$ZFSBOOT_PARTITION_SCHEME" = "MBR" ]; then 1374 # Export the pool(s) 1375 f_dprintf "$funcname: Temporarily exporting ZFS pool(s)..." 1376 f_eval_catch $funcname zpool "$ZPOOL_EXPORT" "$zroot_name" || 1377 return $FAILURE 1378 if [ "$ZFSBOOT_BOOT_POOL" ]; then 1379 f_eval_catch $funcname zpool "$ZPOOL_EXPORT" \ 1380 "$bootpool_name" || return $FAILURE 1381 fi 1382 1383 f_dprintf "$funcname: Updating MBR boot loader on disks..." 1384 # Stick the ZFS boot loader in the "convenient hole" after 1385 # the ZFS internal metadata 1386 for disk in $disks; do 1387 f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \ 1388 /boot/zfsboot /dev/$disk$bootpart \ 1389 "skip=1 seek=1024" || return $FAILURE 1390 done 1391 1392 # Re-import the ZFS pool(s) 1393 f_dprintf "$funcname: Re-importing ZFS pool(s)..." 1394 f_eval_catch $funcname zpool "$ZPOOL_IMPORT_WITH_OPTIONS" \ 1395 "-o altroot=\"$BSDINSTALL_CHROOT\"" "$zroot_name" || 1396 return $FAILURE 1397 if [ "$ZFSBOOT_BOOT_POOL" ]; then 1398 f_eval_catch $funcname zpool "$ZPOOL_IMPORT_WITH_OPTIONS" \ 1399 "-o altroot=\"$BSDINSTALL_CHROOT\"" \ 1400 "$bootpool_name" || return $FAILURE 1401 fi 1402 fi 1403 1404 # While this is apparently not needed, it seems to help MBR 1405 f_dprintf "$funcname: Configuring zpool.cache for zroot..." 1406 f_eval_catch $funcname mkdir "$MKDIR_P" $BSDINSTALL_CHROOT/boot/zfs || 1407 return $FAILURE 1408 f_eval_catch $funcname zpool "$ZPOOL_SET" \ 1409 "cachefile=\"$BSDINSTALL_CHROOT/boot/zfs/zpool.cache\"" \ 1410 "$zroot_name" || return $FAILURE 1411 1412 # 1413 # Set canmount=noauto so that the default Boot Environment (BE) does not 1414 # get mounted if a different BE is selected from the beastie menu 1415 # 1416 f_dprintf "$funcname: Set canmount=noauto for the root of the pool..." 1417 f_eval_catch $funcname zfs "$ZFS_SET" "canmount=noauto" \ 1418 "$zroot_name/$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOTFS_NAME" 1419 1420 # Last, but not least... required lines for rc.conf(5)/loader.conf(5) 1421 # NOTE: We later concatenate these into their destination 1422 f_dprintf "%s: Configuring rc.conf(5)/loader.conf(5) additions..." \ 1423 "$funcname" 1424 f_eval_catch $funcname echo "$ECHO_APPEND" 'zfs_enable=\"YES\"' \ 1425 $BSDINSTALL_TMPETC/rc.conf.zfs || return $FAILURE 1426 f_eval_catch $funcname echo "$ECHO_APPEND" \ 1427 'kern.geom.label.disk_ident.enable=\"0\"' \ 1428 $BSDINSTALL_TMPBOOT/loader.conf.zfs || return $FAILURE 1429 f_eval_catch $funcname echo "$ECHO_APPEND" \ 1430 'kern.geom.label.gptid.enable=\"0\"' \ 1431 $BSDINSTALL_TMPBOOT/loader.conf.zfs || return $FAILURE 1432 1433 if [ "$ZFSBOOT_SWAP_MIRROR" ]; then 1434 f_eval_catch $funcname echo "$ECHO_APPEND" \ 1435 'geom_mirror_load=\"YES\"' \ 1436 $BSDINSTALL_TMPBOOT/loader.conf.gmirror || 1437 return $FAILURE 1438 fi 1439 1440 # We're all done unless we should go on to do encryption 1441 [ "$ZFSBOOT_GELI_ENCRYPTION" ] || return $SUCCESS 1442 1443 # 1444 # Configure geli(8)-based encryption 1445 # 1446 f_dprintf "$funcname: Configuring disk encryption..." 1447 f_eval_catch $funcname echo "$ECHO_APPEND" 'aesni_load=\"YES\"' \ 1448 $BSDINSTALL_TMPBOOT/loader.conf.aesni || return $FAILURE 1449 f_eval_catch $funcname echo "$ECHO_APPEND" 'geom_eli_load=\"YES\"' \ 1450 $BSDINSTALL_TMPBOOT/loader.conf.geli || return $FAILURE 1451 1452 # We're all done unless we should go on for boot pool 1453 [ "$ZFSBOOT_BOOT_POOL" ] || return $SUCCESS 1454 1455 for disk in $disks; do 1456 f_eval_catch $funcname printf "$PRINTF_CONF" \ 1457 geli_%s_keyfile0_load "$disk$targetpart YES" \ 1458 $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart || 1459 return $FAILURE 1460 f_eval_catch $funcname printf "$PRINTF_CONF" \ 1461 geli_%s_keyfile0_type \ 1462 "$disk$targetpart $disk$targetpart:geli_keyfile0" \ 1463 $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart || 1464 return $FAILURE 1465 f_eval_catch $funcname printf "$PRINTF_CONF" \ 1466 geli_%s_keyfile0_name \ 1467 "$disk$targetpart \"$ZFSBOOT_GELI_KEY_FILE\"" \ 1468 $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart || 1469 return $FAILURE 1470 done 1471 1472 # Set cachefile for boot pool so it auto-imports at system start 1473 f_dprintf "$funcname: Configuring zpool.cache for boot pool..." 1474 f_eval_catch $funcname zpool "$ZPOOL_SET" \ 1475 "cachefile=\"$BSDINSTALL_CHROOT/boot/zfs/zpool.cache\"" \ 1476 "$bootpool_name" || return $FAILURE 1477 1478 # Some additional geli(8) requirements for loader.conf(5) 1479 for option in \ 1480 'zpool_cache_load=\"YES\"' \ 1481 'zpool_cache_type=\"/boot/zfs/zpool.cache\"' \ 1482 'zpool_cache_name=\"/boot/zfs/zpool.cache\"' \ 1483 'geom_eli_passphrase_prompt=\"YES\"' \ 1484 ; do 1485 f_eval_catch $funcname echo "$ECHO_APPEND" "$option" \ 1486 $BSDINSTALL_TMPBOOT/loader.conf.zfs || 1487 return $FAILURE 1488 done 1489 f_eval_catch $funcname printf "$PRINTF_CONF" vfs.root.mountfrom \ 1490 "\"zfs:$zroot_name/$zroot_bootfs\"" \ 1491 $BSDINSTALL_TMPBOOT/loader.conf.root || return $FAILURE 1492 1493 return $SUCCESS 1494} 1495 1496# dialog_menu_diskinfo 1497# 1498# Prompt the user to select a disk and then provide detailed info on it. 1499# 1500dialog_menu_diskinfo() 1501{ 1502 local device disk 1503 1504 # 1505 # Break from loop when user cancels disk selection 1506 # 1507 while :; do 1508 device=$( msg_cancel="$msg_back" f_device_menu \ 1509 "$DIALOG_TITLE" "$msg_select_a_disk_device" "" \ 1510 $DEVICE_TYPE_DISK 2>&1 ) || break 1511 $device get name disk 1512 1513 # Show gpart(8) `show' and camcontrol(8) `inquiry' data 1514 f_show_msg "$msg_detailed_disk_info" \ 1515 "$disk" "$( gpart show $disk 2> /dev/null )" \ 1516 "$disk" "$( camcontrol inquiry $disk 2> /dev/null )" \ 1517 "$disk" "$( camcontrol identify $disk 2> /dev/null )" 1518 done 1519 1520 return $SUCCESS 1521} 1522 1523############################################################ MAIN 1524 1525# 1526# Initialize 1527# 1528f_dialog_title "$msg_zfs_configuration" 1529f_dialog_backtitle "$msg_freebsd_installer" 1530 1531# User may have specifically requested ZFS-related operations be interactive 1532! f_interactive && f_zfsinteractive && unset $VAR_NONINTERACTIVE 1533 1534# 1535# Debugging 1536# 1537f_dprintf "BSDINSTALL_CHROOT=[%s]" "$BSDINSTALL_CHROOT" 1538f_dprintf "BSDINSTALL_TMPETC=[%s]" "$BSDINSTALL_TMPETC" 1539f_dprintf "FSTAB_FMT=[%s]" "$FSTAB_FMT" 1540 1541# 1542# If the system was booted with UEFI, set the default boot type to UEFI 1543# 1544bootmethod=$( sysctl -n machdep.bootmethod ) 1545f_dprintf "machdep.bootmethod=[%s]" "$bootmethod" 1546if [ "$bootmethod" = "UEFI" ]; then 1547 : ${ZFSBOOT_BOOT_TYPE:=BIOS+UEFI} 1548 : ${ZFSBOOT_PARTITION_SCHEME:=GPT} 1549else 1550 : ${ZFSBOOT_BOOT_TYPE:=BIOS} 1551 : ${ZFSBOOT_PARTITION_SCHEME:=GPT} 1552fi 1553 1554# 1555# Loop over the main menu until we've accomplished what we came here to do 1556# 1557while :; do 1558 if ! f_interactive; then 1559 retval=$DIALOG_OK 1560 mtag=">>> $msg_install" 1561 else 1562 dialog_menu_main 1563 retval=$? 1564 f_dialog_menutag_fetch mtag 1565 fi 1566 1567 f_dprintf "retval=%u mtag=[%s]" $retval "$mtag" 1568 [ $retval -eq $DIALOG_OK ] || f_die 1569 1570 case "$mtag" in 1571 ">>> $msg_install") 1572 # 1573 # First, validate the user's selections 1574 # 1575 1576 # Make sure they gave us a name for the pool 1577 if [ ! "$ZFSBOOT_POOL_NAME" ]; then 1578 f_dprintf "Pool name cannot be empty." 1579 f_show_err "$msg_pool_name_cannot_be_empty" 1580 continue 1581 fi 1582 1583 # Validate vdev type against number of disks selected/scripted 1584 # (also validates that ZFSBOOT_DISKS are real [probed] disks) 1585 # NB: dialog_menu_layout supports running non-interactively 1586 dialog_menu_layout || continue 1587 1588 # Make sure each disk will have room for ZFS 1589 if f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize && 1590 f_expand_number "$ZFSBOOT_BOOT_POOL_SIZE" bootsize && 1591 f_expand_number "1g" zpoolmin 1592 then 1593 minsize=$(( $swapsize + $zpoolmin )) teeny_disks= 1594 [ "$ZFSBOOT_BOOT_POOL" ] && 1595 minsize=$(( $minsize + $bootsize )) 1596 for disk in $ZFSBOOT_DISKS; do 1597 debug= f_device_find -1 \ 1598 $disk $DEVICE_TYPE_DISK device 1599 $device get capacity disksize || continue 1600 [ ${disksize:-0} -ge 0 ] || disksize=0 1601 [ $disksize -lt $minsize ] && 1602 teeny_disks="$teeny_disks $disk" 1603 done 1604 if [ "$teeny_disks" ]; then 1605 f_dprintf "swapsize=[%s] bootsize[%s] %s" \ 1606 "$ZFSBOOT_SWAP_SIZE" \ 1607 "$ZFSBOOT_BOOT_POOL_SIZE" \ 1608 "minsize=[$minsize]" 1609 f_dprintf "These disks are too small: %s" \ 1610 "$teeny_disks" 1611 f_show_err "$msg_these_disks_are_too_small" \ 1612 "$ZFSBOOT_SWAP_SIZE" \ 1613 "$ZFSBOOT_BOOT_POOL_SIZE" \ 1614 "$teeny_disks" 1615 continue 1616 fi 1617 fi 1618 1619 # 1620 # Last Chance! 1621 # 1622 if f_interactive; then 1623 dialog_last_chance $ZFSBOOT_DISKS || continue 1624 fi 1625 1626 # 1627 # Let's do this 1628 # 1629 1630 vdev_type="$ZFSBOOT_VDEV_TYPE" 1631 1632 # Blank the vdev type for the default layout 1633 [ "$vdev_type" = "stripe" ] && vdev_type= 1634 1635 zfs_create_boot "$ZFSBOOT_POOL_NAME" \ 1636 "$vdev_type" $ZFSBOOT_DISKS || continue 1637 1638 break # to success 1639 ;; 1640 ?" $msg_pool_type_disks") 1641 ZFSBOOT_CONFIRM_LAYOUT=1 1642 dialog_menu_layout 1643 # User has poked settings, disable later confirmation 1644 ZFSBOOT_CONFIRM_LAYOUT= 1645 ;; 1646 "- $msg_rescan_devices") f_device_rescan ;; 1647 "- $msg_disk_info") dialog_menu_diskinfo ;; 1648 ?" $msg_pool_name") 1649 # Prompt the user to input/change the name for the new pool 1650 f_dialog_input input \ 1651 "$msg_please_enter_a_name_for_your_zpool" \ 1652 "$ZFSBOOT_POOL_NAME" && 1653 ZFSBOOT_POOL_NAME="$input" 1654 ;; 1655 ?" $msg_force_4k_sectors") 1656 # Toggle the variable referenced both by the menu and later 1657 if [ "$ZFSBOOT_FORCE_4K_SECTORS" ]; then 1658 ZFSBOOT_FORCE_4K_SECTORS= 1659 else 1660 ZFSBOOT_FORCE_4K_SECTORS=1 1661 fi 1662 ;; 1663 ?" $msg_encrypt_disks") 1664 # Toggle the variable referenced both by the menu and later 1665 if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then 1666 ZFSBOOT_GELI_ENCRYPTION= 1667 else 1668 ZFSBOOT_FORCE_4K_SECTORS=1 1669 ZFSBOOT_GELI_ENCRYPTION=1 1670 fi 1671 ;; 1672 ?" $msg_partition_scheme") 1673 # Toggle between GPT (BIOS), GPT (UEFI) and MBR 1674 if [ "$ZFSBOOT_PARTITION_SCHEME" = "GPT" -a "$ZFSBOOT_BOOT_TYPE" = "BIOS" ]; then 1675 ZFSBOOT_PARTITION_SCHEME="GPT" 1676 ZFSBOOT_BOOT_TYPE="UEFI" 1677 elif [ "$ZFSBOOT_PARTITION_SCHEME" = "GPT" -a "$ZFSBOOT_BOOT_TYPE" = "UEFI" ]; then 1678 ZFSBOOT_PARTITION_SCHEME="GPT" 1679 ZFSBOOT_BOOT_TYPE="BIOS+UEFI" 1680 elif [ "$ZFSBOOT_PARTITION_SCHEME" = "GPT" ]; then 1681 ZFSBOOT_PARTITION_SCHEME="MBR" 1682 ZFSBOOT_BOOT_TYPE="BIOS" 1683 elif [ "$ZFSBOOT_PARTITION_SCHEME" = "MBR" ]; then 1684 ZFSBOOT_PARTITION_SCHEME="GPT + Active" 1685 ZFSBOOT_BOOT_TYPE="BIOS" 1686 elif [ "$ZFSBOOT_PARTITION_SCHEME" = "GPT + Active" ]; then 1687 ZFSBOOT_PARTITION_SCHEME="GPT + Lenovo Fix" 1688 ZFSBOOT_BOOT_TYPE="BIOS" 1689 else 1690 ZFSBOOT_PARTITION_SCHEME="GPT" 1691 ZFSBOOT_BOOT_TYPE="BIOS" 1692 fi 1693 ;; 1694 ?" $msg_swap_size") 1695 # Prompt the user to input/change the swap size for each disk 1696 while :; do 1697 f_dialog_input input \ 1698 "$msg_please_enter_amount_of_swap_space" \ 1699 "$ZFSBOOT_SWAP_SIZE" && 1700 ZFSBOOT_SWAP_SIZE="${input:-0}" 1701 if f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize 1702 then 1703 if [ $swapsize -ne 0 -a $swapsize -lt 104857600 ]; then 1704 f_show_err "$msg_swap_toosmall" \ 1705 "$ZFSBOOT_SWAP_SIZE" 1706 continue; 1707 else 1708 break; 1709 fi 1710 else 1711 f_show_err "$msg_swap_invalid" \ 1712 "$ZFSBOOT_SWAP_SIZE" 1713 continue; 1714 fi 1715 done 1716 ;; 1717 ?" $msg_swap_mirror") 1718 # Toggle the variable referenced both by the menu and later 1719 if [ "$ZFSBOOT_SWAP_MIRROR" ]; then 1720 ZFSBOOT_SWAP_MIRROR= 1721 else 1722 ZFSBOOT_SWAP_MIRROR=1 1723 fi 1724 ;; 1725 ?" $msg_swap_encrypt") 1726 # Toggle the variable referenced both by the menu and later 1727 if [ "$ZFSBOOT_SWAP_ENCRYPTION" ]; then 1728 ZFSBOOT_SWAP_ENCRYPTION= 1729 else 1730 ZFSBOOT_SWAP_ENCRYPTION=1 1731 fi 1732 ;; 1733 esac 1734done 1735 1736exit $SUCCESS 1737 1738################################################################################ 1739# END 1740################################################################################ 1741