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