28c28
< # $FreeBSD: stable/10/usr.sbin/bsdinstall/scripts/zfsboot 257507 2013-11-01 15:54:57Z gjb $
---
> # $FreeBSD: stable/10/usr.sbin/bsdinstall/scripts/zfsboot 258421 2013-11-21 03:40:52Z dteske $
50c50
< : ${ZFSBOOT_BEROOT_NAME:=bootenv}
---
> : ${ZFSBOOT_BEROOT_NAME:=ROOT}
70c70
< : ${ZFSBOOT_GELI_ENCRYPTION:=}
---
> : ${ZFSBOOT_GELI_ENCRYPTION=}
104c104
< # Default ZFS layout for root zpool
---
> # Default ZFS datasets for root zpool
122,123d121
< /usr/local # local files (i.e. from packages) separate from base system
<
125c123
< /usr/home setuid=off
---
> /usr/home # NB: /home is a symlink to /usr/home
129,130d126
< /usr/ports/distfiles compression=off,exec=off,setuid=off
< /usr/ports/packages compression=off,exec=off,setuid=off
134d129
< /usr/obj # Object files
139,141d133
< /var/db exec=off,setuid=off
< /var/db/pkg compression=lz4,exec=off,setuid=off
< /var/empty exec=off,setuid=off
143,144d134
< /var/mail compression=lz4,exec=off,setuid=off
< /var/run exec=off,setuid=off
147a138,143
> #
> # If interactive and the user has not explicitly chosen a vdev type or disks,
> # make the user confirm scripted/default choices when proceeding to install.
> #
> : ${ZFSBOOT_CONFIRM_LAYOUT:=1}
>
150a147,183
> # Format of a line in printf(1) syntax to add to fstab(5)
> #
> FSTAB_FMT="%s\t\t%s\t%s\t%s\t\t%s\t%s\n"
>
> #
> # Command strings for various tasks
> #
> CHMOD_MODE='chmod %s "%s"'
> DD_WITH_OPTIONS='dd if="%s" of="%s" %s'
> ECHO_APPEND='echo "%s" >> "%s"'
> GELI_ATTACH='geli attach -j - -k "%s" "%s"'
> GELI_PASSWORD_INIT='geli init -b -B "%s" -e %s -J - -K "%s" -l 256 -s 4096 "%s"'
> GNOP_CREATE='gnop create -S 4096 "%s"'
> GPART_ADD='gpart add -t %s "%s"'
> GPART_ADD_INDEX='gpart add -i %s -t %s "%s"'
> GPART_ADD_INDEX_WITH_SIZE='gpart add -i %s -t %s -s %s "%s"'
> GPART_ADD_LABEL='gpart add -l %s -t %s "%s"'
> GPART_ADD_LABEL_WITH_SIZE='gpart add -l %s -t %s -s %s "%s"'
> GPART_BOOTCODE='gpart bootcode -b "%s" "%s"'
> GPART_BOOTCODE_PART='gpart bootcode -b "%s" -p "%s" -i %s "%s"'
> GPART_CREATE='gpart create -s %s "%s"'
> GPART_SET_ACTIVE='gpart set -a active -i %s "%s"'
> LN_SF='ln -sf "%s" "%s"'
> MKDIR_P='mkdir -p "%s"'
> MOUNT_TYPE='mount -t %s "%s" "%s"'
> PRINTF_CONF="printf '%s=\"%%s\"\\\n' %s >> \"%s\""
> PRINTF_FSTAB='printf "$FSTAB_FMT" "%s" "%s" "%s" "%s" "%s" "%s" >> "%s"'
> SHELL_TRUNCATE=':> "%s"'
> ZFS_CREATE_WITH_OPTIONS='zfs create %s "%s"'
> ZFS_SET='zfs set "%s" "%s"'
> ZFS_UNMOUNT='zfs unmount "%s"'
> ZPOOL_CREATE_WITH_OPTIONS='zpool create %s "%s" %s %s'
> ZPOOL_EXPORT='zpool export "%s"'
> ZPOOL_IMPORT_WITH_OPTIONS='zpool import %s "%s"'
> ZPOOL_SET='zpool set %s "%s"'
>
> #
155a189
> msg_an_unknown_error_occurred="An unknown error occurred"
158c192
< msg_change="Change Selection"
---
> msg_change_selection="Change Selection"
160,162d193
< msg_create="Install"
< msg_create_desc="Proceed with Installation"
< msg_create_help="Create ZFS boot pool with displayed options"
166,167c197,199
< msg_disks_to_use="Disks To Use"
< msg_disks_to_use_help="Choose which disks to use for the Virtual Device (Required)"
---
> msg_encrypt_disks="Encrypt Disks?"
> msg_encrypt_disks_help="Use geli(8) to encrypt all data partitions"
> msg_error="Error"
171,172d202
< msg_geli_encryption="Encrypt Disks?"
< msg_geli_encryption_help="Use geli(8) to encrypt all data partitions"
174a205,211
> msg_install="Install"
> msg_install_desc="Proceed with Installation"
> msg_install_help="Create ZFS boot pool with displayed options"
> msg_invalid_disk_argument="Invalid disk argument \`%s'"
> msg_invalid_geli_boot_size="Invalid geli(8) boot size \`%s'"
> msg_invalid_index_argument="Invalid index argument \`%s'"
> msg_invalid_swap_size="Invalid swap size \`%s'"
176,178c213,214
< msg_invalid_virtual_device_type_help="Select another Virtual Device type or Cancel to\nreturn to the ZFS menu. From there you can select\nmore disks or rescan for additional devices."
< msg_last_chance_are_you_sure="Last Chance! Are you sure you want to destroy the current contents of the following disks:\n%s"
< msg_last_chance_are_you_sure_color="\\\\ZrLast Chance!\\\\ZR Are you \\\\Z1sure\\\\Zn you want to \\\\Zr\\\\Z1destroy\\\\Zn the current contents of the following disks:\n%s"
---
> msg_last_chance_are_you_sure="Last Chance! Are you sure you want to destroy\nthe current contents of the following disks:\n\n %s"
> msg_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'
180a217,218
> msg_missing_disk_arguments="missing disk arguments"
> msg_missing_one_or_more_scripted_disks="Missing one or more scripted disks!"
184c222,225
< msg_not_enough_disks_selected="Not enough disks selected. (%u < %u wanted)"
---
> msg_not_enough_disks_selected="Not enough disks selected. (%u < %u minimum)"
> msg_null_disk_argument="NULL disk argument"
> msg_null_index_argument="NULL index argument"
> msg_null_poolname="NULL poolname"
193a235,236
> msg_pool_type_disks="Pool Type/Disks:"
> msg_pool_type_disks_help="Choose type of ZFS Virtual Device and disks to use (Required)"
210c253,256
< msg_these_disks_are_too_small="These disks are too small given the amount of requested\nswap (%s) and/or GELI (%s) partitions, which would take\n50%% or more (not recommended) of each of the following\nselected disk devices:\n\n %s\n\nRecommend changing partition size(s) and/or selecting a\ndifferent set of devices."
---
> msg_these_disks_are_too_small="These disks are too small given the amount of requested\nswap (%s) and/or geli(8) (%s) partitions, which would\ntake 50%% or more of each of the following selected disk\ndevices (not recommended):\n\n %s\n\nRecommend changing partition size(s) and/or selecting a\ndifferent set of devices."
> msg_unable_to_get_disk_capacity="Unable to get disk capacity of \`%s'"
> msg_unsupported_partition_scheme="%s is an unsupported partition scheme"
> msg_user_cancelled="User Cancelled."
213,214d258
< msg_zfs_vdev_type="ZFS VDev Type"
< msg_zfs_vdev_type_help="Select type of ZFS Virtual Device to create"
230a275,276
> local disks n=$( set -- $ZFSBOOT_DISKS; echo $# )
> { [ $n -eq 1 ] && disks=disk; } || disks=disks # grammar
232,233c278,281
< '>>> $msg_create' '$msg_create_desc'
< '$msg_create_help'
---
> '>>> $msg_install' '$msg_install_desc'
> '$msg_install_help'
> 'T $msg_pool_type_disks' '$ZFSBOOT_VDEV_TYPE: $n $disks'
> '$msg_pool_type_disks_help'
238c286
< '1 $msg_pool_name' '$ZFSBOOT_POOL_NAME'
---
> 'N $msg_pool_name' '$ZFSBOOT_POOL_NAME'
240,243d287
< '2 $msg_disks_to_use' '$ZFSBOOT_DISKS'
< '$msg_disks_to_use_help'
< '3 $msg_zfs_vdev_type' '$ZFSBOOT_VDEV_TYPE'
< '$msg_zfs_vdev_type_help'
246,248c290,292
< '5 $msg_geli_encryption' '$usegeli'
< '$msg_geli_encryption_help'
< '6 $msg_partition_scheme' '$ZFSBOOT_PARTITION_SCHEME'
---
> 'E $msg_encrypt_disks' '$usegeli'
> '$msg_encrypt_disks_help'
> 'P $msg_partition_scheme' '$ZFSBOOT_PARTITION_SCHEME'
250c294
< '7 $msg_swap_size' '$ZFSBOOT_SWAP_SIZE'
---
> 'S $msg_swap_size' '$ZFSBOOT_SWAP_SIZE'
287c331
< # dialog_edit_disks
---
> # dialog_last_chance $disks ...
289c333,335
< # Edit the list of disks to be used by the ZFS boot pool.
---
> # Display a list of the disks that the user is about to destroy. The default
> # action is to return error status unless the user explicitly (non-default)
> # selects "Yes" from the noyes dialog.
291c337
< dialog_edit_disks()
---
> dialog_last_chance()
295,298c341,342
< local prompt="$msg_please_select_one_or_more_disks"
< local check_list= # Calculated below
< local hline="$hline_arrows_space_tab_enter"
< local dev vardev disks=
---
> local prompt # Calculated below
> local hline="$hline_arrows_tab_enter"
300,306c344,356
< #
< # Get a [new] list of disk devices
< #
< f_device_find "" $DEVICE_TYPE_DISK disks
< if [ ! "$disks" ]; then
< f_show_msg "$msg_no_disks_present_to_configure"
< return $FAILURE
---
> local height=8 width=50 prefix=" "
> local plen=${#prefix} list= line=
> local max_width=$(( $width - 3 - $plen ))
>
> local yes no defaultno extra_args format
> if [ "$USE_XDIALOG" ]; then
> yes=ok no=cancel defaultno=default-no
> extra_args="--wrap --left"
> format="$msg_last_chance_are_you_sure"
> else
> yes=yes no=no defaultno=defaultno
> extra_args="--colors --cr-wrap"
> format="$msg_last_chance_are_you_sure_color"
309,318c359,374
< # Lets sort the disks array to be more user friendly
< disks=$( echo "$disks" | tr ' ' '\n' | sort | tr '\n' ' ' )
<
< #
< # Loop through the list of selected disks and create temporary local
< # variables mapping their status onto an up-to-date list of disks.
< #
< for dev in $ZFSBOOT_DISKS; do
< f_str2varname "$dev" vardev
< local _${vardev}_status=on
---
> local disk line_width
> for disk in $*; do
> if [ "$line" ]; then
> line_width=${#line}
> else
> line_width=$plen
> fi
> line_width=$(( $line_width + 1 + ${#disk} ))
> # Add newline before disk if it would exceed max_width
> if [ $line_width -gt $max_width ]; then
> list="$list$line\n"
> line="$prefix"
> height=$(( $height + 1 ))
> fi
> # Add the disk to the list
> line="$line $disk"
319a376,380
> # Append the left-overs
> if [ "${line#$prefix}" ]; then
> list="$list$line"
> height=$(( $height + 1 ))
> fi
321,332c382,383
< #
< # Create the checklist menu of discovered disk devices
< #
< local on_off
< for dev in $disks; do
< local desc=
< device_$dev get desc desc
< f_shell_escape "$desc" desc
< f_str2varname "$dev" vardev
< f_getvar _${vardev}_status:-off on_off
< check_list="$check_list '$dev' '$desc' $on_off"
< done
---
> # Add height for Xdialog(1)
> [ "$USE_XDIALOG" ] && height=$(( $height + $height / 5 + 3 ))
334,356c385,395
< #
< # Prompt the user to check some disks
< #
< local height width rows
< eval f_dialog_checklist_size height width rows \
< \"\$title\" \"\$btitle\" \"\$prompt\" \"\$hline\" $check_list
< disks=$( eval $DIALOG \
< --title \"\$DIALOG_TITLE\" \
< --backtitle \"\$DIALOG_BACKTITLE\" \
< --hline \"\$hline\" \
< --ok-label \"\$msg_ok\" \
< --cancel-label \"\$msg_cancel\" \
< --checklist \"\$prompt\" \
< $height $width $rows \
< $check_list \
< 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
< ) || return $?
< # Exit if user either pressed ESC or chose Cancel/No
< f_dialog_data_sanitize disks
<
< ZFSBOOT_DISKS="$disks"
<
< return $DIALOG_OK
---
> prompt=$( printf "$format" "$list" )
> f_dprintf "%s: Last Chance!" "$0"
> $DIALOG \
> --title "$title" \
> --backtitle "$btitle" \
> --hline "$hline" \
> --$defaultno \
> --$yes-label "$msg_yes" \
> --$no-label "$msg_no" \
> $extra_args \
> --yesno "$prompt" $height $width
359c398
< # dialog_menu_vdev
---
> # dialog_menu_layout
361c400,401
< # Prompt the user to select a a Virtual Device type.
---
> # Configure Virtual Device type and disks to use for the ZFS boot pool. User
> # must select enough disks to satisfy the chosen vdev type.
363c403
< dialog_menu_vdev()
---
> dialog_menu_layout()
364a405
> local funcname=dialog_menu_layout
367,377c408,410
< local prompt="$msg_select_virtual_device_type"
<
< # Make sure [potentially scripted] selections are real
< real_disks=
< for disk in $ZFSBOOT_DISKS; do
< f_struct device_$disk && real_disks="$real_disks $disk"
< done
< # Make sure we have at least one real disk selected
< ndisks=$( set -- $real_disks; echo $# )
<
< local menu_list="
---
> local vdev_prompt="$msg_select_virtual_device_type"
> local disk_prompt="$msg_please_select_one_or_more_disks"
> local vdev_menu_list="
383a417,419
> local disk_check_list= # Calculated below
> local vdev_hline="$hline_arrows_tab_enter"
> local disk_hline="$hline_arrows_space_tab_enter"
385,423c421,423
< local defaultitem="$ZFSBOOT_VDEV_TYPE"
< local hline="$hline_arrows_tab_enter"
< local error_msg revalidate_choice
<
< local mheight mwidth mrows
< eval f_dialog_menu_size mheight mwidth mrows \
< \"\$title\" \"\$btitle\" \"\$prompt\" \"\$hline\" $menu_list
< local iheight iwidth
< f_dialog_infobox_size iheight iwidth \
< "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$msg_processing_selection"
<
< local menu_choice
< menu_choice=$( eval $DIALOG \
< --title \"\$title\" \
< --backtitle \"\$btitle\" \
< --hline \"\$hline\" \
< --ok-label \"\$msg_ok\" \
< --cancel-label \"\$msg_cancel\" \
< --item-help \
< --default-item \"\$defaultitem\" \
< --menu \"\$prompt\" \
< $mheight $mwidth $mrows \
< $menu_list \
< --and-widget \
< ${USE_XDIALOG:+--no-buttons} \
< --infobox \"\$msg_processing_selection\" \
< $iheight $iwidth \
< 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
< ) || return $FAILURE
< f_dialog_data_sanitize menu_choice
< sleep 0.5 # Give time to read `--and-widget --info-box'
<
< # Make sure we have enough disks for the desired vdev type
< case "$menu_choice" in
< stripe) want_disks=1 ;;
< mirror) want_disks=2 ;;
< raidz1) want_disks=3 ;;
< raidz2) want_disks=4 ;;
< raidz3) want_disks=5 ;;
---
> # Warn the user if vdev type is not valid
> case "$ZFSBOOT_VDEV_TYPE" in
> stripe|mirror|raidz1|raidz2|raidz3) : known good ;;
425,427c425,429
< f_show_msg "$msg_invalid_virtual_device_type" \
< "$menu_choice"
< continue
---
> f_dprintf "%s: Invalid virtual device type \`%s'" \
> $funcname "$ZFSBOOT_VDEV_TYPE"
> f_show_err "$msg_invalid_virtual_device_type" \
> "$ZFSBOOT_VDEV_TYPE"
> f_interactive || return $FAILURE
429,437c431,445
< if [ $ndisks -lt $want_disks ]; then
< msg_yes="$msg_change" msg_no="$msg_cancel" f_yesno \
< "%s: $msg_not_enough_disks_selected\n%s" \
< "$menu_choice" $ndisks $want_disks \
< "$msg_invalid_virtual_device_type_help" ||
< return $FAILURE
< dialog_menu_vdev
< else
< ZFSBOOT_VDEV_TYPE="$menu_choice"
---
>
> # Calculate size of vdev menu once only
> local vheight vwidth vrows
> eval f_dialog_menu_with_help_size vheight vwidth vrows \
> \"\$title\" \"\$btitle\" \"\$vdev_prompt\" \"\$vdev_hline\" \
> $vdev_menu_list
>
> # Get a list of probed disk devices
> local disks=
> f_device_find "" $DEVICE_TYPE_DISK disks
> f_dprintf "$funcname: disks=[%s]" "$disks"
> if [ ! "$disks" ]; then
> f_dprintf "No disk(s) present to configure"
> f_show_err "$msg_no_disks_present_to_configure"
> return $FAILURE
438a447,603
>
> # Lets sort the disks array to be more user friendly
> disks=$( echo "$disks" | tr ' ' '\n' | sort | tr '\n' ' ' )
>
> #
> # Operate in a loop so we can (if interactive) repeat if not enough
> # disks are selected to satisfy the chosen vdev type or user wants to
> # back-up to the previous menu.
> #
> local vardisk ndisks onoff selections vdev_choice
> while :; do
> #
> # Confirm the vdev type that was selected
> #
> if f_interactive && [ "$ZFSBOOT_CONFIRM_LAYOUT" ]; then
> vdev_choice=$( eval $DIALOG \
> --title \"\$title\" \
> --backtitle \"\$btitle\" \
> --hline \"\$vdev_hline\" \
> --ok-label \"\$msg_ok\" \
> --cancel-label \"\$msg_cancel\" \
> --item-help \
> --default-item \"\$ZFSBOOT_VDEV_TYPE\" \
> --menu \"\$vdev_prompt\" \
> $vheight $vwidth $vrows \
> $vdev_menu_list \
> 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
> ) || return $?
> # Exit if user pressed ESC or chose Cancel/No
> f_dialog_data_sanitize vdev_choice
>
> ZFSBOOT_VDEV_TYPE="$vdev_choice"
> f_dprintf "$funcname: ZFSBOOT_VDEV_TYPE=[%s]" \
> "$ZFSBOOT_VDEV_TYPE"
> fi
>
> # Determine the number of disks needed for this vdev type
> local want_disks=0
> case "$ZFSBOOT_VDEV_TYPE" in
> stripe) want_disks=1 ;;
> mirror) want_disks=2 ;;
> raidz1) want_disks=3 ;;
> raidz2) want_disks=4 ;;
> raidz3) want_disks=5 ;;
> esac
>
> # Warn the user if any scripted disks are invalid
> local disk valid_disks=
> local all_valid=${ZFSBOOT_DISKS:+1} # optimism
> for disk in $ZFSBOOT_DISKS; do
> if f_struct device_$disk; then
> valid_disks="$valid_disks $disk"
> continue
> fi
> f_dprintf "$funcname: \`%s' is not a real disk" "$disk"
> all_valid=
> done
> if [ ! "$all_valid" ]; then
> if [ "$ZFSBOOT_DISKS" ]; then
> f_show_err \
> "$msg_missing_one_or_more_scripted_disks"
> else
> f_dprintf "No disks selected."
> f_interactive ||
> f_show_err "$msg_no_disks_selected"
> fi
> f_interactive || return $FAILURE
> fi
> ZFSBOOT_DISKS="${valid_disks# }"
>
> #
> # Short-circuit if we're running non-interactively
> #
> if ! f_interactive || [ ! "$ZFSBOOT_CONFIRM_LAYOUT" ]; then
> ndisks=$( set -- $ZFSBOOT_DISKS; echo $# )
> [ $ndisks -ge $want_disks ] && break # to success
>
> # Not enough disks selected
> f_dprintf "$funcname: %s: %s (%u < %u minimum)" \
> "$ZFSBOOT_VDEV_TYPE" \
> "Not enough disks selected." \
> $ndisks $want_disks
> f_interactive || return $FAILURE
> msg_yes="$msg_change_selection" msg_no="$msg_cancel" \
> f_yesno "%s: $msg_not_enough_disks_selected" \
> "$ZFSBOOT_VDEV_TYPE" $ndisks $want_disks ||
> return $FAILURE
> fi
>
> #
> # Confirm the disks that were selected
> # Loop until the user cancels or selects enough disks
> #
> local breakout=
> while :; do
> # Loop over list of available disks, resetting state
> for disk in $disks; do unset _${disk}_status; done
>
> # Loop over list of selected disks and create temporary
> # locals to map statuses onto up-to-date list of disks
> for disk in $ZFSBOOT_DISKS; do
> local _${disk}_status=on
> done
>
> # Create the checklist menu of discovered disk devices
> disk_check_list=
> for disk in $disks; do
> local desc=
> device_$disk get desc desc
> f_shell_escape "$desc" desc
> f_getvar _${disk}_status:-off onoff
> disk_check_list="$disk_check_list
> $disk '$desc' $onoff"
> done
>
> local height width rows
> eval f_dialog_checklist_size height width rows \
> \"\$title\" \"\$btitle\" \"\$prompt\" \
> \"\$hline\" $disk_check_list
>
> selections=$( eval $DIALOG \
> --title \"\$DIALOG_TITLE\" \
> --backtitle \"\$DIALOG_BACKTITLE\" \
> --hline \"\$hline\" \
> --ok-label \"\$msg_ok\" \
> --cancel-label \"\$msg_back\" \
> --checklist \"\$prompt\" \
> $height $width $rows \
> $disk_check_list \
> 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
> ) || break
> # Loop if user pressed ESC or chose Cancel/No
> f_dialog_data_sanitize selections
>
> ZFSBOOT_DISKS="$selections"
> f_dprintf "$funcname: ZFSBOOT_DISKS=[%s]" \
> "$ZFSBOOT_DISKS"
>
> ndisks=$( set -- $ZFSBOOT_DISKS; echo $# )
> [ $ndisks -ge $want_disks ] &&
> breakout=break && break
>
> # Not enough disks selected
> f_dprintf "$funcname: %s: %s (%u < %u minimum)" \
> "$ZFSBOOT_VDEV_TYPE" \
> "Not enough disks selected." \
> $ndisks $want_disks
> msg_yes="$msg_change_selection" msg_no="$msg_cancel" \
> f_yesno "%s: $msg_not_enough_disks_selected" \
> "$ZFSBOOT_VDEV_TYPE" $ndisks $want_disks ||
> break
> done
> [ "$breakout" = "break" ] && break
> [ "$ZFSBOOT_CONFIRM_LAYOUT" ] || return $FAILURE
> done
>
> return $DIALOG_OK
452d616
< local disk="$1" index="$2"
453a618
> local disk="$1" index="$2"
457c622,646
< [ "$disk" -a "$index" ] || return $FAILURE
---
> if [ ! "$disk" ]; then
> f_dprintf "$funcname: NULL disk argument"
> msg_error="$msg_error: $funcname" \
> f_show_err "$msg_null_disk_argument"
> return $FAILURE
> fi
> if [ "${disk#*[$IFS]}" != "$disk" ]; then
> f_dprintf "$funcname: Invalid disk argument \`%s'" "$disk"
> msg_error="$msg_error: $funcname" \
> f_show_err "$msg_invalid_disk_argument" "$disk"
> return $FAILURE
> fi
> if [ ! "$index" ]; then
> f_dprintf "$funcname: NULL index argument"
> msg_error="$msg_error: $funcname" \
> f_show_err "$msg_null_index_argument"
> return $FAILURE
> fi
> if ! f_isinteger "$index"; then
> f_dprintf "$funcname: Invalid index argument \`%s'" "$index"
> msg_error="$msg_error: $funcname" \
> f_show_err "$msg_invalid_index_argument" "$index"
> return $FAILURE
> fi
> f_dprintf "$funcname: disk=[%s] index=[%s]" "$disk" "$index"
458a648,659
> # Check for unknown partition scheme before proceeding further
> case "$ZFSBOOT_PARTITION_SCHEME" in
> ""|MBR|GPT) : known good ;;
> *)
> f_dprintf "$funcname: %s is an unsupported partition scheme" \
> "$ZFSBOOT_PARTITION_SCHEME"
> msg_error="$msg_error: $funcname" f_show_err \
> "$msg_unsupported_partition_scheme" \
> "$ZFSBOOT_PARTITION_SCHEME"
> return $FAILURE
> esac
>
463a665
> f_dprintf "$funcname: Destroying all data/layouts on \`%s'..." "$disk"
464a667
> f_quietly graid destroy $disk
468,469c671,672
< f_quietly gpart create -s gpt $disk || return $FAILURE
< f_quietly gpart destroy -F $disk || return $FAILURE
---
> f_quietly gpart create -s gpt $disk
> f_quietly gpart destroy -F $disk
472c675,682
< device_$disk get capacity disksize || return $FAILURE
---
> f_dprintf "$funcname: Getting disk capactiy for \`%s'" "$disk"
> if ! device_$disk get capacity disksize; then
> f_dprintf "$funcname: Unable to get disk capacity of \`%s'" \
> "$disk"
> msg_error="$msg_error: $funcname" \
> f_show_err "$msg_unable_to_get_disk_capacity" "$disk"
> return $FAILURE
> fi
473a684,685
> f_dprintf "$funcname: disksize=[%s] partsize=[%s]" \
> "$disksize" "$partsize"
480c692
< ""|GPT)
---
> ""|GPT) f_dprintf "$funcname: Creating GPT layout..."
484c696,697
< gpart create -s gpt $disk || return $FAILURE
---
> f_eval_catch $funcname gpart "$GPART_CREATE" gpt \$disk ||
> return $FAILURE
489,492c702,707
< gpart add -l gptboot$index -t freebsd-boot -s 512k $disk ||
< return $FAILURE
< gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 $disk ||
< return $FAILURE
---
> f_eval_catch $funcname gpart "$GPART_ADD_LABEL_WITH_SIZE" \
> gptboot\$index freebsd-boot 512k \$disk ||
> return $FAILURE
> f_eval_catch $funcname gpart "$GPART_BOOTCODE_PART" \
> /boot/pmbr /boot/gptzfsboot 1 \$disk ||
> return $FAILURE
497c712
< # Change things around if we are using GELI
---
> # Change things around if we are using geli(8)
501,502c716,722
< gpart add -l boot$index -t freebsd-zfs \
< -s ${gelisize}b -a 1m $disk || return $FAILURE
---
> f_dprintf "$funcname: gelisize=[%s]" \
> "gelisize=[$gelisize]"
> f_eval_catch $funcname gpart \
> "$GPART_ADD_LABEL_WITH_SIZE" boot\$index \
> freebsd-zfs \${gelisize}b \$disk ||
> return $FAILURE
>
504,505c724,725
< f_quietly zpool labelclear -f /dev/$disk$bootpart
< f_quietly geli detach -f /dev/$disk$targetpart
---
> f_quietly zpool labelclear -f "/dev/$disk$bootpart"
> f_quietly geli detach -f "/dev/$disk$targetpart"
512,515c732,744
< [ $swapsize -gt 0 ] && setsize="-s ${partsize}b"
< gpart add -l zfs$index -t freebsd-zfs $setsize -a 1m $disk ||
< return $FAILURE
< f_quietly zpool labelclear -f /dev/$disk$targetpart # Pedantic
---
> if [ ${swapsize:-0} -gt 0 ]; then
> f_dprintf "$funcname: partsize=[%s]" \
> "partsize=[$partsize]"
> f_eval_catch $funcname gpart \
> "$GPART_ADD_LABEL_WITH_SIZE" zfs\$index \
> freebsd-zfs \${partsize}b \$disk ||
> return $FAILURE
> else
> f_eval_catch $funcname gpart "$GPART_ADD_LABEL" \
> zfs\$index freebsd-zfs \$disk ||
> return $FAILURE
> fi
> f_quietly zpool labelclear -f "/dev/$disk$targetpart"
521,522c750,752
< gpart add -l swap$index -t freebsd-swap -a 1m $disk ||
< return $FAILURE
---
> f_eval_catch $funcname gpart "$GPART_ADD_LABEL" \
> swap\$index freebsd-swap \$disk ||
> return $FAILURE
524,526c754,757
< printf "$fstab_fmt" \
< /dev/gpt/swap$index none swap sw 0 0 \
< >> $BSDINSTALL_TMPETC/fstab || return $FAILURE
---
> f_eval_catch $funcname printf "$PRINTF_FSTAB" \
> /dev/gpt/swap\$index none swap sw 0 0 \
> \$BSDINSTALL_TMPETC/fstab ||
> return $FAILURE
530c761
< MBR)
---
> MBR) f_dprintf "$funcname: Creating MBR layout..."
534,535c765,768
< gpart create -s mbr $disk || return $FAILURE
< gpart bootcode -b /boot/boot0 $disk || return $FAILURE
---
> f_eval_catch $funcname gpart "$GPART_CREATE" mbr \$disk ||
> return $FAILURE
> f_eval_catch $funcname gpart "$GPART_BOOTCODE" /boot/mbr \
> \$disk || return $FAILURE
540,541c773,776
< gpart add -t freebsd $disk || return $FAILURE
< gpart set -a active -i 1 $disk || return $FAILURE
---
> f_eval_catch $funcname gpart "$GPART_ADD" freebsd \$disk ||
> return $FAILURE
> f_eval_catch $funcname gpart "$GPART_SET_ACTIVE" 1 \$disk ||
> return $FAILURE
546c781
< # 3. Write BSD sceme to the freebsd slice
---
> # 3. Write BSD scheme to the freebsd slice
548c783,784
< gpart create -s BSD ${disk}s1 || return $FAILURE
---
> f_eval_catch $funcname gpart "$GPART_CREATE" BSD \${disk}s1 ||
> return $FAILURE
553c789
< # Change things around if we are using GELI
---
> # Change things around if we are using geli(8)
558,559c794,799
< gpart add -t freebsd-zfs -i 1 -s ${gelisize}b \
< ${disk}s1 || return $FAILURE
---
> f_dprintf "$funcname: mbrindex=[%s] gelisize=[%s]" \
> "$mbrindex" "$gelisize"
> f_eval_catch $funcname gpart \
> "$GPART_ADD_INDEX_WITH_SIZE" \
> 1 freebsd-zfs \${gelisize}b \${disk}s1 ||
> return $FAILURE
561,562c801,802
< f_quietly zpool labelclear -f /dev/$disk$bootpart
< f_quietly geli detach -f /dev/$disk$targetpart
---
> f_quietly zpool labelclear -f "/dev/$disk$bootpart"
> f_quietly geli detach -f "/dev/$disk$targetpart"
569,571c809,821
< [ $swapsize -gt 0 ] && setsize="-s ${partsize}b"
< gpart add -t freebsd-zfs -i $mbrindex $setsize ${disk}s1 ||
< return $FAILURE
---
> if [ ${swapsize:-0} -gt 0 ]; then
> f_dprintf "$funcname: mbrindex=[%s] partsize=[%s]" \
> "$mbrindex" "$partsize"
> f_eval_catch $funcname gpart \
> "$GPART_ADD_INDEX_WITH_SIZE" \
> \$mbrindex freebsd-zfs \${partsize}b \
> \${disk}s1 || return $FAILURE
> else
> f_dprintf "$funcname: mbrindex=[%s]" "$mbrindex"
> f_eval_catch $funcname gpart "$GPART_ADD_INDEX" \
> \$mbrindex freebsd-zfs \${disk}s1 ||
> return $FAILURE
> fi
578,579c828,830
< gpart add -t freebsd-swap -i 2 ${disk}s1 ||
< return $FAILURE
---
> f_eval_catch $funcname gpart "$GPART_ADD_INDEX" \
> 2 freebsd-swap \${disk}s1 ||
> return $FAILURE
581,582c832,835
< printf "$fstab_fmt" /dev/${disk}s1b none swap sw 0 0 \
< >> $BSDINSTALL_TMPETC/fstab || return $FAILURE
---
> f_eval_catch $funcname printf "$PRINTF_FSTAB" \
> /dev/\${disk}s1b none swap sw 0 0 \
> \$BSDINSTALL_TMPETC/fstab ||
> return $FAILURE
586,590d838
< *)
< printf "%s: %s is an unsupported partition scheme" \
< "$funcname" "$ZFSBOOT_PARTITION_SCHEME" >&2
< return $FAILURE
<
596c844
< # zfs_create_boot $poolname $vdev_type $real_disks ...
---
> # zfs_create_boot $poolname $vdev_type $disks ...
603,604d850
< local poolname="$1" vdev_type="$2"
< local fstab_fmt="%s\t\t%s\t%s\t%s\t\t%s\t%s\n"
605a852
> local poolname="$1" vdev_type="$2"
611c858
< local realdisks=$*
---
> local disks="$*"
615c862,864
< echo "$funcname: NULL poolname" >&2
---
> f_dprintf "$funcname: NULL poolname"
> msg_error="$msg_error: $funcname" \
> f_show_err "$msg_null_poolname"
619c868,870
< echo "$funcname: missing disk arguments" >&2
---
> f_dprintf "$funcname: missing disk arguments"
> msg_error="$msg_error: $funcname" \
> f_show_err "$msg_missing_disk_arguments"
621a873,874
> f_dprintf "$funcname: poolname=[%s] vdev_type=[%s]" \
> "$poolname" "$vdev_type"
624,626c877,883
< printf "$fstab_fmt" \
< "# Device" Mountpoint FStype Options Dump "Pass#" \
< >> $BSDINSTALL_TMPETC/fstab || return $FAILURE
---
> f_dprintf "$funcname: Initializing temporary fstab(5) file..."
> f_eval_catch $funcname sh \
> "$SHELL_TRUNCATE" \$BSDINSTALL_TMPETC/fstab ||
> return $FAILURE
> f_eval_catch $funcname printf "$PRINTF_FSTAB" \
> "# Device" Mountpoint FStype Options Dump "Pass#" \
> \$BSDINSTALL_TMPETC/fstab || return $FAILURE
628a886
> f_dprintf "$funcname: Expanding supplied swapsize/gelisize values..."
630,631c888,904
< f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize || return $FAILURE
< f_expand_number "$ZFSBOOT_GELI_BOOT_SIZE" gelisize || return $FAILURE
---
> if ! f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize; then
> f_dprintf "$funcname: Invalid swap size \`%s'" \
> "$ZFSBOOT_SWAP_SIZE"
> f_show_err "$msg_invalid_swap_size" "$ZFSBOOT_SWAP_SIZE"
> return $FAILURE
> fi
> if ! f_expand_number "$ZFSBOOT_GELI_BOOT_SIZE" gelisize; then
> f_dprintf "$funcname: Invalid geli(8) boot size \`%s'" \
> "$ZFSBOOT_GELI_BOOT_SIZE"
> f_show_err "$msg_invalid_geli_boot_size" \
> "$ZFSBOOT_GELI_BOOT_SIZE"
> return $FAILURE
> fi
> f_dprintf "$funcname: ZFSBOOT_SWAP_SIZE=[%s] swapsize=[%s]" \
> "$ZFSBOOT_SWAP_SIZE" "$swapsize"
> f_dprintf "$funcname: ZFSBOOT_GELI_BOOT_SIZE=[%s] gelisize=[%s]" \
> "$ZFSBOOT_GELI_BOOT_SIZE" "$gelisize"
633a907
> f_dprintf "$funcname: Preparing disk partitions for ZFS pool..."
643,645c917,923
< for disk in $realdisks; do
< dd if=/boot/zfsboot of=/dev/${disk}s1 count=1 ||
< return $FAILURE
---
> f_dprintf "$funcname: Copying MBR boot loader to disks..."
> f_dprintf "$funcname: disks=[%s]" "$disks"
> for disk in $disks; do
> f_dprintf "$funcname: disk=[%s]" "$disk"
> f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \
> /boot/zfsboot /dev/\${disk}s1 count=1 ||
> return $FAILURE
652c930,937
< local new_list=
---
> local part="$targetpart" new_list=
>
> # We don't gnop the encrypted partition because geli will do
> # this for us gnop the unencrypted disk
> [ "$ZFSBOOT_GELI_ENCRYPTION" ] && part="$bootpart"
>
> f_dprintf "$funcname: Applying 4k alignment with gnop(8)..."
> f_dprintf "$funcname: *=[%s]" "$*"
653a939,942
> f_dprintf "$funcname: disk=[%s] part=[%s]" \
> "$disk" "$part"
> f_eval_catch $funcname gnop "$GNOP_CREATE" \
> \$disk\$part || return $FAILURE
655,660c944
< # We don't gnop the encrypted partition
< # because geli will do this for us
< # gnop the unencrypted disk
< gnop create -S 4096 $disk$bootpart ||
< return $FAILURE
< unenc_list="$unenc_list $disk$bootpart.nop"
---
> unenc_list="$unenc_list $disk$part.nop"
662,663d945
< gnop create -S 4096 $disk$targetpart ||
< return $FAILURE
685a968,969
> f_dprintf "$funcname: Setting up disk encryption..."
>
688c972,973
< mount -t tmpfs none $BSDINSTALL_CHROOT || return $FAILURE
---
> f_eval_catch $funcname mount "$MOUNT_TYPE" tmpfs none \
> \$BSDINSTALL_CHROOT || return $FAILURE
693,697c978,988
< zpool create -o altroot=$BSDINSTALL_CHROOT \
< -m "/$ZFSBOOT_GELI_POOL_NAME" -f \
< "$ZFSBOOT_GELI_POOL_NAME" $bootvdev $unenc_list ||
< return $FAILURE
< mkdir -p $geli_pool/boot || return $FAILURE
---
> f_dprintf "$funcname: %s %s %s" \
> "ZFSBOOT_GELI_POOL_NAME=[$ZFSBOOT_GELI_POOL_NAME]" \
> "bootvdev=[$bootvdev]" "unenc_list=[$unenc_list]"
> f_eval_catch $funcname zpool "$ZPOOL_CREATE_WITH_OPTIONS" \
> "-o altroot=\"\$BSDINSTALL_CHROOT\"
> -m \"/\$ZFSBOOT_GELI_POOL_NAME\" -f" \
> \$ZFSBOOT_GELI_POOL_NAME \$bootvdev \
> \$unenc_list || return $FAILURE
> f_dprintf "$funcname: geli_pool=[%s]" "$geli_pool"
> f_eval_catch $funcname mkdir "$MKDIR_P" \$geli_pool/boot ||
> return $FAILURE
700,701c991,994
< dd if=/dev/random of="$geli_pool/$key" bs=4096 count=1 ||
< return $FAILURE
---
> f_dprintf "$funcname: key=[%s]" "$key"
> f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \
> /dev/random \$geli_pool/\$key "bs=4096 count=1" ||
> return $FAILURE
705,715c998,1016
< msg_enter_new_password="$msg_geli_password" \
< f_dialog_input_password || return $FAILURE
< f_dialog_info "$msg_geli_setup" \
< 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
< for disk in $realdisks; do
< echo "$pw_password" | geli init -b -B \
< "$geli_pool/boot/$disk$targetpart.eli" \
< -e AES-XTS -J - -K "$geli_pool/$key" -l 256 \
< -s 4096 $disk$targetpart || return $FAILURE
< echo "$pw_password" | geli attach -j - \
< -k "$geli_pool/$key" $disk$targetpart ||
---
> if ! msg_enter_new_password="$msg_geli_password" \
> f_dialog_input_password
> then
> f_dprintf "$funcname: User cancelled"
> f_show_err "$msg_user_cancelled"
> return $FAILURE
> fi
> f_dprintf "$funcname: disks=[%s]" "$disks"
> for disk in $disks; do
> f_dprintf "$funcname: disk=[%s] targetpart=[%s]" \
> "$disk" "$targetpart"
> f_dialog_info "$msg_geli_setup" \
> 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
> if ! echo "$pw_password" | f_eval_catch $funcname \
> geli "$GELI_PASSWORD_INIT" \
> \$geli_pool/boot/\$disk\$targetpart.eli \
> AES-XTS \$geli_pool/\$key \$disk\$targetpart
> then
> f_interactive || f_die
716a1018,1025
> fi
> if ! echo "$pw_password" | f_eval_catch $funcname \
> geli "$GELI_ATTACH" \$geli_pool/\$key \
> \$disk\$targetpart
> then
> f_interactive || f_die
> return $FAILURE
> fi
720c1029,1030
< zfs unmount "$ZFSBOOT_GELI_POOL_NAME" || return $FAILURE
---
> f_eval_catch $funcname zfs "$ZFS_UNMOUNT" \
> \$ZFSBOOT_GELI_POOL_NAME || return $FAILURE
727,728c1037,1043
< zpool create -o altroot=$BSDINSTALL_CHROOT -m none -f \
< "$poolname" $vdev_type $* || return $FAILURE
---
> local vdevs="$*"
> f_dprintf "$funcname: Creating boot pool..."
> f_dprintf "poolname=[%s] vdev_type=[%s] vdevs=[%s]" \
> "$poolname" "$vdev_type" "$vdevs"
> f_eval_catch $funcname zpool "$ZPOOL_CREATE_WITH_OPTIONS" \
> "-o altroot=\"\$BSDINSTALL_CHROOT\" -m none -f" \
> \$poolname \$vdev_type \$vdevs
731,732c1046,1052
< zfs set checksum=fletcher4 "$poolname" || return $FAILURE
< zfs set atime=off "$poolname" || return $FAILURE
---
> local option
> f_dprintf "$funcname: Setting miscellaneous options on boot pool..."
> for option in checksum=fletcher4 atime=off; do
> f_dprintf "$funcname: option=[%s]" "$option"
> f_eval_catch $funcname zfs "$ZFS_SET" \$option \$poolname ||
> return $FAILURE
> done
736a1057
> f_dprintf "$funcname: Creating ZFS datasets..."
753,754c1074,1078
< zfs create ${options:+-o $options} "$poolname$dataset" ||
< return $FAILURE
---
> f_dprintf "$funcname: dataset=[%s] options=[%s]" \
> "$dataset" "$options"
> f_eval_catch $funcname zfs "$ZFS_CREATE_WITH_OPTIONS" \
> "\${options:+-o \$options}" \$poolname\$dataset ||
> return $FAILURE
758,759c1082,1088
< chmod 1777 $BSDINSTALL_CHROOT/tmp || return $FAILURE
< chmod 1777 $BSDINSTALL_CHROOT/var/tmp || return $FAILURE
---
> f_dprintf "$funcname: Modifying directory permissions..."
> local dir
> for dir in /tmp /var/tmp; do
> f_dprintf "$funcname: dir=[%s]" "$dir"
> f_eval_catch $funcname chmod "$CHMOD_MODE" 1777 \
> \$BSDINSTALL_CHROOTDIR\$dir || return $FAILURE
> done
762,764c1091,1096
< [ "$ZFSBOOT_GELI_ENCRYPTION" ] &&
< { ln -s $ZFSBOOT_GELI_POOL_NAME/boot $BSDINSTALL_CHROOT/boot ||
< return $FAILURE; }
---
> if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
> f_dprintf "$funcname: Creating /boot symlink for GELI..."
> f_eval_catch $funcname ln "$LN_SF" \
> \$ZFSBOOT_GELI_POOL_NAME/boot \
> \$BSDINSTALL_CHROOT/boot || return $FAILURE
> fi
767,768c1099,1105
< zpool set bootfs="$poolname/$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOTFS_NAME" \
< "$poolname" || return $FAILURE
---
> f_dprintf "$funcname: Setting bootfs property..."
> f_dprintf "$funcname: %s %s" \
> "ZFSBOOT_BEROOT_NAME=[$ZFSBOOT_BEROOT_NAME]" \
> "ZFSBOOT_BOOTFS_NAME=[$ZFSBOOT_BOOTFS_NAME]"
> f_eval_catch $funcname zpool "$ZPOOL_SET" \
> bootfs=\"\$poolname/\$ZFSBOOT_BEROOT_NAME/\$ZFSBOOT_BOOTFS_NAME\" \
> \$poolname || return $FAILURE
771,773c1108,1114
< zpool export "$poolname" || return $FAILURE
< [ "$ZFSBOOT_GELI_ENCRYPTION" ] &&
< { zpool export "$ZFSBOOT_GELI_POOL_NAME" || return $FAILURE; }
---
> f_dprintf "$funcname: Temporarily exporting ZFS pool(s)..."
> f_eval_catch $funcname zpool "$ZPOOL_EXPORT" \$poolname ||
> return $FAILURE
> if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
> f_eval_catch $funcname zpool "$ZPOOL_EXPORT" \
> \$ZFSBOOT_GELI_POOL_NAME || return $FAILURE
> fi
776c1117
< for disk in ${ZFSBOOT_GNOP_4K_FORCE_ALIGN:+$realdisks}; do
---
> for disk in ${ZFSBOOT_GNOP_4K_FORCE_ALIGN:+$disks}; do
785a1127,1128
> f_dprintf "$funcname: Updating MBR boot loader on disks..."
> f_dprintf "$funcname: disks=[%s]"
788,790c1131,1136
< for disk in $realdisks; do
< dd if=/boot/zfsboot of=/dev/$disk$bootpart \
< skip=1 seek=1024 || return $FAILURE
---
> for disk in $disks; do
> f_dprintf "$funcname: disk=[%s] bootpart=[%s]" \
> "$disk" "$bootpart"
> f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \
> /boot/zfsboot /dev/\$disk\$bootpart \
> "skip=1 seek=1024" || return $FAILURE
795,798c1141,1149
< zpool import -o altroot=$BSDINSTALL_CHROOT $poolname || return $FAILURE
< [ "$ZFSBOOT_GELI_ENCRYPTION" ] &&
< { zpool import -o altroot=$BSDINSTALL_CHROOT \
< "$ZFSBOOT_GELI_POOL_NAME" || return $FAILURE; }
---
> f_dprintf "$funcname: Re-importing ZFS pool(s)..."
> f_eval_catch $funcname zpool "$ZPOOL_IMPORT_WITH_OPTIONS" \
> "-o altroot=\"\$BSDINSTALL_CHROOT\"" \$poolname ||
> return $FAILURE
> if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
> f_eval_catch $funcname zpool "$ZPOOL_IMPORT_WITH_OPTIONS" \
> "-o altroot=\"\$BSDINSTALL_CHROOT\"" \
> \$ZFSBOOT_GELI_POOL_NAME || return $FAILURE
> fi
801,803c1152,1157
< mkdir -p $BSDINSTALL_CHROOT/boot/zfs || return $FAILURE
< zpool set cachefile=$BSDINSTALL_CHROOT/boot/zfs/zpool.cache \
< "$poolname" || return $FAILURE
---
> f_dprintf "$funcname: Configuring zpool.cache..."
> f_eval_catch $funcname mkdir "$MKDIR_P" \$BSDINSTALL_CHROOT/boot/zfs ||
> return $FAILURE
> f_eval_catch $funcname zpool "$ZPOOL_SET" \
> cachefile=\"\$BSDINSTALL_CHROOT/boot/zfs/zpool.cache\" \
> \$poolname || return $FAILURE
807,810c1161,1166
< echo 'zfs_enable="YES"' > $BSDINSTALL_TMPETC/rc.conf.zfs ||
< return $FAILURE
< echo 'zfs_load="YES"' > $BSDINSTALL_TMPBOOT/loader.conf.zfs ||
< return $FAILURE
---
> f_dprintf "%s: Configuring rc.conf(5)/loader.conf(5) additions..." \
> "$funcname"
> f_eval_catch $funcname echo "$ECHO_APPEND" 'zfs_enable=\"YES\"' \
> \$BSDINSTALL_TMPETC/rc.conf.zfs || return $FAILURE
> f_eval_catch $funcname echo "$ECHO_APPEND" 'zfs_load=\"YES\"' \
> \$BSDINSTALL_TMPBOOT/loader.conf.zfs || return $FAILURE
815,821c1171,1180
< # Some additional GELI requirements for loader.conf(5)
< echo 'zpool_cache_load="YES"' \
< >> $BSDINSTALL_TMPBOOT/loader.conf.zfs || return $FAILURE
< echo 'zpool_cache_type="/boot/zfs/zpool.cache"' \
< >> $BSDINSTALL_TMPBOOT/loader.conf.zfs || return $FAILURE
< echo 'zpool_cache_name="/boot/zfs/zpool.cache"' \
< >> $BSDINSTALL_TMPBOOT/loader.conf.zfs || return $FAILURE
---
> # Some additional geli(8) requirements for loader.conf(5)
> for option in \
> zpool_cache_load=\"YES\" \
> zpool_cache_type=\"/boot/zfs/zpool.cache\" \
> zpool_cache_name=\"/boot/zfs/zpool.cache\" \
> ; do
> f_eval_catch $funcname echo "$ECHO_APPEND" \$option \
> \$BSDINSTALL_TMPBOOT/loader.conf.zfs ||
> return $FAILURE
> done
826,836c1185,1200
< echo 'aesni_load="YES"' \
< > $BSDINSTALL_TMPBOOT/loader.conf.aesni || return $FAILURE
< echo 'geom_eli_load="YES"' \
< > $BSDINSTALL_TMPBOOT/loader.conf.geli || return $FAILURE
< printf 'vfs.root.mountfrom="zfs:%s/%s/%s"\n' "$poolname" \
< "$ZFSBOOT_BEROOT_NAME" "$ZFSBOOT_BOOTFS_NAME" \
< > $BSDINSTALL_TMPBOOT/loader.conf.root || return $FAILURE
< for disk in $realdisks; do
< printf 'geli_%s_keyfile0_load="YES"\n' \
< "$disk$targetpart" \
< > $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart ||
---
> f_dprintf "$funcname: Configuring disk encryption..."
> f_eval_catch $funcname echo "$ECHO_APPEND" 'aesni_load=\"YES\"' \
> \$BSDINSTALL_TMPBOOT/loader.conf.aesni || return $FAILURE
> f_eval_catch $funcname echo "$ECHO_APPEND" 'geom_eli_load=\"YES\"' \
> \$BSDINSTALL_TMPBOOT/loader.conf.geli || return $FAILURE
> f_eval_catch $funcname printf "$PRINTF_CONF" vfs.root.mountfrom \
> '"zfs:$poolname/$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOT_FSNAME"' \
> \$BSDINSTALL_TMPBOOT/loader.conf.root || return $FAILURE
> f_dprintf "$funcname: disks=[%s]" "$disks"
> for disk in $disks; do
> f_dprintf "$funcname: %s %s %s" \
> "disk=[$disk]" "targetpart=[$targetpart]" \
> "ZFSBOOT_GELI_KEY_FILE=[$ZFSBOOT_GELI_KEY_FILE]"
> f_eval_catch $funcname printf "$PRINTF_CONF" \
> geli_%s_keyfile0_load '"$disk$targetpart" YES' \
> \$BSDINSTALL_TMPBOOT/loader.conf.\$disk\$targetpart ||
838,840c1202,1205
< printf 'geli_%s_keyfile0_type="%s:geli_keyfile0"\n' \
< "$disk$targetpart" "$disk$targetpart" \
< >> $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart ||
---
> f_eval_catch $funcname printf "$PRINTF_CONF" \
> geli_%s_keyfile0_type \
> '"$disk$targetpart" "$disk$targetpart"' \
> \$BSDINSTALL_TMPBOOT/loader.conf.\$disk\$targetpart ||
842,844c1207,1210
< printf 'geli_%s_keyfile0_name="%s"\n' \
< "$disk$targetpart" "$ZFSBOOT_GELI_KEY_FILE" \
< >> $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart ||
---
> f_eval_catch $funcname printf "$PRINTF_CONF" \
> geli_%s_keyfile0_name \
> '"$disk$targetpart" "$ZFSBOOT_GELI_KEY_FILE"' \
> \$BSDINSTALL_TMPBOOT/loader.conf.\$disk\$targetpart ||
888a1255,1261
> # Debugging
> #
> f_dprintf "BSDINSTALL_CHROOT=[%s]" "$BSDINSTALL_CHROOT"
> f_dprintf "BSDINSTALL_TMPETC=[%s]" "$BSDINSTALL_TMPETC"
> f_dprintf "PRINTF_FSTAB=[%s]" "$PRINTF_FSTAB"
>
> #
894c1267
< mtag=">>> $msg_create"
---
> mtag=">>> $msg_install"
901c1274
< f_dprintf "retval=%u mtag=[%s]" $reval "$mtag"
---
> f_dprintf "retval=%u mtag=[%s]" $retval "$mtag"
905c1278
< ">>> $msg_create")
---
> ">>> $msg_install")
912,913c1285,1286
< f_show_msg "$msg_pool_name_cannot_be_empty"
< f_interactive || f_die
---
> f_dprintf "Pool name cannot be empty."
> f_show_err "$msg_pool_name_cannot_be_empty"
916,946c1289,1294
< # Make sure [potentially scripted] selections are real
< real_disks=
< for disk in $ZFSBOOT_DISKS; do
< f_struct device_$disk && real_disks="$real_disks $disk"
< done
< # Make sure we have at least one real disk selected
< ndisks=$( set -- $real_disks; echo $# )
< if [ $ndisks -lt 1 ]; then
< f_show_msg "$msg_no_disks_selected"
< f_interactive || f_die
< continue
< fi
< # Make sure we have enough disks for the desired vdev type
< case "$ZFSBOOT_VDEV_TYPE" in
< stripe) want_disks=1 ;;
< mirror) want_disks=2 ;;
< raidz1) want_disks=3 ;;
< raidz2) want_disks=4 ;;
< raidz3) want_disks=5 ;;
< *)
< f_show_msg "$msg_invalid_virtual_device_type" \
< "$ZFSBOOT_VDEV_TYPE"
< f_interactive || f_die
< continue
< esac
< if [ $ndisks -lt $want_disks ]; then
< f_show_msg "%s: $msg_not_enough_disks_selected" \
< "$ZFSBOOT_VDEV_TYPE" "$want_disks"
< f_interactive || f_die
< continue
< fi
---
>
> # Validate vdev type against number of disks selected/scripted
> # (also validates that ZFSBOOT_DISKS are real [probed] disks)
> # NB: dialog_menu_layout supports running non-interactively
> dialog_menu_layout || continue
>
954c1302
< for disk in $real_disks; do
---
> for disk in $ZFSBOOT_DISKS; do
961c1309,1314
< f_show_msg "$msg_these_disks_are_too_small" \
---
> f_dprintf "swapsize=[%s] gelisize[%s]" \
> "$ZFSBOOT_SWAP_SIZE" \
> "$ZFSBOOT_GELI_BOOT_SIZE"
> f_dprintf "These disks are too small: %s" \
> "$teeny_disks"
> f_show_err "$msg_these_disks_are_too_small" \
965d1317
< f_interactive || f_die
973,980c1325,1326
< if [ ! "$USE_XDIALOG" ]; then
< f_interactive && DIALOG="$DIALOG --colors" f_noyes \
< "$msg_last_chance_are_you_sure_color" \
< "$ZFSBOOT_DISKS" || continue
< else
< f_interactive && f_noyes \
< "$msg_last_chance_are_you_sure" \
< "$ZFSBOOT_DISKS" || continue
---
> if f_interactive; then
> dialog_last_chance $ZFSBOOT_DISKS || continue
992,998c1338,1339
< if ! error=$( zfs_create_boot "$ZFSBOOT_POOL_NAME" \
< "$vdev_type" $real_disks 2>&1 )
< then
< f_dialog_msgbox "$error"
< f_interactive || f_die
< continue
< fi
---
> zfs_create_boot "$ZFSBOOT_POOL_NAME" \
> "$vdev_type" $ZFSBOOT_DISKS || continue
1001a1343,1348
> ?" $msg_pool_type_disks")
> ZFSBOOT_CONFIRM_LAYOUT=1
> dialog_menu_layout
> # User has poked settings, disable later confirmation
> ZFSBOOT_CONFIRM_LAYOUT=
> ;;
1011,1012d1357
< ?" $msg_disks_to_use") dialog_edit_disks ;;
< ?" $msg_zfs_vdev_type") dialog_menu_vdev ;;
1021c1366
< ?" $msg_geli_encryption")
---
> ?" $msg_encrypt_disks")
< # $FreeBSD: stable/10/usr.sbin/bsdinstall/scripts/zfsboot 257507 2013-11-01 15:54:57Z gjb $
---
> # $FreeBSD: stable/10/usr.sbin/bsdinstall/scripts/zfsboot 258421 2013-11-21 03:40:52Z dteske $
50c50
< : ${ZFSBOOT_BEROOT_NAME:=bootenv}
---
> : ${ZFSBOOT_BEROOT_NAME:=ROOT}
70c70
< : ${ZFSBOOT_GELI_ENCRYPTION:=}
---
> : ${ZFSBOOT_GELI_ENCRYPTION=}
104c104
< # Default ZFS layout for root zpool
---
> # Default ZFS datasets for root zpool
122,123d121
< /usr/local # local files (i.e. from packages) separate from base system
<
125c123
< /usr/home setuid=off
---
> /usr/home # NB: /home is a symlink to /usr/home
129,130d126
< /usr/ports/distfiles compression=off,exec=off,setuid=off
< /usr/ports/packages compression=off,exec=off,setuid=off
134d129
< /usr/obj # Object files
139,141d133
< /var/db exec=off,setuid=off
< /var/db/pkg compression=lz4,exec=off,setuid=off
< /var/empty exec=off,setuid=off
143,144d134
< /var/mail compression=lz4,exec=off,setuid=off
< /var/run exec=off,setuid=off
147a138,143
> #
> # If interactive and the user has not explicitly chosen a vdev type or disks,
> # make the user confirm scripted/default choices when proceeding to install.
> #
> : ${ZFSBOOT_CONFIRM_LAYOUT:=1}
>
150a147,183
> # Format of a line in printf(1) syntax to add to fstab(5)
> #
> FSTAB_FMT="%s\t\t%s\t%s\t%s\t\t%s\t%s\n"
>
> #
> # Command strings for various tasks
> #
> CHMOD_MODE='chmod %s "%s"'
> DD_WITH_OPTIONS='dd if="%s" of="%s" %s'
> ECHO_APPEND='echo "%s" >> "%s"'
> GELI_ATTACH='geli attach -j - -k "%s" "%s"'
> GELI_PASSWORD_INIT='geli init -b -B "%s" -e %s -J - -K "%s" -l 256 -s 4096 "%s"'
> GNOP_CREATE='gnop create -S 4096 "%s"'
> GPART_ADD='gpart add -t %s "%s"'
> GPART_ADD_INDEX='gpart add -i %s -t %s "%s"'
> GPART_ADD_INDEX_WITH_SIZE='gpart add -i %s -t %s -s %s "%s"'
> GPART_ADD_LABEL='gpart add -l %s -t %s "%s"'
> GPART_ADD_LABEL_WITH_SIZE='gpart add -l %s -t %s -s %s "%s"'
> GPART_BOOTCODE='gpart bootcode -b "%s" "%s"'
> GPART_BOOTCODE_PART='gpart bootcode -b "%s" -p "%s" -i %s "%s"'
> GPART_CREATE='gpart create -s %s "%s"'
> GPART_SET_ACTIVE='gpart set -a active -i %s "%s"'
> LN_SF='ln -sf "%s" "%s"'
> MKDIR_P='mkdir -p "%s"'
> MOUNT_TYPE='mount -t %s "%s" "%s"'
> PRINTF_CONF="printf '%s=\"%%s\"\\\n' %s >> \"%s\""
> PRINTF_FSTAB='printf "$FSTAB_FMT" "%s" "%s" "%s" "%s" "%s" "%s" >> "%s"'
> SHELL_TRUNCATE=':> "%s"'
> ZFS_CREATE_WITH_OPTIONS='zfs create %s "%s"'
> ZFS_SET='zfs set "%s" "%s"'
> ZFS_UNMOUNT='zfs unmount "%s"'
> ZPOOL_CREATE_WITH_OPTIONS='zpool create %s "%s" %s %s'
> ZPOOL_EXPORT='zpool export "%s"'
> ZPOOL_IMPORT_WITH_OPTIONS='zpool import %s "%s"'
> ZPOOL_SET='zpool set %s "%s"'
>
> #
155a189
> msg_an_unknown_error_occurred="An unknown error occurred"
158c192
< msg_change="Change Selection"
---
> msg_change_selection="Change Selection"
160,162d193
< msg_create="Install"
< msg_create_desc="Proceed with Installation"
< msg_create_help="Create ZFS boot pool with displayed options"
166,167c197,199
< msg_disks_to_use="Disks To Use"
< msg_disks_to_use_help="Choose which disks to use for the Virtual Device (Required)"
---
> msg_encrypt_disks="Encrypt Disks?"
> msg_encrypt_disks_help="Use geli(8) to encrypt all data partitions"
> msg_error="Error"
171,172d202
< msg_geli_encryption="Encrypt Disks?"
< msg_geli_encryption_help="Use geli(8) to encrypt all data partitions"
174a205,211
> msg_install="Install"
> msg_install_desc="Proceed with Installation"
> msg_install_help="Create ZFS boot pool with displayed options"
> msg_invalid_disk_argument="Invalid disk argument \`%s'"
> msg_invalid_geli_boot_size="Invalid geli(8) boot size \`%s'"
> msg_invalid_index_argument="Invalid index argument \`%s'"
> msg_invalid_swap_size="Invalid swap size \`%s'"
176,178c213,214
< msg_invalid_virtual_device_type_help="Select another Virtual Device type or Cancel to\nreturn to the ZFS menu. From there you can select\nmore disks or rescan for additional devices."
< msg_last_chance_are_you_sure="Last Chance! Are you sure you want to destroy the current contents of the following disks:\n%s"
< msg_last_chance_are_you_sure_color="\\\\ZrLast Chance!\\\\ZR Are you \\\\Z1sure\\\\Zn you want to \\\\Zr\\\\Z1destroy\\\\Zn the current contents of the following disks:\n%s"
---
> msg_last_chance_are_you_sure="Last Chance! Are you sure you want to destroy\nthe current contents of the following disks:\n\n %s"
> msg_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'
180a217,218
> msg_missing_disk_arguments="missing disk arguments"
> msg_missing_one_or_more_scripted_disks="Missing one or more scripted disks!"
184c222,225
< msg_not_enough_disks_selected="Not enough disks selected. (%u < %u wanted)"
---
> msg_not_enough_disks_selected="Not enough disks selected. (%u < %u minimum)"
> msg_null_disk_argument="NULL disk argument"
> msg_null_index_argument="NULL index argument"
> msg_null_poolname="NULL poolname"
193a235,236
> msg_pool_type_disks="Pool Type/Disks:"
> msg_pool_type_disks_help="Choose type of ZFS Virtual Device and disks to use (Required)"
210c253,256
< msg_these_disks_are_too_small="These disks are too small given the amount of requested\nswap (%s) and/or GELI (%s) partitions, which would take\n50%% or more (not recommended) of each of the following\nselected disk devices:\n\n %s\n\nRecommend changing partition size(s) and/or selecting a\ndifferent set of devices."
---
> msg_these_disks_are_too_small="These disks are too small given the amount of requested\nswap (%s) and/or geli(8) (%s) partitions, which would\ntake 50%% or more of each of the following selected disk\ndevices (not recommended):\n\n %s\n\nRecommend changing partition size(s) and/or selecting a\ndifferent set of devices."
> msg_unable_to_get_disk_capacity="Unable to get disk capacity of \`%s'"
> msg_unsupported_partition_scheme="%s is an unsupported partition scheme"
> msg_user_cancelled="User Cancelled."
213,214d258
< msg_zfs_vdev_type="ZFS VDev Type"
< msg_zfs_vdev_type_help="Select type of ZFS Virtual Device to create"
230a275,276
> local disks n=$( set -- $ZFSBOOT_DISKS; echo $# )
> { [ $n -eq 1 ] && disks=disk; } || disks=disks # grammar
232,233c278,281
< '>>> $msg_create' '$msg_create_desc'
< '$msg_create_help'
---
> '>>> $msg_install' '$msg_install_desc'
> '$msg_install_help'
> 'T $msg_pool_type_disks' '$ZFSBOOT_VDEV_TYPE: $n $disks'
> '$msg_pool_type_disks_help'
238c286
< '1 $msg_pool_name' '$ZFSBOOT_POOL_NAME'
---
> 'N $msg_pool_name' '$ZFSBOOT_POOL_NAME'
240,243d287
< '2 $msg_disks_to_use' '$ZFSBOOT_DISKS'
< '$msg_disks_to_use_help'
< '3 $msg_zfs_vdev_type' '$ZFSBOOT_VDEV_TYPE'
< '$msg_zfs_vdev_type_help'
246,248c290,292
< '5 $msg_geli_encryption' '$usegeli'
< '$msg_geli_encryption_help'
< '6 $msg_partition_scheme' '$ZFSBOOT_PARTITION_SCHEME'
---
> 'E $msg_encrypt_disks' '$usegeli'
> '$msg_encrypt_disks_help'
> 'P $msg_partition_scheme' '$ZFSBOOT_PARTITION_SCHEME'
250c294
< '7 $msg_swap_size' '$ZFSBOOT_SWAP_SIZE'
---
> 'S $msg_swap_size' '$ZFSBOOT_SWAP_SIZE'
287c331
< # dialog_edit_disks
---
> # dialog_last_chance $disks ...
289c333,335
< # Edit the list of disks to be used by the ZFS boot pool.
---
> # Display a list of the disks that the user is about to destroy. The default
> # action is to return error status unless the user explicitly (non-default)
> # selects "Yes" from the noyes dialog.
291c337
< dialog_edit_disks()
---
> dialog_last_chance()
295,298c341,342
< local prompt="$msg_please_select_one_or_more_disks"
< local check_list= # Calculated below
< local hline="$hline_arrows_space_tab_enter"
< local dev vardev disks=
---
> local prompt # Calculated below
> local hline="$hline_arrows_tab_enter"
300,306c344,356
< #
< # Get a [new] list of disk devices
< #
< f_device_find "" $DEVICE_TYPE_DISK disks
< if [ ! "$disks" ]; then
< f_show_msg "$msg_no_disks_present_to_configure"
< return $FAILURE
---
> local height=8 width=50 prefix=" "
> local plen=${#prefix} list= line=
> local max_width=$(( $width - 3 - $plen ))
>
> local yes no defaultno extra_args format
> if [ "$USE_XDIALOG" ]; then
> yes=ok no=cancel defaultno=default-no
> extra_args="--wrap --left"
> format="$msg_last_chance_are_you_sure"
> else
> yes=yes no=no defaultno=defaultno
> extra_args="--colors --cr-wrap"
> format="$msg_last_chance_are_you_sure_color"
309,318c359,374
< # Lets sort the disks array to be more user friendly
< disks=$( echo "$disks" | tr ' ' '\n' | sort | tr '\n' ' ' )
<
< #
< # Loop through the list of selected disks and create temporary local
< # variables mapping their status onto an up-to-date list of disks.
< #
< for dev in $ZFSBOOT_DISKS; do
< f_str2varname "$dev" vardev
< local _${vardev}_status=on
---
> local disk line_width
> for disk in $*; do
> if [ "$line" ]; then
> line_width=${#line}
> else
> line_width=$plen
> fi
> line_width=$(( $line_width + 1 + ${#disk} ))
> # Add newline before disk if it would exceed max_width
> if [ $line_width -gt $max_width ]; then
> list="$list$line\n"
> line="$prefix"
> height=$(( $height + 1 ))
> fi
> # Add the disk to the list
> line="$line $disk"
319a376,380
> # Append the left-overs
> if [ "${line#$prefix}" ]; then
> list="$list$line"
> height=$(( $height + 1 ))
> fi
321,332c382,383
< #
< # Create the checklist menu of discovered disk devices
< #
< local on_off
< for dev in $disks; do
< local desc=
< device_$dev get desc desc
< f_shell_escape "$desc" desc
< f_str2varname "$dev" vardev
< f_getvar _${vardev}_status:-off on_off
< check_list="$check_list '$dev' '$desc' $on_off"
< done
---
> # Add height for Xdialog(1)
> [ "$USE_XDIALOG" ] && height=$(( $height + $height / 5 + 3 ))
334,356c385,395
< #
< # Prompt the user to check some disks
< #
< local height width rows
< eval f_dialog_checklist_size height width rows \
< \"\$title\" \"\$btitle\" \"\$prompt\" \"\$hline\" $check_list
< disks=$( eval $DIALOG \
< --title \"\$DIALOG_TITLE\" \
< --backtitle \"\$DIALOG_BACKTITLE\" \
< --hline \"\$hline\" \
< --ok-label \"\$msg_ok\" \
< --cancel-label \"\$msg_cancel\" \
< --checklist \"\$prompt\" \
< $height $width $rows \
< $check_list \
< 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
< ) || return $?
< # Exit if user either pressed ESC or chose Cancel/No
< f_dialog_data_sanitize disks
<
< ZFSBOOT_DISKS="$disks"
<
< return $DIALOG_OK
---
> prompt=$( printf "$format" "$list" )
> f_dprintf "%s: Last Chance!" "$0"
> $DIALOG \
> --title "$title" \
> --backtitle "$btitle" \
> --hline "$hline" \
> --$defaultno \
> --$yes-label "$msg_yes" \
> --$no-label "$msg_no" \
> $extra_args \
> --yesno "$prompt" $height $width
359c398
< # dialog_menu_vdev
---
> # dialog_menu_layout
361c400,401
< # Prompt the user to select a a Virtual Device type.
---
> # Configure Virtual Device type and disks to use for the ZFS boot pool. User
> # must select enough disks to satisfy the chosen vdev type.
363c403
< dialog_menu_vdev()
---
> dialog_menu_layout()
364a405
> local funcname=dialog_menu_layout
367,377c408,410
< local prompt="$msg_select_virtual_device_type"
<
< # Make sure [potentially scripted] selections are real
< real_disks=
< for disk in $ZFSBOOT_DISKS; do
< f_struct device_$disk && real_disks="$real_disks $disk"
< done
< # Make sure we have at least one real disk selected
< ndisks=$( set -- $real_disks; echo $# )
<
< local menu_list="
---
> local vdev_prompt="$msg_select_virtual_device_type"
> local disk_prompt="$msg_please_select_one_or_more_disks"
> local vdev_menu_list="
383a417,419
> local disk_check_list= # Calculated below
> local vdev_hline="$hline_arrows_tab_enter"
> local disk_hline="$hline_arrows_space_tab_enter"
385,423c421,423
< local defaultitem="$ZFSBOOT_VDEV_TYPE"
< local hline="$hline_arrows_tab_enter"
< local error_msg revalidate_choice
<
< local mheight mwidth mrows
< eval f_dialog_menu_size mheight mwidth mrows \
< \"\$title\" \"\$btitle\" \"\$prompt\" \"\$hline\" $menu_list
< local iheight iwidth
< f_dialog_infobox_size iheight iwidth \
< "$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$msg_processing_selection"
<
< local menu_choice
< menu_choice=$( eval $DIALOG \
< --title \"\$title\" \
< --backtitle \"\$btitle\" \
< --hline \"\$hline\" \
< --ok-label \"\$msg_ok\" \
< --cancel-label \"\$msg_cancel\" \
< --item-help \
< --default-item \"\$defaultitem\" \
< --menu \"\$prompt\" \
< $mheight $mwidth $mrows \
< $menu_list \
< --and-widget \
< ${USE_XDIALOG:+--no-buttons} \
< --infobox \"\$msg_processing_selection\" \
< $iheight $iwidth \
< 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
< ) || return $FAILURE
< f_dialog_data_sanitize menu_choice
< sleep 0.5 # Give time to read `--and-widget --info-box'
<
< # Make sure we have enough disks for the desired vdev type
< case "$menu_choice" in
< stripe) want_disks=1 ;;
< mirror) want_disks=2 ;;
< raidz1) want_disks=3 ;;
< raidz2) want_disks=4 ;;
< raidz3) want_disks=5 ;;
---
> # Warn the user if vdev type is not valid
> case "$ZFSBOOT_VDEV_TYPE" in
> stripe|mirror|raidz1|raidz2|raidz3) : known good ;;
425,427c425,429
< f_show_msg "$msg_invalid_virtual_device_type" \
< "$menu_choice"
< continue
---
> f_dprintf "%s: Invalid virtual device type \`%s'" \
> $funcname "$ZFSBOOT_VDEV_TYPE"
> f_show_err "$msg_invalid_virtual_device_type" \
> "$ZFSBOOT_VDEV_TYPE"
> f_interactive || return $FAILURE
429,437c431,445
< if [ $ndisks -lt $want_disks ]; then
< msg_yes="$msg_change" msg_no="$msg_cancel" f_yesno \
< "%s: $msg_not_enough_disks_selected\n%s" \
< "$menu_choice" $ndisks $want_disks \
< "$msg_invalid_virtual_device_type_help" ||
< return $FAILURE
< dialog_menu_vdev
< else
< ZFSBOOT_VDEV_TYPE="$menu_choice"
---
>
> # Calculate size of vdev menu once only
> local vheight vwidth vrows
> eval f_dialog_menu_with_help_size vheight vwidth vrows \
> \"\$title\" \"\$btitle\" \"\$vdev_prompt\" \"\$vdev_hline\" \
> $vdev_menu_list
>
> # Get a list of probed disk devices
> local disks=
> f_device_find "" $DEVICE_TYPE_DISK disks
> f_dprintf "$funcname: disks=[%s]" "$disks"
> if [ ! "$disks" ]; then
> f_dprintf "No disk(s) present to configure"
> f_show_err "$msg_no_disks_present_to_configure"
> return $FAILURE
438a447,603
>
> # Lets sort the disks array to be more user friendly
> disks=$( echo "$disks" | tr ' ' '\n' | sort | tr '\n' ' ' )
>
> #
> # Operate in a loop so we can (if interactive) repeat if not enough
> # disks are selected to satisfy the chosen vdev type or user wants to
> # back-up to the previous menu.
> #
> local vardisk ndisks onoff selections vdev_choice
> while :; do
> #
> # Confirm the vdev type that was selected
> #
> if f_interactive && [ "$ZFSBOOT_CONFIRM_LAYOUT" ]; then
> vdev_choice=$( eval $DIALOG \
> --title \"\$title\" \
> --backtitle \"\$btitle\" \
> --hline \"\$vdev_hline\" \
> --ok-label \"\$msg_ok\" \
> --cancel-label \"\$msg_cancel\" \
> --item-help \
> --default-item \"\$ZFSBOOT_VDEV_TYPE\" \
> --menu \"\$vdev_prompt\" \
> $vheight $vwidth $vrows \
> $vdev_menu_list \
> 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
> ) || return $?
> # Exit if user pressed ESC or chose Cancel/No
> f_dialog_data_sanitize vdev_choice
>
> ZFSBOOT_VDEV_TYPE="$vdev_choice"
> f_dprintf "$funcname: ZFSBOOT_VDEV_TYPE=[%s]" \
> "$ZFSBOOT_VDEV_TYPE"
> fi
>
> # Determine the number of disks needed for this vdev type
> local want_disks=0
> case "$ZFSBOOT_VDEV_TYPE" in
> stripe) want_disks=1 ;;
> mirror) want_disks=2 ;;
> raidz1) want_disks=3 ;;
> raidz2) want_disks=4 ;;
> raidz3) want_disks=5 ;;
> esac
>
> # Warn the user if any scripted disks are invalid
> local disk valid_disks=
> local all_valid=${ZFSBOOT_DISKS:+1} # optimism
> for disk in $ZFSBOOT_DISKS; do
> if f_struct device_$disk; then
> valid_disks="$valid_disks $disk"
> continue
> fi
> f_dprintf "$funcname: \`%s' is not a real disk" "$disk"
> all_valid=
> done
> if [ ! "$all_valid" ]; then
> if [ "$ZFSBOOT_DISKS" ]; then
> f_show_err \
> "$msg_missing_one_or_more_scripted_disks"
> else
> f_dprintf "No disks selected."
> f_interactive ||
> f_show_err "$msg_no_disks_selected"
> fi
> f_interactive || return $FAILURE
> fi
> ZFSBOOT_DISKS="${valid_disks# }"
>
> #
> # Short-circuit if we're running non-interactively
> #
> if ! f_interactive || [ ! "$ZFSBOOT_CONFIRM_LAYOUT" ]; then
> ndisks=$( set -- $ZFSBOOT_DISKS; echo $# )
> [ $ndisks -ge $want_disks ] && break # to success
>
> # Not enough disks selected
> f_dprintf "$funcname: %s: %s (%u < %u minimum)" \
> "$ZFSBOOT_VDEV_TYPE" \
> "Not enough disks selected." \
> $ndisks $want_disks
> f_interactive || return $FAILURE
> msg_yes="$msg_change_selection" msg_no="$msg_cancel" \
> f_yesno "%s: $msg_not_enough_disks_selected" \
> "$ZFSBOOT_VDEV_TYPE" $ndisks $want_disks ||
> return $FAILURE
> fi
>
> #
> # Confirm the disks that were selected
> # Loop until the user cancels or selects enough disks
> #
> local breakout=
> while :; do
> # Loop over list of available disks, resetting state
> for disk in $disks; do unset _${disk}_status; done
>
> # Loop over list of selected disks and create temporary
> # locals to map statuses onto up-to-date list of disks
> for disk in $ZFSBOOT_DISKS; do
> local _${disk}_status=on
> done
>
> # Create the checklist menu of discovered disk devices
> disk_check_list=
> for disk in $disks; do
> local desc=
> device_$disk get desc desc
> f_shell_escape "$desc" desc
> f_getvar _${disk}_status:-off onoff
> disk_check_list="$disk_check_list
> $disk '$desc' $onoff"
> done
>
> local height width rows
> eval f_dialog_checklist_size height width rows \
> \"\$title\" \"\$btitle\" \"\$prompt\" \
> \"\$hline\" $disk_check_list
>
> selections=$( eval $DIALOG \
> --title \"\$DIALOG_TITLE\" \
> --backtitle \"\$DIALOG_BACKTITLE\" \
> --hline \"\$hline\" \
> --ok-label \"\$msg_ok\" \
> --cancel-label \"\$msg_back\" \
> --checklist \"\$prompt\" \
> $height $width $rows \
> $disk_check_list \
> 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
> ) || break
> # Loop if user pressed ESC or chose Cancel/No
> f_dialog_data_sanitize selections
>
> ZFSBOOT_DISKS="$selections"
> f_dprintf "$funcname: ZFSBOOT_DISKS=[%s]" \
> "$ZFSBOOT_DISKS"
>
> ndisks=$( set -- $ZFSBOOT_DISKS; echo $# )
> [ $ndisks -ge $want_disks ] &&
> breakout=break && break
>
> # Not enough disks selected
> f_dprintf "$funcname: %s: %s (%u < %u minimum)" \
> "$ZFSBOOT_VDEV_TYPE" \
> "Not enough disks selected." \
> $ndisks $want_disks
> msg_yes="$msg_change_selection" msg_no="$msg_cancel" \
> f_yesno "%s: $msg_not_enough_disks_selected" \
> "$ZFSBOOT_VDEV_TYPE" $ndisks $want_disks ||
> break
> done
> [ "$breakout" = "break" ] && break
> [ "$ZFSBOOT_CONFIRM_LAYOUT" ] || return $FAILURE
> done
>
> return $DIALOG_OK
452d616
< local disk="$1" index="$2"
453a618
> local disk="$1" index="$2"
457c622,646
< [ "$disk" -a "$index" ] || return $FAILURE
---
> if [ ! "$disk" ]; then
> f_dprintf "$funcname: NULL disk argument"
> msg_error="$msg_error: $funcname" \
> f_show_err "$msg_null_disk_argument"
> return $FAILURE
> fi
> if [ "${disk#*[$IFS]}" != "$disk" ]; then
> f_dprintf "$funcname: Invalid disk argument \`%s'" "$disk"
> msg_error="$msg_error: $funcname" \
> f_show_err "$msg_invalid_disk_argument" "$disk"
> return $FAILURE
> fi
> if [ ! "$index" ]; then
> f_dprintf "$funcname: NULL index argument"
> msg_error="$msg_error: $funcname" \
> f_show_err "$msg_null_index_argument"
> return $FAILURE
> fi
> if ! f_isinteger "$index"; then
> f_dprintf "$funcname: Invalid index argument \`%s'" "$index"
> msg_error="$msg_error: $funcname" \
> f_show_err "$msg_invalid_index_argument" "$index"
> return $FAILURE
> fi
> f_dprintf "$funcname: disk=[%s] index=[%s]" "$disk" "$index"
458a648,659
> # Check for unknown partition scheme before proceeding further
> case "$ZFSBOOT_PARTITION_SCHEME" in
> ""|MBR|GPT) : known good ;;
> *)
> f_dprintf "$funcname: %s is an unsupported partition scheme" \
> "$ZFSBOOT_PARTITION_SCHEME"
> msg_error="$msg_error: $funcname" f_show_err \
> "$msg_unsupported_partition_scheme" \
> "$ZFSBOOT_PARTITION_SCHEME"
> return $FAILURE
> esac
>
463a665
> f_dprintf "$funcname: Destroying all data/layouts on \`%s'..." "$disk"
464a667
> f_quietly graid destroy $disk
468,469c671,672
< f_quietly gpart create -s gpt $disk || return $FAILURE
< f_quietly gpart destroy -F $disk || return $FAILURE
---
> f_quietly gpart create -s gpt $disk
> f_quietly gpart destroy -F $disk
472c675,682
< device_$disk get capacity disksize || return $FAILURE
---
> f_dprintf "$funcname: Getting disk capactiy for \`%s'" "$disk"
> if ! device_$disk get capacity disksize; then
> f_dprintf "$funcname: Unable to get disk capacity of \`%s'" \
> "$disk"
> msg_error="$msg_error: $funcname" \
> f_show_err "$msg_unable_to_get_disk_capacity" "$disk"
> return $FAILURE
> fi
473a684,685
> f_dprintf "$funcname: disksize=[%s] partsize=[%s]" \
> "$disksize" "$partsize"
480c692
< ""|GPT)
---
> ""|GPT) f_dprintf "$funcname: Creating GPT layout..."
484c696,697
< gpart create -s gpt $disk || return $FAILURE
---
> f_eval_catch $funcname gpart "$GPART_CREATE" gpt \$disk ||
> return $FAILURE
489,492c702,707
< gpart add -l gptboot$index -t freebsd-boot -s 512k $disk ||
< return $FAILURE
< gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 $disk ||
< return $FAILURE
---
> f_eval_catch $funcname gpart "$GPART_ADD_LABEL_WITH_SIZE" \
> gptboot\$index freebsd-boot 512k \$disk ||
> return $FAILURE
> f_eval_catch $funcname gpart "$GPART_BOOTCODE_PART" \
> /boot/pmbr /boot/gptzfsboot 1 \$disk ||
> return $FAILURE
497c712
< # Change things around if we are using GELI
---
> # Change things around if we are using geli(8)
501,502c716,722
< gpart add -l boot$index -t freebsd-zfs \
< -s ${gelisize}b -a 1m $disk || return $FAILURE
---
> f_dprintf "$funcname: gelisize=[%s]" \
> "gelisize=[$gelisize]"
> f_eval_catch $funcname gpart \
> "$GPART_ADD_LABEL_WITH_SIZE" boot\$index \
> freebsd-zfs \${gelisize}b \$disk ||
> return $FAILURE
>
504,505c724,725
< f_quietly zpool labelclear -f /dev/$disk$bootpart
< f_quietly geli detach -f /dev/$disk$targetpart
---
> f_quietly zpool labelclear -f "/dev/$disk$bootpart"
> f_quietly geli detach -f "/dev/$disk$targetpart"
512,515c732,744
< [ $swapsize -gt 0 ] && setsize="-s ${partsize}b"
< gpart add -l zfs$index -t freebsd-zfs $setsize -a 1m $disk ||
< return $FAILURE
< f_quietly zpool labelclear -f /dev/$disk$targetpart # Pedantic
---
> if [ ${swapsize:-0} -gt 0 ]; then
> f_dprintf "$funcname: partsize=[%s]" \
> "partsize=[$partsize]"
> f_eval_catch $funcname gpart \
> "$GPART_ADD_LABEL_WITH_SIZE" zfs\$index \
> freebsd-zfs \${partsize}b \$disk ||
> return $FAILURE
> else
> f_eval_catch $funcname gpart "$GPART_ADD_LABEL" \
> zfs\$index freebsd-zfs \$disk ||
> return $FAILURE
> fi
> f_quietly zpool labelclear -f "/dev/$disk$targetpart"
521,522c750,752
< gpart add -l swap$index -t freebsd-swap -a 1m $disk ||
< return $FAILURE
---
> f_eval_catch $funcname gpart "$GPART_ADD_LABEL" \
> swap\$index freebsd-swap \$disk ||
> return $FAILURE
524,526c754,757
< printf "$fstab_fmt" \
< /dev/gpt/swap$index none swap sw 0 0 \
< >> $BSDINSTALL_TMPETC/fstab || return $FAILURE
---
> f_eval_catch $funcname printf "$PRINTF_FSTAB" \
> /dev/gpt/swap\$index none swap sw 0 0 \
> \$BSDINSTALL_TMPETC/fstab ||
> return $FAILURE
530c761
< MBR)
---
> MBR) f_dprintf "$funcname: Creating MBR layout..."
534,535c765,768
< gpart create -s mbr $disk || return $FAILURE
< gpart bootcode -b /boot/boot0 $disk || return $FAILURE
---
> f_eval_catch $funcname gpart "$GPART_CREATE" mbr \$disk ||
> return $FAILURE
> f_eval_catch $funcname gpart "$GPART_BOOTCODE" /boot/mbr \
> \$disk || return $FAILURE
540,541c773,776
< gpart add -t freebsd $disk || return $FAILURE
< gpart set -a active -i 1 $disk || return $FAILURE
---
> f_eval_catch $funcname gpart "$GPART_ADD" freebsd \$disk ||
> return $FAILURE
> f_eval_catch $funcname gpart "$GPART_SET_ACTIVE" 1 \$disk ||
> return $FAILURE
546c781
< # 3. Write BSD sceme to the freebsd slice
---
> # 3. Write BSD scheme to the freebsd slice
548c783,784
< gpart create -s BSD ${disk}s1 || return $FAILURE
---
> f_eval_catch $funcname gpart "$GPART_CREATE" BSD \${disk}s1 ||
> return $FAILURE
553c789
< # Change things around if we are using GELI
---
> # Change things around if we are using geli(8)
558,559c794,799
< gpart add -t freebsd-zfs -i 1 -s ${gelisize}b \
< ${disk}s1 || return $FAILURE
---
> f_dprintf "$funcname: mbrindex=[%s] gelisize=[%s]" \
> "$mbrindex" "$gelisize"
> f_eval_catch $funcname gpart \
> "$GPART_ADD_INDEX_WITH_SIZE" \
> 1 freebsd-zfs \${gelisize}b \${disk}s1 ||
> return $FAILURE
561,562c801,802
< f_quietly zpool labelclear -f /dev/$disk$bootpart
< f_quietly geli detach -f /dev/$disk$targetpart
---
> f_quietly zpool labelclear -f "/dev/$disk$bootpart"
> f_quietly geli detach -f "/dev/$disk$targetpart"
569,571c809,821
< [ $swapsize -gt 0 ] && setsize="-s ${partsize}b"
< gpart add -t freebsd-zfs -i $mbrindex $setsize ${disk}s1 ||
< return $FAILURE
---
> if [ ${swapsize:-0} -gt 0 ]; then
> f_dprintf "$funcname: mbrindex=[%s] partsize=[%s]" \
> "$mbrindex" "$partsize"
> f_eval_catch $funcname gpart \
> "$GPART_ADD_INDEX_WITH_SIZE" \
> \$mbrindex freebsd-zfs \${partsize}b \
> \${disk}s1 || return $FAILURE
> else
> f_dprintf "$funcname: mbrindex=[%s]" "$mbrindex"
> f_eval_catch $funcname gpart "$GPART_ADD_INDEX" \
> \$mbrindex freebsd-zfs \${disk}s1 ||
> return $FAILURE
> fi
578,579c828,830
< gpart add -t freebsd-swap -i 2 ${disk}s1 ||
< return $FAILURE
---
> f_eval_catch $funcname gpart "$GPART_ADD_INDEX" \
> 2 freebsd-swap \${disk}s1 ||
> return $FAILURE
581,582c832,835
< printf "$fstab_fmt" /dev/${disk}s1b none swap sw 0 0 \
< >> $BSDINSTALL_TMPETC/fstab || return $FAILURE
---
> f_eval_catch $funcname printf "$PRINTF_FSTAB" \
> /dev/\${disk}s1b none swap sw 0 0 \
> \$BSDINSTALL_TMPETC/fstab ||
> return $FAILURE
586,590d838
< *)
< printf "%s: %s is an unsupported partition scheme" \
< "$funcname" "$ZFSBOOT_PARTITION_SCHEME" >&2
< return $FAILURE
<
596c844
< # zfs_create_boot $poolname $vdev_type $real_disks ...
---
> # zfs_create_boot $poolname $vdev_type $disks ...
603,604d850
< local poolname="$1" vdev_type="$2"
< local fstab_fmt="%s\t\t%s\t%s\t%s\t\t%s\t%s\n"
605a852
> local poolname="$1" vdev_type="$2"
611c858
< local realdisks=$*
---
> local disks="$*"
615c862,864
< echo "$funcname: NULL poolname" >&2
---
> f_dprintf "$funcname: NULL poolname"
> msg_error="$msg_error: $funcname" \
> f_show_err "$msg_null_poolname"
619c868,870
< echo "$funcname: missing disk arguments" >&2
---
> f_dprintf "$funcname: missing disk arguments"
> msg_error="$msg_error: $funcname" \
> f_show_err "$msg_missing_disk_arguments"
621a873,874
> f_dprintf "$funcname: poolname=[%s] vdev_type=[%s]" \
> "$poolname" "$vdev_type"
624,626c877,883
< printf "$fstab_fmt" \
< "# Device" Mountpoint FStype Options Dump "Pass#" \
< >> $BSDINSTALL_TMPETC/fstab || return $FAILURE
---
> f_dprintf "$funcname: Initializing temporary fstab(5) file..."
> f_eval_catch $funcname sh \
> "$SHELL_TRUNCATE" \$BSDINSTALL_TMPETC/fstab ||
> return $FAILURE
> f_eval_catch $funcname printf "$PRINTF_FSTAB" \
> "# Device" Mountpoint FStype Options Dump "Pass#" \
> \$BSDINSTALL_TMPETC/fstab || return $FAILURE
628a886
> f_dprintf "$funcname: Expanding supplied swapsize/gelisize values..."
630,631c888,904
< f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize || return $FAILURE
< f_expand_number "$ZFSBOOT_GELI_BOOT_SIZE" gelisize || return $FAILURE
---
> if ! f_expand_number "$ZFSBOOT_SWAP_SIZE" swapsize; then
> f_dprintf "$funcname: Invalid swap size \`%s'" \
> "$ZFSBOOT_SWAP_SIZE"
> f_show_err "$msg_invalid_swap_size" "$ZFSBOOT_SWAP_SIZE"
> return $FAILURE
> fi
> if ! f_expand_number "$ZFSBOOT_GELI_BOOT_SIZE" gelisize; then
> f_dprintf "$funcname: Invalid geli(8) boot size \`%s'" \
> "$ZFSBOOT_GELI_BOOT_SIZE"
> f_show_err "$msg_invalid_geli_boot_size" \
> "$ZFSBOOT_GELI_BOOT_SIZE"
> return $FAILURE
> fi
> f_dprintf "$funcname: ZFSBOOT_SWAP_SIZE=[%s] swapsize=[%s]" \
> "$ZFSBOOT_SWAP_SIZE" "$swapsize"
> f_dprintf "$funcname: ZFSBOOT_GELI_BOOT_SIZE=[%s] gelisize=[%s]" \
> "$ZFSBOOT_GELI_BOOT_SIZE" "$gelisize"
633a907
> f_dprintf "$funcname: Preparing disk partitions for ZFS pool..."
643,645c917,923
< for disk in $realdisks; do
< dd if=/boot/zfsboot of=/dev/${disk}s1 count=1 ||
< return $FAILURE
---
> f_dprintf "$funcname: Copying MBR boot loader to disks..."
> f_dprintf "$funcname: disks=[%s]" "$disks"
> for disk in $disks; do
> f_dprintf "$funcname: disk=[%s]" "$disk"
> f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \
> /boot/zfsboot /dev/\${disk}s1 count=1 ||
> return $FAILURE
652c930,937
< local new_list=
---
> local part="$targetpart" new_list=
>
> # We don't gnop the encrypted partition because geli will do
> # this for us gnop the unencrypted disk
> [ "$ZFSBOOT_GELI_ENCRYPTION" ] && part="$bootpart"
>
> f_dprintf "$funcname: Applying 4k alignment with gnop(8)..."
> f_dprintf "$funcname: *=[%s]" "$*"
653a939,942
> f_dprintf "$funcname: disk=[%s] part=[%s]" \
> "$disk" "$part"
> f_eval_catch $funcname gnop "$GNOP_CREATE" \
> \$disk\$part || return $FAILURE
655,660c944
< # We don't gnop the encrypted partition
< # because geli will do this for us
< # gnop the unencrypted disk
< gnop create -S 4096 $disk$bootpart ||
< return $FAILURE
< unenc_list="$unenc_list $disk$bootpart.nop"
---
> unenc_list="$unenc_list $disk$part.nop"
662,663d945
< gnop create -S 4096 $disk$targetpart ||
< return $FAILURE
685a968,969
> f_dprintf "$funcname: Setting up disk encryption..."
>
688c972,973
< mount -t tmpfs none $BSDINSTALL_CHROOT || return $FAILURE
---
> f_eval_catch $funcname mount "$MOUNT_TYPE" tmpfs none \
> \$BSDINSTALL_CHROOT || return $FAILURE
693,697c978,988
< zpool create -o altroot=$BSDINSTALL_CHROOT \
< -m "/$ZFSBOOT_GELI_POOL_NAME" -f \
< "$ZFSBOOT_GELI_POOL_NAME" $bootvdev $unenc_list ||
< return $FAILURE
< mkdir -p $geli_pool/boot || return $FAILURE
---
> f_dprintf "$funcname: %s %s %s" \
> "ZFSBOOT_GELI_POOL_NAME=[$ZFSBOOT_GELI_POOL_NAME]" \
> "bootvdev=[$bootvdev]" "unenc_list=[$unenc_list]"
> f_eval_catch $funcname zpool "$ZPOOL_CREATE_WITH_OPTIONS" \
> "-o altroot=\"\$BSDINSTALL_CHROOT\"
> -m \"/\$ZFSBOOT_GELI_POOL_NAME\" -f" \
> \$ZFSBOOT_GELI_POOL_NAME \$bootvdev \
> \$unenc_list || return $FAILURE
> f_dprintf "$funcname: geli_pool=[%s]" "$geli_pool"
> f_eval_catch $funcname mkdir "$MKDIR_P" \$geli_pool/boot ||
> return $FAILURE
700,701c991,994
< dd if=/dev/random of="$geli_pool/$key" bs=4096 count=1 ||
< return $FAILURE
---
> f_dprintf "$funcname: key=[%s]" "$key"
> f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \
> /dev/random \$geli_pool/\$key "bs=4096 count=1" ||
> return $FAILURE
705,715c998,1016
< msg_enter_new_password="$msg_geli_password" \
< f_dialog_input_password || return $FAILURE
< f_dialog_info "$msg_geli_setup" \
< 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
< for disk in $realdisks; do
< echo "$pw_password" | geli init -b -B \
< "$geli_pool/boot/$disk$targetpart.eli" \
< -e AES-XTS -J - -K "$geli_pool/$key" -l 256 \
< -s 4096 $disk$targetpart || return $FAILURE
< echo "$pw_password" | geli attach -j - \
< -k "$geli_pool/$key" $disk$targetpart ||
---
> if ! msg_enter_new_password="$msg_geli_password" \
> f_dialog_input_password
> then
> f_dprintf "$funcname: User cancelled"
> f_show_err "$msg_user_cancelled"
> return $FAILURE
> fi
> f_dprintf "$funcname: disks=[%s]" "$disks"
> for disk in $disks; do
> f_dprintf "$funcname: disk=[%s] targetpart=[%s]" \
> "$disk" "$targetpart"
> f_dialog_info "$msg_geli_setup" \
> 2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
> if ! echo "$pw_password" | f_eval_catch $funcname \
> geli "$GELI_PASSWORD_INIT" \
> \$geli_pool/boot/\$disk\$targetpart.eli \
> AES-XTS \$geli_pool/\$key \$disk\$targetpart
> then
> f_interactive || f_die
716a1018,1025
> fi
> if ! echo "$pw_password" | f_eval_catch $funcname \
> geli "$GELI_ATTACH" \$geli_pool/\$key \
> \$disk\$targetpart
> then
> f_interactive || f_die
> return $FAILURE
> fi
720c1029,1030
< zfs unmount "$ZFSBOOT_GELI_POOL_NAME" || return $FAILURE
---
> f_eval_catch $funcname zfs "$ZFS_UNMOUNT" \
> \$ZFSBOOT_GELI_POOL_NAME || return $FAILURE
727,728c1037,1043
< zpool create -o altroot=$BSDINSTALL_CHROOT -m none -f \
< "$poolname" $vdev_type $* || return $FAILURE
---
> local vdevs="$*"
> f_dprintf "$funcname: Creating boot pool..."
> f_dprintf "poolname=[%s] vdev_type=[%s] vdevs=[%s]" \
> "$poolname" "$vdev_type" "$vdevs"
> f_eval_catch $funcname zpool "$ZPOOL_CREATE_WITH_OPTIONS" \
> "-o altroot=\"\$BSDINSTALL_CHROOT\" -m none -f" \
> \$poolname \$vdev_type \$vdevs
731,732c1046,1052
< zfs set checksum=fletcher4 "$poolname" || return $FAILURE
< zfs set atime=off "$poolname" || return $FAILURE
---
> local option
> f_dprintf "$funcname: Setting miscellaneous options on boot pool..."
> for option in checksum=fletcher4 atime=off; do
> f_dprintf "$funcname: option=[%s]" "$option"
> f_eval_catch $funcname zfs "$ZFS_SET" \$option \$poolname ||
> return $FAILURE
> done
736a1057
> f_dprintf "$funcname: Creating ZFS datasets..."
753,754c1074,1078
< zfs create ${options:+-o $options} "$poolname$dataset" ||
< return $FAILURE
---
> f_dprintf "$funcname: dataset=[%s] options=[%s]" \
> "$dataset" "$options"
> f_eval_catch $funcname zfs "$ZFS_CREATE_WITH_OPTIONS" \
> "\${options:+-o \$options}" \$poolname\$dataset ||
> return $FAILURE
758,759c1082,1088
< chmod 1777 $BSDINSTALL_CHROOT/tmp || return $FAILURE
< chmod 1777 $BSDINSTALL_CHROOT/var/tmp || return $FAILURE
---
> f_dprintf "$funcname: Modifying directory permissions..."
> local dir
> for dir in /tmp /var/tmp; do
> f_dprintf "$funcname: dir=[%s]" "$dir"
> f_eval_catch $funcname chmod "$CHMOD_MODE" 1777 \
> \$BSDINSTALL_CHROOTDIR\$dir || return $FAILURE
> done
762,764c1091,1096
< [ "$ZFSBOOT_GELI_ENCRYPTION" ] &&
< { ln -s $ZFSBOOT_GELI_POOL_NAME/boot $BSDINSTALL_CHROOT/boot ||
< return $FAILURE; }
---
> if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
> f_dprintf "$funcname: Creating /boot symlink for GELI..."
> f_eval_catch $funcname ln "$LN_SF" \
> \$ZFSBOOT_GELI_POOL_NAME/boot \
> \$BSDINSTALL_CHROOT/boot || return $FAILURE
> fi
767,768c1099,1105
< zpool set bootfs="$poolname/$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOTFS_NAME" \
< "$poolname" || return $FAILURE
---
> f_dprintf "$funcname: Setting bootfs property..."
> f_dprintf "$funcname: %s %s" \
> "ZFSBOOT_BEROOT_NAME=[$ZFSBOOT_BEROOT_NAME]" \
> "ZFSBOOT_BOOTFS_NAME=[$ZFSBOOT_BOOTFS_NAME]"
> f_eval_catch $funcname zpool "$ZPOOL_SET" \
> bootfs=\"\$poolname/\$ZFSBOOT_BEROOT_NAME/\$ZFSBOOT_BOOTFS_NAME\" \
> \$poolname || return $FAILURE
771,773c1108,1114
< zpool export "$poolname" || return $FAILURE
< [ "$ZFSBOOT_GELI_ENCRYPTION" ] &&
< { zpool export "$ZFSBOOT_GELI_POOL_NAME" || return $FAILURE; }
---
> f_dprintf "$funcname: Temporarily exporting ZFS pool(s)..."
> f_eval_catch $funcname zpool "$ZPOOL_EXPORT" \$poolname ||
> return $FAILURE
> if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
> f_eval_catch $funcname zpool "$ZPOOL_EXPORT" \
> \$ZFSBOOT_GELI_POOL_NAME || return $FAILURE
> fi
776c1117
< for disk in ${ZFSBOOT_GNOP_4K_FORCE_ALIGN:+$realdisks}; do
---
> for disk in ${ZFSBOOT_GNOP_4K_FORCE_ALIGN:+$disks}; do
785a1127,1128
> f_dprintf "$funcname: Updating MBR boot loader on disks..."
> f_dprintf "$funcname: disks=[%s]"
788,790c1131,1136
< for disk in $realdisks; do
< dd if=/boot/zfsboot of=/dev/$disk$bootpart \
< skip=1 seek=1024 || return $FAILURE
---
> for disk in $disks; do
> f_dprintf "$funcname: disk=[%s] bootpart=[%s]" \
> "$disk" "$bootpart"
> f_eval_catch $funcname dd "$DD_WITH_OPTIONS" \
> /boot/zfsboot /dev/\$disk\$bootpart \
> "skip=1 seek=1024" || return $FAILURE
795,798c1141,1149
< zpool import -o altroot=$BSDINSTALL_CHROOT $poolname || return $FAILURE
< [ "$ZFSBOOT_GELI_ENCRYPTION" ] &&
< { zpool import -o altroot=$BSDINSTALL_CHROOT \
< "$ZFSBOOT_GELI_POOL_NAME" || return $FAILURE; }
---
> f_dprintf "$funcname: Re-importing ZFS pool(s)..."
> f_eval_catch $funcname zpool "$ZPOOL_IMPORT_WITH_OPTIONS" \
> "-o altroot=\"\$BSDINSTALL_CHROOT\"" \$poolname ||
> return $FAILURE
> if [ "$ZFSBOOT_GELI_ENCRYPTION" ]; then
> f_eval_catch $funcname zpool "$ZPOOL_IMPORT_WITH_OPTIONS" \
> "-o altroot=\"\$BSDINSTALL_CHROOT\"" \
> \$ZFSBOOT_GELI_POOL_NAME || return $FAILURE
> fi
801,803c1152,1157
< mkdir -p $BSDINSTALL_CHROOT/boot/zfs || return $FAILURE
< zpool set cachefile=$BSDINSTALL_CHROOT/boot/zfs/zpool.cache \
< "$poolname" || return $FAILURE
---
> f_dprintf "$funcname: Configuring zpool.cache..."
> f_eval_catch $funcname mkdir "$MKDIR_P" \$BSDINSTALL_CHROOT/boot/zfs ||
> return $FAILURE
> f_eval_catch $funcname zpool "$ZPOOL_SET" \
> cachefile=\"\$BSDINSTALL_CHROOT/boot/zfs/zpool.cache\" \
> \$poolname || return $FAILURE
807,810c1161,1166
< echo 'zfs_enable="YES"' > $BSDINSTALL_TMPETC/rc.conf.zfs ||
< return $FAILURE
< echo 'zfs_load="YES"' > $BSDINSTALL_TMPBOOT/loader.conf.zfs ||
< return $FAILURE
---
> f_dprintf "%s: Configuring rc.conf(5)/loader.conf(5) additions..." \
> "$funcname"
> f_eval_catch $funcname echo "$ECHO_APPEND" 'zfs_enable=\"YES\"' \
> \$BSDINSTALL_TMPETC/rc.conf.zfs || return $FAILURE
> f_eval_catch $funcname echo "$ECHO_APPEND" 'zfs_load=\"YES\"' \
> \$BSDINSTALL_TMPBOOT/loader.conf.zfs || return $FAILURE
815,821c1171,1180
< # Some additional GELI requirements for loader.conf(5)
< echo 'zpool_cache_load="YES"' \
< >> $BSDINSTALL_TMPBOOT/loader.conf.zfs || return $FAILURE
< echo 'zpool_cache_type="/boot/zfs/zpool.cache"' \
< >> $BSDINSTALL_TMPBOOT/loader.conf.zfs || return $FAILURE
< echo 'zpool_cache_name="/boot/zfs/zpool.cache"' \
< >> $BSDINSTALL_TMPBOOT/loader.conf.zfs || return $FAILURE
---
> # Some additional geli(8) requirements for loader.conf(5)
> for option in \
> zpool_cache_load=\"YES\" \
> zpool_cache_type=\"/boot/zfs/zpool.cache\" \
> zpool_cache_name=\"/boot/zfs/zpool.cache\" \
> ; do
> f_eval_catch $funcname echo "$ECHO_APPEND" \$option \
> \$BSDINSTALL_TMPBOOT/loader.conf.zfs ||
> return $FAILURE
> done
826,836c1185,1200
< echo 'aesni_load="YES"' \
< > $BSDINSTALL_TMPBOOT/loader.conf.aesni || return $FAILURE
< echo 'geom_eli_load="YES"' \
< > $BSDINSTALL_TMPBOOT/loader.conf.geli || return $FAILURE
< printf 'vfs.root.mountfrom="zfs:%s/%s/%s"\n' "$poolname" \
< "$ZFSBOOT_BEROOT_NAME" "$ZFSBOOT_BOOTFS_NAME" \
< > $BSDINSTALL_TMPBOOT/loader.conf.root || return $FAILURE
< for disk in $realdisks; do
< printf 'geli_%s_keyfile0_load="YES"\n' \
< "$disk$targetpart" \
< > $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart ||
---
> f_dprintf "$funcname: Configuring disk encryption..."
> f_eval_catch $funcname echo "$ECHO_APPEND" 'aesni_load=\"YES\"' \
> \$BSDINSTALL_TMPBOOT/loader.conf.aesni || return $FAILURE
> f_eval_catch $funcname echo "$ECHO_APPEND" 'geom_eli_load=\"YES\"' \
> \$BSDINSTALL_TMPBOOT/loader.conf.geli || return $FAILURE
> f_eval_catch $funcname printf "$PRINTF_CONF" vfs.root.mountfrom \
> '"zfs:$poolname/$ZFSBOOT_BEROOT_NAME/$ZFSBOOT_BOOT_FSNAME"' \
> \$BSDINSTALL_TMPBOOT/loader.conf.root || return $FAILURE
> f_dprintf "$funcname: disks=[%s]" "$disks"
> for disk in $disks; do
> f_dprintf "$funcname: %s %s %s" \
> "disk=[$disk]" "targetpart=[$targetpart]" \
> "ZFSBOOT_GELI_KEY_FILE=[$ZFSBOOT_GELI_KEY_FILE]"
> f_eval_catch $funcname printf "$PRINTF_CONF" \
> geli_%s_keyfile0_load '"$disk$targetpart" YES' \
> \$BSDINSTALL_TMPBOOT/loader.conf.\$disk\$targetpart ||
838,840c1202,1205
< printf 'geli_%s_keyfile0_type="%s:geli_keyfile0"\n' \
< "$disk$targetpart" "$disk$targetpart" \
< >> $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart ||
---
> f_eval_catch $funcname printf "$PRINTF_CONF" \
> geli_%s_keyfile0_type \
> '"$disk$targetpart" "$disk$targetpart"' \
> \$BSDINSTALL_TMPBOOT/loader.conf.\$disk\$targetpart ||
842,844c1207,1210
< printf 'geli_%s_keyfile0_name="%s"\n' \
< "$disk$targetpart" "$ZFSBOOT_GELI_KEY_FILE" \
< >> $BSDINSTALL_TMPBOOT/loader.conf.$disk$targetpart ||
---
> f_eval_catch $funcname printf "$PRINTF_CONF" \
> geli_%s_keyfile0_name \
> '"$disk$targetpart" "$ZFSBOOT_GELI_KEY_FILE"' \
> \$BSDINSTALL_TMPBOOT/loader.conf.\$disk\$targetpart ||
888a1255,1261
> # Debugging
> #
> f_dprintf "BSDINSTALL_CHROOT=[%s]" "$BSDINSTALL_CHROOT"
> f_dprintf "BSDINSTALL_TMPETC=[%s]" "$BSDINSTALL_TMPETC"
> f_dprintf "PRINTF_FSTAB=[%s]" "$PRINTF_FSTAB"
>
> #
894c1267
< mtag=">>> $msg_create"
---
> mtag=">>> $msg_install"
901c1274
< f_dprintf "retval=%u mtag=[%s]" $reval "$mtag"
---
> f_dprintf "retval=%u mtag=[%s]" $retval "$mtag"
905c1278
< ">>> $msg_create")
---
> ">>> $msg_install")
912,913c1285,1286
< f_show_msg "$msg_pool_name_cannot_be_empty"
< f_interactive || f_die
---
> f_dprintf "Pool name cannot be empty."
> f_show_err "$msg_pool_name_cannot_be_empty"
916,946c1289,1294
< # Make sure [potentially scripted] selections are real
< real_disks=
< for disk in $ZFSBOOT_DISKS; do
< f_struct device_$disk && real_disks="$real_disks $disk"
< done
< # Make sure we have at least one real disk selected
< ndisks=$( set -- $real_disks; echo $# )
< if [ $ndisks -lt 1 ]; then
< f_show_msg "$msg_no_disks_selected"
< f_interactive || f_die
< continue
< fi
< # Make sure we have enough disks for the desired vdev type
< case "$ZFSBOOT_VDEV_TYPE" in
< stripe) want_disks=1 ;;
< mirror) want_disks=2 ;;
< raidz1) want_disks=3 ;;
< raidz2) want_disks=4 ;;
< raidz3) want_disks=5 ;;
< *)
< f_show_msg "$msg_invalid_virtual_device_type" \
< "$ZFSBOOT_VDEV_TYPE"
< f_interactive || f_die
< continue
< esac
< if [ $ndisks -lt $want_disks ]; then
< f_show_msg "%s: $msg_not_enough_disks_selected" \
< "$ZFSBOOT_VDEV_TYPE" "$want_disks"
< f_interactive || f_die
< continue
< fi
---
>
> # Validate vdev type against number of disks selected/scripted
> # (also validates that ZFSBOOT_DISKS are real [probed] disks)
> # NB: dialog_menu_layout supports running non-interactively
> dialog_menu_layout || continue
>
954c1302
< for disk in $real_disks; do
---
> for disk in $ZFSBOOT_DISKS; do
961c1309,1314
< f_show_msg "$msg_these_disks_are_too_small" \
---
> f_dprintf "swapsize=[%s] gelisize[%s]" \
> "$ZFSBOOT_SWAP_SIZE" \
> "$ZFSBOOT_GELI_BOOT_SIZE"
> f_dprintf "These disks are too small: %s" \
> "$teeny_disks"
> f_show_err "$msg_these_disks_are_too_small" \
965d1317
< f_interactive || f_die
973,980c1325,1326
< if [ ! "$USE_XDIALOG" ]; then
< f_interactive && DIALOG="$DIALOG --colors" f_noyes \
< "$msg_last_chance_are_you_sure_color" \
< "$ZFSBOOT_DISKS" || continue
< else
< f_interactive && f_noyes \
< "$msg_last_chance_are_you_sure" \
< "$ZFSBOOT_DISKS" || continue
---
> if f_interactive; then
> dialog_last_chance $ZFSBOOT_DISKS || continue
992,998c1338,1339
< if ! error=$( zfs_create_boot "$ZFSBOOT_POOL_NAME" \
< "$vdev_type" $real_disks 2>&1 )
< then
< f_dialog_msgbox "$error"
< f_interactive || f_die
< continue
< fi
---
> zfs_create_boot "$ZFSBOOT_POOL_NAME" \
> "$vdev_type" $ZFSBOOT_DISKS || continue
1001a1343,1348
> ?" $msg_pool_type_disks")
> ZFSBOOT_CONFIRM_LAYOUT=1
> dialog_menu_layout
> # User has poked settings, disable later confirmation
> ZFSBOOT_CONFIRM_LAYOUT=
> ;;
1011,1012d1357
< ?" $msg_disks_to_use") dialog_edit_disks ;;
< ?" $msg_zfs_vdev_type") dialog_menu_vdev ;;
1021c1366
< ?" $msg_geli_encryption")
---
> ?" $msg_encrypt_disks")